Component guide · Beginner · 3 min read
SW-420 vibration sensor

Pinout, Wiring and Code
By Geekobot Learning Team · Updated 29 Oct 2026
On this page
The SW-420 module detects vibration and knocks using a normally-closed spring switch and an LM393 comparator. When the board shakes, the switch opens briefly and the digital output changes; the trimmer sets how much shaking is needed. It is a simple on/off sensor for alarms and machine-running detection, not a vibration meter.
Key specs at a glance
- Sensor
- SW-420 normally-closed vibration switch
- Output
- Digital DO (LM393 comparator), LED indicator
- Sensitivity
- Adjustable with the trimmer
- Supply
- 3.3 to 5 V
- Signal
- Short pulses while vibration lasts
- Size
- About 32 x 14 mm with mounting hole
Models in this guide
These are alternatives. Pick the one that fits your project; you only need one.
What the SW-420 vibration sensor is
Inside the SW-420 is a tiny spring around a metal pin. At rest they touch; vibration makes them separate for a moment. The comparator turns those brief openings into clean digital pulses.
More pulses per second means stronger or longer shaking, so counting pulses gives a rough level. For measured vibration in g, use an accelerometer.
SW-420 vibration sensor pinout
The pins on the SW-420 vibration sensor and what each one does.
| Pin | Function |
|---|---|
| VCC | 3.3 to 5 V |
| GND | Ground |
| DO | Digital output: changes on vibration |
- VCC
- 3.3 to 5 V
- GND
- Ground
- DO
- Digital output: changes on vibration
Wiring the SW-420 vibration sensor
Mount the module firmly to the object you want to monitor; a loose board picks up its own wobble.
| SW-420 vibration sensor pin | Arduino Uno | ESP32 |
|---|---|---|
| VCC | 5V | 3V3 |
| GND | GND | GND |
| DO | D2 (interrupt) | GPIO 27 |
- VCC
- Arduino Uno:
- 5V
- ESP32:
- 3V3
- GND
- Arduino Uno:
- GND
- ESP32:
- GND
- DO
- Arduino Uno:
- D2 (interrupt)
- ESP32:
- GPIO 27
Example code
Counting pulses over a second filters out single knocks. Tune the threshold (20 here) for your machine.
const int DO_PIN = 2;
volatile unsigned long pulses = 0;
void onPulse() { pulses++; }
void setup() {
Serial.begin(9600);
pinMode(DO_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(DO_PIN), onPulse, CHANGE);
}
void loop() {
noInterrupts(); unsigned long n = pulses; pulses = 0; interrupts();
Serial.print(n); Serial.println(n > 20 ? " vibration!" : "");
delay(1000);
}Setup and tuning
turn the trimmer until the LED stays steady at rest, then back it off slightly.
a washing machine or pump that stops vibrating for several minutes can trigger a 'finished' message on an ESP32.
combine with a buzzer for a bike or box alarm.
the switch responds best to motion perpendicular to the spring.
What you need
Shop this list4 of 5 found in our store · ₹617
SW-420 vibration sensor module: the common moduleSW-420 Vibration Sensor Module Alarm for Arduino – Digital Output₹42
Seeed Grove SW-420 vibration sensor: Grove connectorSeeed Studio SW-420 Grove Vibration Sensor Module – Digital Output₹499- Uno R3 development board: the controller used in the wiring tableFind this part
Buzzer module 3.3-5 V: for an audible alarmBuzzer Module 3.3–5V₹27
Dupont jumper wires: for the connectionsDupont Jumper Wires (40 pcs)₹49Closest match, check the specs
Alternatives and when to choose them
- Vibration and tilt sensors: ball switches, piezo and more.
- Piezo sensors: knock detection with an analog signal.
- Accelerometers: measure vibration amplitude and frequency.
Common mistakes to avoid
- Expecting a vibration strength in g.
- Leaving the module loose so it triggers on its own.
- Polling the pin slowly and missing short pulses.
- Setting the trimmer so high that the output is always active.
Frequently asked questions
How does the SW-420 work?
A spring touches a pin at rest; vibration separates them briefly and the comparator outputs a pulse.
Is DO HIGH or LOW on vibration?
It depends on the board; most go HIGH while vibrating. Check with the LED and Serial Monitor.
Can it measure earthquake strength?
No. It only detects vibration. Use an accelerometer for measurements.
Does it work with ESP32?
Yes, at 3.3 V.
How do I adjust sensitivity?
Turn the blue trimmer potentiometer.
Can it detect a door knock?
Yes, when mounted firmly on the door.
Parts for this guide
Projects that use it
Put this into practice: 20 step-by-step builds in our project library use parts from this guide.
Keep learning
Sources
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.

