Overview
In this project, we will make a Vibration Detection System using the SW-420 Vibration Sensor and an Arduino.
Vibration is a common phenomenon in machinery and structures, and while it can be harmless, excessive vibration may indicate impending failures or structural defects. Early detection of unusual vibrations can be critical for maintenance and safety in industrial settings, as well as for security applications where vibrations may indicate tampering or intrusion.
In this post, we’ll show you how to make a system that can detect shakes or trembles using a SW-420 Vibration Detection Sensor and an Arduino. This system will use a light (LED) and a sound (buzzer) to let people or other systems nearby know when it senses any unusual movement.
Bill of Materials
For this tutorial I am using the SunFounder Arduino Starter Kit which has 90+ components.
Here are the list of components I am using from this Kit.
| S.N. | Components | Quantity | Purchase Links |
|---|---|---|---|
| 1 | Arduino UNO R4/R3 Board | 1 | Amazon | AliExpress |
| 2 | SW-420 Vibration Sensor | 1 | Amazon | AliExpress | SunFounder |
| 3 | Red LED | 1 | Amazon | AliExpress | SunFounder |
| 4 | Buzzer | 1 | Amazon | AliExpress | SunFounder |
| 5 | Connecting Wires | 10 | Amazon | AliExpress | SunFounder |
| 6 | Type C USB Cable | 1 | Amazon | AliExpress |
| 7 | Breadboard | 1 | Amazon | AliExpress | SunFounder |
Vibration Sensor Module (SW-420)
The SW-420 vibration sensor is a small module designed to detect vibrations or shocks on surfaces.
It’s a versatile device that can be used for a variety of applications, such as sensing if someone knocks on a door, identifying problems in machines, detecting car accidents, or as part of an alarm system. This sensor is compatible with low-voltage systems since it operates on a power supply ranging from 3.3 V to 5 V.
Working Principle of Vibration Sensor
At the heart of the SW-420 vibration sensor module is a SW-420 vibration switch coupled with an LM393 voltage comparator. The vibration switch contains a spring-loaded rod within a tube.
When a vibration or shock occurs, the movement causes the spring to make contact with the rod, thus closing an electrical circuit. The sensor detects these movements and translates them into electrical signals.
The LM393 comparator is a critical component in this setup. It takes the electrical signals from the vibration switch and compares them to a preset threshold voltage, which you can adjust using the onboard potentiometer. When the signal’s amplitude surpasses the threshold, the comparator’s output switches to high (1), indicating a vibration has been detected. If the signal is below the threshold, the output remains low (0), indicating no significant vibration.
Features & Specifications of SW-420 Vibration Sensor
- Voltage: 3.3-5V DC
- Current: 15mA
- Sensor: SW-420 normally closed
- Indicators: Power and signal LEDs
- Design: LM393 comparator
- Compatibility: Easy to use with microcontrollers
- Installation: Bolt holes for mounting
- Size & Cost: Compact, affordable, widely available
Pinout of SW-420 Vibration Sensor
The SW-420 module typically has three to four pins:
- VCC: Connects to the power supply (3.3 V to 5 V).
- GND: Connects to the ground of the power supply.
- D0: Digital output pin that goes high when vibration is detected (after the threshold set by the potentiometer is exceeded).
- A0: (Not always available) Analog output pin that provides a voltage signal proportional to the vibrations detected.
Vibration Detection with SW-420 Vibration Sensor & Arduino
Now let us interface the SW-420 Vibration Detection Sensor with Arduino, LED and Buzzer.
Circuit Diagram & Connections
Here is a simple circuit diagram for this project.
Connect the SW-420 Vibration sensor’s VCC to Arduino’s 5V and GND to Arduino’s GND, and its digital output pin to Arduino’s pin 4.
The buzzer’s positive lead connects to Arduino’s pin 3, and its negative lead to another GND pin. Lastly, connect the LED’s anode to Arduino’s pin 2 through a 220-ohm resistor, and its cathode directly to Arduino’s GND.
Source Code/Program
The code for Vibration Detection with SW-420 Vibration Sensor & Arduino is very simple and is written in Arduino IDE. You can copy the following code and paste it on your Arduino IDE editor window.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
const int sensorPin = 4; const int ledPin = 2; // Define the pin for the LED const int buzzerPin = 3; // Define the pin for the buzzer void setup() { Serial.begin(9600); // Start serial communication at 9600 baud rate pinMode(sensorPin, INPUT); // Set the sensorPin as an input pin pinMode(ledPin, OUTPUT); // Set the ledPin as an output pin pinMode(buzzerPin, OUTPUT); // Set the buzzerPin as an output pin } void loop() { if (digitalRead(sensorPin)) // Check if there is any vibration detected by the sensor { Serial.println("Detected vibration..."); // Print "Detected vibration..." if vibration detected digitalWrite(ledPin, HIGH); // Turn on the LED tone(buzzerPin, 1000); // Play a 1kHz tone on the buzzer } else { Serial.println("..."); // Print "..." otherwise digitalWrite(ledPin, LOW); // Turn off the LED noTone(buzzerPin); // Stop playing any tone on the buzzer } // Add a delay to avoid flooding the serial monitor delay(100); } |
From the tools menu, Select the Arduino UNO Board and the Arduino COM port. Then click on the upload icon to upload the code.
Testing & Results
When the SW-420 vibration sensor detects movement, it sends a digital HIGH signal to the designated input pin on the Arduino. The programmed code reacts to this signal by executing two functions.
Firstly, it sends a HIGH signal to the LED pin, lighting up the LED. This acts as a visual cue that vibration has been detected. Secondly, it triggers the buzzer connected to another pin to emit a sound, serving as an auditory alert.
Conversely, when no vibration is present, the sensor sends a LOW signal to the Arduino. The code responds by turning off the LED (sending a LOW signal to the LED pin) and silencing the buzzer, indicating a stable environment without any detected vibrations.
Conclusion
Building a vibration detection system using an Arduino and the SW-420 vibration sensor is an excellent project for enthusiasts and those interested in learning about sensors and alert systems. It showcases how straightforward components can be assembled to develop practical and responsive systems. With proper configuration and coding, anyone can create a fundamental vibration detection system that enhances security and offers immediate alerts to potential disturbances or unauthorized access.














