Arduino 101: Using a vibration sensor module (SW-420)
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
- Vibration Sensor Module - SW-420
- LED
- Resistor (220 ohms)
- Breadboard
- Computer
- USB type A to B cable
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
Tutorial Contents
Step 1: Gather the parts
- You can buy the components in your nearby electronics shop or order it online.
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.
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.
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.
Step 3: Programming
- Once plugged, open the arduino IDE and go to Tools > Board: > then select Arduino/Genuino Uno.
- 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.
- If no errors is found, click the Upload button to install the program into the arduino uno board.
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:
- Arduino 101: Using a KY-036 metal touch sensor
- Arduino 101: Using a Flame sensor module
- Arduino 101: Using a Capacitive Touch sensor to control an LED
- Arduino 101: Using a Reed switch
Posted on Utopian.io - Rewarding Open Source Contributors
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
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
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.