What is the SW-420 Vibration Sensor?
The SW-420 vibration sensor module is a tiny, low-cost board that tells your microcontroller when something has been shaken, knocked or bumped. It has three pins, no library and no configuration: when vibration crosses a threshold you set with a small screw trimmer, the digital output changes state.
That simplicity is what makes it useful. Typical projects include a knock-activated doorbell, an alarm that fires when a box, bike or cabinet is moved, a counter that registers each time a machine thumps, and a "wake up" trigger that lets a battery project sleep until something happens.
It is important to know what the module is not. It does not measure how hard or how fast something shakes, and it cannot tell you the direction or frequency. It answers one question only: did the vibration cross my threshold or not? If you need numbers, use an accelerometer such as the ADXL345 or MPU-6050 instead.
How the module works
The SW-420 sensor is a small spring-type switch that is normally closed. When the board is still, the switch sits in one state. When it is shaken or knocked, the contacts flicker for a moment, producing a brief electrical disturbance.
That disturbance alone is too small and ragged for a microcontroller to use, so an LM393 comparator cleans it up. It compares the signal from the sensor against a reference voltage set by the blue trimmer. When the signal crosses the reference, the comparator output flips and the DO pin changes state. The second LED on the board lights to show this.
That is why the trimmer is called a threshold control rather than a calibration. Turn it one way and a gentle tap triggers the output; turn it the other way and only a hard knock does. The module is inherently a yes or no detector, not a measuring instrument.
Which level means vibration?
Documentation for this module generally describes the output as low at rest and high when vibration is detected, but cheap clones do not all follow that. Some boards are inverted, and the behaviour can change with the trimmer setting. Never assume. Upload the sketch below, watch the Serial Monitor and the output LED, and note which level appears when you tap the board. The code uses a single constant so you can flip it in one place.
Setting the sensitivity
- Mount the module in its final position first. How it is fixed changes how vibration reaches the sensor, so tune it where it will live.
- Power it up and let the output settle at rest.
- Turn the trimmer slowly with a small screwdriver until the output LED just stays in its resting state.
- Tap the surface where you expect the event. The LED should flash. If it does not, back the trimmer off a little at a time.
- Check that normal background vibration, such as a fan or footsteps, does not trigger it.
Small turns make a big difference, and the direction that raises sensitivity differs between boards, so go gently and watch the LED.
Basic sketch: count vibration events
This sketch checks the pin in the main loop and ignores repeats for half a second, so a single knock is counted once rather than dozens of times. Change ACTIVE_LEVEL to LOW if your module is inverted. On an ESP32, change SENSOR_PIN to the GPIO you wired.
Interrupt version for fast or low-power projects
Polling can miss a very short pulse if your loop is busy, and it keeps the processor awake. An interrupt reacts the instant the pin changes and lets you do other work, or sleep, in between. On an Uno or Mega use pin 2 or 3 (the Mega also has 18 to 21). On an ESP32 any GPIO works, but add IRAM_ATTR before the handler. Use RISING for an active-high module and FALLING if yours is inverted.
Using it well
- Fix it firmly. A loose board makes its own vibration and triggers falsely.
- Tune in place. Always set the trimmer in the finished enclosure, not on the desk.
- Debounce in software. One knock produces several quick transitions, so ignore repeats for a short time.
- Match the logic voltage. Power it at 3.3 V on 3.3 V boards.
- Combine it with an output. An active buzzer turns it into a simple alarm in a few lines of code.
- Use an interrupt for battery projects. Let the processor sleep until the sensor wakes it.
Frequently asked questions
Does it have an analog output? No. Only the digital DO pin is provided on this module, so you cannot read the strength of the vibration.
Can it detect an earthquake? It can react to strong shaking, but it is far too crude and unreliable to be used as an earthquake detector.
Why is the output inverted on my board? Different manufacturers wire the comparator differently. Check the resting level with the Serial Monitor and set ACTIVE_LEVEL to match.
Can I power it from 3.3 V? Yes. The module is rated for 3.3 to 5 V, and 3.3 V is the right choice for ESP32 and Raspberry Pi projects.
How sensitive is it? It depends on the trimmer and on how the module is mounted. There is no calibrated figure, so test it against the event you care about.
Specifications
- Sensing element
- SW-420 vibration switch (normally closed type)
- Signal conditioning
- LM393 voltage comparator
- Operating voltage
- 3.3 to 5 V DC
- Operating current
- About 15 mA
- Output
- Digital (DO) only; there is no analog output
- Output behaviour
- Low at rest and high on vibration on most documented boards; some clones are inverted
- Sensitivity adjustment
- Onboard 10 kΩ trimmer potentiometer
- Indicators
- Two LEDs: power and output status
- Mounting
- Bolt holes on the board
Pinout
| Pin | Name | Description |
|---|---|---|
| 1 | VCC | Power supply, 3.3 to 5 V |
| 2 | GND | Ground |
| 3 | DO | Digital output, changes state when vibration crosses the set threshold |
Swipe sideways to see every column →
Power it from the logic voltage of your board. The output swings between 0 V and the supply voltage. On a 5 V Arduino that is fine. On an ESP32 or Raspberry Pi, power the module from 3.3 V so the DO pin can never exceed what the GPIO tolerates.
Pin order varies between makers. Most boards print VCC, GND and DO along the edge, but always follow the silkscreen on your own module rather than the position of the pins.
Share the ground. The module and the microcontroller must be on the same ground, or the output level is meaningless.
Wiring & code
Setting up SW-420 Vibration Sensor with Arduino Uno R3
Library
digitalRead (built-in) by Arduino
No additional library; use the Uno R3 board package.
Wiring — Arduino Uno R3
| Module pin | Arduino Uno R3 pin | Notes |
|---|---|---|
| VCC | 3.3V (if module supports it) | Check the exact module voltage range; if 5V powered, verify output voltage |
| GND | GND | Common ground |
| DO | D2 | Digital output; observe output at rest and triggered to set ACTIVE_LEVEL |
Swipe sideways to see every column →
No extra library is required. Verify polarity and whether a pull-up is needed for this exact SW-420 board. The sketch uses state-change detection and a 150 ms refractory interval to suppress repeated messages. Not physically bench-tested.







