SW 420 vibration sensor with Arduino | Step by step instructions
Hello and welcome back. Today we are going to talk about the SW-420 Vibration sensor. Also, this tutorial explains how to work this vibration sensor and how to connect it to an Arduino board. We can mainly use this sensor to detect vibrations. Also, this sensor can be used for transporting goods unsuitable for vibration and for equipment damaged under vibration conditions. That is, in those cases, vibrations can be detected and action can be taken. The knowledge in this tutorial can also be used for your vibration detection projects.
How does the SW-420 vibration sensor work?
This vibration sensor module mainly includes a sensor called the SW-420. This sensor is activated by opening and closing the electrical contact. In the absence of vibrations, this electrical contact is in a closed state. Also, when there is a vibration, the electrical contact opens and the resistance level rises. Then a pulse is generated. This pulse is converted into a digital signal using the LM393 voltage comparator. That is, we can get digital signals through this sensor. Also, the sensitivity of this digital signal can be changed by using the 10k potentiometer included here.
The PIN structure of this sensor
OK, now we will learn how to connect this sensor to Arduino step by step. To do this, the necessary components are listed below.
- Arduino Nano board x 1 – Our Store / Amazon
- Vibration sensor x 1 – Our Store / Amazon
- LED bulb x 1 – Our Store / Amazon
- 180-ohm resistor x 1 – Our Store / Amazon
- Breadboard x 1 – Our Store / Amazon
- Jumper wires – Our Store / Amazon
Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.
Step 1
Firstly, identify these components.
Arduino Nano board
Vibration sensor
LED bulb
180-ohm resistor
Breadboard
Jumper wires
Step 2
Secondly, connect these components, To do this, use the circuit diagram below.
Step 3
Thirdly, let’s create the program for this project. It is as follows.
- The complete program of this project – Download
/*Vibration sensor tutorial.
created by the SriTu Tech team.
Read the code below and use it for any of your creations.
Home Page
*/
#define LED 3
#define Sensor 2
void setup() {
Serial.begin(9600);
pinMode(Sensor, INPUT);
pinMode(LED, OUTPUT);
}
void loop() {
bool value = digitalRead(Sensor);
if (value == 1) {
digitalWrite(LED,HIGH);
}else if(value == 0){
digitalWrite(LED,LOW);
}
}
Code explanation
First, the LED and sensor PINs are defined.
#define LED 3
#define Sensor 2
In the setup function, the sensor pin set as input, and the LED pin set as output. Also, the serial monitor is started.
void setup() {
Serial.begin(9600);
pinMode(Sensor, INPUT);
pinMode(LED, OUTPUT);
}
In the loop function, the sensor values are taken and these values are put into a Boolean variable. Also, these values are checked using the IF condition. If the value is 1, the LED is turned ON. Otherwise, the LED is turned OFF.
void loop() {
bool value = digitalRead(Sensor);
if (value == 1) {
digitalWrite(LED,HIGH);
}else if(value == 0){
digitalWrite(LED,LOW);
}
Step 4
Lastly, select the board and port, Afterward, upload this code to the Arduino board.
OK, study this tutorial carefully. The full video guide is given below. So, we will meet in the next tutorial. Have a good day.
SW 420 vibration sensor with Arduino | Step by step instructions