Arduino 101: Using a vibration sensor module (SW-420)

in #utopian-io8 years ago (edited)

What Will I Learn?

  • You will learn how to use a vibration sensor.
  • You will learn how to integrate the vibration sensor module with the Arduino Uno board.
  • You will learn the program codes to make the vibration sensor work properly with the Arduino Uno board.

Requirements

Hardware

  • Arduino Uno

image.png

Image source

  • Vibration Sensor Module - SW-420

image.png

Image Source

  • LED

image.png

Image source

  • Resistor (220 ohms)

image.png

Image source

  • Breadboard

image.png

Image source

image.png

Image source

  • Computer

image.png

Image source

  • USB type A to B cable

image.png

Image source

Software

  • Arduino Software/ Arduino IDE

Knowledge

  • Basic electronics and programming knowledge

Difficulty

  • Basic

Project description

  • This project uses a vibration sensor module that is controlled by an arduino uno board. The vibration sensor is connected as the INPUT while the LED will be its OUTPUT. When the sensor detects vibration it will send a HIGH pulse to the arduino uno board, the arduino will then turn the LED on. If the sensor does not detect any vibration, it will keep its value at LOW, thus turning the LED off.

Component description

Arduino Uno - one type of arduino board that is commonly by specialist and hobbyist because of its robust design. It is equipped with a microcontroller board that is based on ATMega328P with 14 advanced I/O pins (6 are PWM outputs), 6 analog inputs, 16 Mhz quartz crystal, a power jack, a USB port, an ICSP header and a reset button.Reference

Vibration sensor module (SW-420) - is a type of sensor that detects vibration in the surrounding. It consists of a SW-420 vibration sensor, an LM393 comparator, an LED and a potentiometer. The threshold can be adjusted by turning the potentionmeter, When it detects vibration that is above its set threshold, it will send a HIGH signal and if no vibration or below the threshold, it will send a LOW signal. Reference

image.png

Image source

Tutorial Contents

Using a vibration sensor module (SW-420)

Step 1: Gather the parts

  • You can buy the components in your nearby electronics shop or order it online.

image.png

Step 2: Construct the circuit

Connect the sources
-Connect the 5V pin of the arduino uno board into the top/bottom slot of the breadboard. The connections here are horizontally connected making it an ideal for the sources.
-Connect the GND pin of the arduino uno board into the top/bottom slot of the breadboard but make sure not to place them together to avoid shorting the arduino board.

image.png

Connect the LED
-Connect the Anode(+) of the LED to a 220 ohm resistor that is connected to pin 7 of the arduino uno board. This resistor will protect the LED from over supply of current.
-Connect the Cathode(-) of the LED to the common ground.

image.png

Connect the sensor

  • Connect the VCC pin of the vibration sensor to the voltage source (+) in the breadboard.
  • Connect the GND pin of the vibration sensor to the common ground(-) in the breadboard.
  • Connect the D0(Digital pin) pin of the vibration sensor to pin number 4 of the arduino uno board.

image.png

Step 3: Programming

  • Connect the arduino uno board to the computer by using the usb type A to B cable.
    image.png

Image source

  • Once plugged, open the arduino IDE and go to Tools > Board: > then select Arduino/Genuino Uno.

image.png

  • Copy the code below and paste it to your sketch in the arduino IDE.
int vibratePin  = 7; //sets the digital pin(d0)of the vibration sensor @pin 7
int ledPin  = 2;  //sets the LED @pin 2
int value;        //defines the value variable
void setup() {
  pinMode(vibratePin,INPUT);  //sets the vibration sensor as INPUT
  pinMode(ledPin,OUTPUT);   //sets the LED as OUTPUT
}
void loop() {
  value=digitalRead(vibratePin);  //reads the sensors status
  if(value==1)      //if sensor sends a HIGH signal
  {
    digitalWrite(ledPin,HIGH);  //turns LED on
    delay(3000);      //duration of 3 seconds
   }
   else   //otherwise 
   digitalWrite(ledPin,LOW);  //LED is turned off
}

What this code does is very straightforward, first it sets the pins of the sensor and the LED and defines the value as a variable. In the setup command, it sets the vibration sensor as the INPUT while the LED as the OUTPUT. In the loop command, the value is set to read the status of the sensor. If it sends a HIGH signal, it will interpret it as a 1 and then runs the command to turn the LED on. Otherwise, the LED is turned off.

  • After typing the code into your sketch, click the Verify button to save it and compile the program. This will check for any errors in the program.

image.png

  • If no errors is found, click the Upload button to install the program into the arduino uno board.

image.png

Step 4: Testing

  • After the programming is complete, remove the arduino uno board from the computer and connect it with a battery pack to power up the device.
  • Now place the vibration sensor in the table and start making vibration this should make the LED turn on, indicating that the sensor is detecting a vibration in the area.
  • Stop the vibration now, this should turn the LED off indicating that the sensor is not detecting any vibrations.

Curriculum

Check out my other Arduino tutorials below:



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Thanks a lot man👍

Hey @ted7 I am @utopian-io. I have just upvoted you!

Achievements

  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Resteemed your article. This article was resteemed because you are part of the New Steemians project. You can learn more about it here: https://steemit.com/introduceyourself/@gaman/new-steemians-project-launch

Hello dear STEEMIAN......... You have received this message as a follower of @lightingmacsteem.

I would like to invite you to come visit the JOULESTEEM circuit posts, it may interest you to learn methods of harnessing atmospheric energy and create your own low-power off-the-grid energy source regardless of your location.

SBD author rewards sharing is also started to ptomote such approach, your support can greatly help in this goodwill good-for-our-Earth endevor.

Regards.

Coin Marketplace

STEEM 0.13
TRX 0.35
JST 0.033
BTC 115324.49
ETH 4502.80
SBD 0.85