In this easy CircuitMagic tutorial you will build detect vibration using arduino and sw-420 sensor using Arduino Uno and one simple sensor. The project needs only a few connections and a short Arduino IDE sketch.
What does the sensor do?
The SW-420 module contains a vibration-sensitive switch and an adjustable comparator. It produces digital pulses when vibration exceeds the selected threshold.
Required components
Arduino Uno, SW-420 vibration module, jumper wires, USB cable.
Connection diagram
The diagram below is a pin-to-pin connection map: each colored line shows one separate wire between labeled terminals, not a photograph of a particular board’s header layout.

Pin connections
Unplug USB power before wiring. The pin table is authoritative; always verify your board’s printed pin labels and your module’s pinout.
| Arduino Uno pin / connection | SW-420 vibration sensor module connection |
|---|---|
| 5V | Module VCC |
| GND | Module GND |
| D2 | Module DO |
Arduino IDE setup
No additional library needed. Select the matching board and serial port, then upload this sketch.
Complete Arduino code
const int vibrationPin = 2;
int restLevel;
void setup() {
Serial.begin(9600);
pinMode(vibrationPin, INPUT);
delay(1000);
restLevel = digitalRead(vibrationPin);
Serial.println("Tap the table to test vibration.");
}
void loop() {
if (digitalRead(vibrationPin) != restLevel) {
Serial.println("Vibration detected");
}
delay(30);
}
Expected output
Tap or shake the module gently: Vibration detected appears. Open Serial Monitor at the baud rate specified by Serial.begin().
Troubleshooting
Adjust the blue trimmer for sensitivity. A different idle output polarity is normal; if detection is unstable, observe the module LED and test both digital states.
If there is no output, double-check the board and port, USB data cable, common ground, sensor pin labels and Serial Monitor speed.
Try next
Once the basic example works, experiment with the sampling delay, add an LED indicator, or log the sensor output to a computer. See more CircuitMagic electronics projects for related beginner tutorials.










