Learn how to use a Vibration Sensor (SW-420) with Arduino. In this post we’ll go over the basics of the Vibration Sensor, the sensor pins, how to connect to an Arduino UNO, how to program in Arduino, and testing of the sensor.
Vibration Sensor Basics
The Vibration Sensor (SW-420) can be used to detect whether or not vibration is present. The sensor will not provide an analog signal to indicate the intensity of the vibration, instead it will indicate whether or not vibration is present through a digital output. To define what constitutes as a vibration, one must set the sensor sensitivity through a built-in potentiometer (more details provided later).
Sensor Pins and Connection to Arduino
VCC – Connected to Arduino UNO 5V output.
GND – Connected to Arduino GND.
DO – Digital Output
Sensor Sensitivity Adjustment
This Vibration Sensor has the capability for sensitivity adjustment. To do so, you need to use the potentiometer included in the sensor circuit board. All you have to do is take a small screwdriver and turn the potentiometer to adjust the sensitivity to vibration. Setting towards the middle of the potentiometer range should work for most applications, but make adjustments if needed and test to confirm.
Arduino Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
//Arduino Code - Vibration Sensor int Vibration_signal = 7; //Define the Digital Input on the Arduino for the sensor signal int Sensor_State = 1; void setup() { pinMode(Vibration_signal, INPUT); //Set pin as input Serial.begin(9600); // Start the serial communication } void loop() { Serial.print("Vibration status: "); Sensor_State = digitalRead(Vibration_signal); if (Sensor_State == 1) { Serial.println("Sensing vibration"); } else { Serial.println("No vibration"); } delay(50); } |
Run Arduino Code – Testing the Vibration Sensor
All you need to do now is run the code that was provided above and open the Serial Monitor. As soon as you do, you will see the output indicating whether or not vibration is being detected by the sensor. If the serial monitor only shows “Sensing vibration” or “Sensing vibration” regardless of what you do, then consider adjusting the sensor sensitivity through the potentiometer.
Components used in this example
*As an Amazon & Ebay Associate I earn from qualifying purchases.
Component | Link |
Arduino UNO | https://amzn.to/3uYVAMC https://ebay.us/veZdKX |
Vibration Sensor (SW-420) | https://amzn.to/32nmvpb https://ebay.us/qEaORc |