Documentation

SW-420 Vibration Sensor Module for Arduino | ShillehTek Product Manual
Documentation / SW-420 Vibration Sensor Module for Arduino | ShillehTek Product Manual

SW-420 Vibration Sensor Module for Arduino | ShillehTek Product Manual

Overview

The SW-420 module is the simplest way to give a project a sense of touch-by-shake: it detects taps, knocks, bumps, and machine vibration and reports them as a clean digital signal on one pin. Inside the blue cylinder is a spring-and-pin vibration switch that is conductive at rest; the moment the module is jolted, the contact chatters open and closed. An onboard LM393 comparator turns that chatter into crisp digital pulses, with a blue trimmer potentiometer setting how hard a shake counts as "vibration."

Because the output is plain 3.3V/5V logic, the SW-420 works with every board in the drawer — Arduino, ESP32, Raspberry Pi, and Pico — with no libraries, no protocols, and no analog math. Power it from 3.3V or 5V, watch the DO pin, and react. Two onboard LEDs make setup easy: one shows power, the other mirrors the output so you can tune the sensitivity pot with your eyes before writing a single line of code.

It is a detector, not a measuring instrument — it tells you that something shook, not precisely how hard. That is exactly right for anti-tamper alarms, package and door knock sensors, washing-machine end-of-cycle detectors, earthquake toys, bike and vehicle movement alarms, and machine health monitors that flag unusual rattling. When you need actual vibration magnitude and frequency, step up to an accelerometer like the ADXL345 or MPU6050.

At a Glance

Operating Voltage
3.3V - 5V DC
Sensing Element
SW-420 vibration switch
Output
Digital (DO), comparator-driven
Sensitivity
Adjustable via potentiometer
Comparator
LM393
Pins
VCC, GND, DO

Specifications

Parameter Value
Sensing Element SW-420 normally-closed spring vibration switch
Operating Voltage 3.3V - 5V DC
Operating Current ~15 mA
Comparator LM393 dual differential comparator
Output Digital logic on DO; pulses when vibration exceeds threshold
Sensitivity Adjustment Onboard trimmer potentiometer (comparator threshold)
Direction Sensitivity Non-directional — responds to shakes on any axis
Indicator LEDs 2 (power + DO status)
Response Bursts of pulses during vibration — count or debounce in code
Board Dimensions ~32 x 14 mm

Pinout Diagram

Three pins run the whole show: VCC accepts 3.3V or 5V (match your board's logic level), GND is ground, and DO is the digital output from the LM393 comparator. The blue potentiometer sets the vibration threshold — turning it changes how big a jolt is needed before DO fires and the output LED blinks. The SW-420 tube itself is the blue cylinder soldered to the board; it senses shakes in any direction, so the module's mounting orientation does not matter.

SW-420 vibration sensor module annotated diagram showing VCC, GND, digital output pins, sensitivity potentiometer, LM393 comparator, and onboard LEDs

Wiring Guide

Arduino Wiring

Power from 5V and read DO on any digital pin. Pin 2 is used here because it supports external interrupts, which the example sketch uses to catch even the shortest pulses.

SW-420 Pin Arduino Pin
VCC 5V
GND GND
DO Digital Pin 2 (interrupt-capable)
Tip: Tune the pot before coding: tap the table next to the module and adjust until the output LED stays off at rest but flickers on a firm tap. That LED shows exactly what your sketch will see on pin 2.

ESP32 Wiring

Power the module from 3V3 so DO swings at 3.3V — safe for ESP32 inputs with zero extra components.

SW-420 Pin ESP32 Pin Details
VCC 3V3 Do NOT use VIN/5V
GND GND
DO GPIO 25 Any free GPIO works
Warning: If you power the module at 5V, DO pulses at 5V — too high for ESP32 pins. Powering from 3V3 keeps the output within safe levels automatically, and the module works fine at 3.3V.

Raspberry Pi Wiring

Same rule as the ESP32: power from the 3.3V pin so the output is GPIO-safe.

SW-420 Pin Raspberry Pi Pin Details
VCC Pin 1 (3.3V) Do NOT use 5V pins
GND Pin 6 (GND)
DO Pin 11 (GPIO 17)
Warning: Raspberry Pi GPIO has no 5V protection. Always power the SW-420 from Pin 1 (3.3V) — a 5V-powered module would push 5V pulses into GPIO 17 and can damage the Pi.

Raspberry Pi Pico Wiring

Power from 3V3(OUT) and read DO on any GPIO — GP15 here to match the code example.

SW-420 Pin Pico Pin Details
VCC 3V3(OUT) (physical pin 36) Do NOT use VBUS (5V)
GND GND (physical pin 38)
DO GP15 (physical pin 20)
Tip: Vibration output arrives as fast pulse bursts. The MicroPython example counts pulses with an interrupt handler, which is far more reliable than polling in a loop.

Code Examples

Vibration shows up as short bursts of pulses on DO, so all four examples use interrupts to count pulses and then report activity once per second — a simple, robust pattern that doubles as a rough intensity estimate (more pulses = harder shaking). Note: some board revisions idle HIGH instead of LOW; the pulse-counting approach works either way, since any vibration produces edges.

Arduino

sw420_arduino.ino
// SW-420 Vibration Sensor - Arduino Example (interrupt pulse counting)
// DO -> Pin 2, VCC -> 5V, GND -> GND

const int sensorPin = 2;               // interrupt-capable pin
volatile unsigned int pulseCount = 0;

void onVibration() {
  pulseCount++;                        // keep the ISR tiny
}

void setup() {
  Serial.begin(9600);
  pinMode(sensorPin, INPUT);
  // CHANGE catches every edge, so idle-HIGH boards work too
  attachInterrupt(digitalPinToInterrupt(sensorPin), onVibration, CHANGE);
  Serial.println("Monitoring vibration...");
}

void loop() {
  // Report once per second
  noInterrupts();
  unsigned int count = pulseCount;
  pulseCount = 0;
  interrupts();

  if (count == 0) {
    Serial.println("Still");
  } else if (count < 20) {
    Serial.print("Light vibration  (");
    Serial.print(count);
    Serial.println(" pulses)");
  } else {
    Serial.print("STRONG vibration (");
    Serial.print(count);
    Serial.println(" pulses)");
  }

  delay(1000);
}

ESP32 (MicroPython)

sw420_esp32.py
# SW-420 Vibration Sensor - ESP32 MicroPython Example
# DO -> GPIO 25, VCC -> 3V3, GND -> GND

from machine import Pin
import time

sensor = Pin(25, Pin.IN)
pulse_count = 0

def on_vibration(pin):
    global pulse_count
    pulse_count += 1

# Trigger on both edges so idle-HIGH board revisions work too
sensor.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=on_vibration)

print("Monitoring vibration...")

while True:
    pulse_count = 0
    time.sleep(1)

    if pulse_count == 0:
        print("Still")
    elif pulse_count < 20:
        print("Light vibration  ({} pulses)".format(pulse_count))
    else:
        print("STRONG vibration ({} pulses)".format(pulse_count))

Raspberry Pi (Python)

sw420_rpi.py
#!/usr/bin/env python3
# SW-420 Vibration Sensor - Raspberry Pi Example
# DO -> GPIO 17 (pin 11), VCC -> 3.3V (pin 1), GND -> GND (pin 6)

import RPi.GPIO as GPIO
import time

SENSOR_PIN = 17
pulse_count = 0

def on_vibration(channel):
    global pulse_count
    pulse_count += 1

GPIO.setmode(GPIO.BCM)
GPIO.setup(SENSOR_PIN, GPIO.IN)
# BOTH edges so idle-HIGH board revisions work too
GPIO.add_event_detect(SENSOR_PIN, GPIO.BOTH, callback=on_vibration)

print("Monitoring vibration (Ctrl+C to stop)...")

try:
    while True:
        pulse_count = 0
        time.sleep(1)

        if pulse_count == 0:
            print("Still")
        elif pulse_count < 20:
            print("Light vibration  ({} pulses)".format(pulse_count))
        else:
            print("STRONG vibration ({} pulses)".format(pulse_count))

except KeyboardInterrupt:
    print("Stopped by user")
finally:
    GPIO.cleanup()

Raspberry Pi Pico (MicroPython)

sw420_pico.py
# SW-420 Vibration Sensor - Pico MicroPython Example
# DO -> GP15, VCC -> 3V3(OUT), GND -> GND

from machine import Pin
import time

sensor = Pin(15, Pin.IN)
pulse_count = 0

def on_vibration(pin):
    global pulse_count
    pulse_count += 1

sensor.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=on_vibration)

print("Monitoring vibration...")

while True:
    pulse_count = 0
    time.sleep(1)

    if pulse_count == 0:
        print("Still")
    elif pulse_count < 20:
        print("Light vibration  ({} pulses)".format(pulse_count))
    else:
        print("STRONG vibration ({} pulses)".format(pulse_count))

Frequently Asked Questions

How do I adjust the sensitivity?
Turn the blue potentiometer while watching the output LED. Set it so the LED is off when the module sits still, then tap the surface it is mounted on — the LED should flicker. Turning toward more sensitivity catches lighter taps but also more false triggers from ambient bumps; find the point where your real events register and background noise does not.
Does DO sit LOW or HIGH when there is no vibration?
On most boards DO idles LOW and pulses HIGH during vibration, but some revisions wire the comparator the other way around. The onboard output LED tells you instantly which way yours behaves. The pulse-counting code in this manual triggers on both edges, so it works correctly on either revision without changes.
Can it measure how strong the vibration is?
Not truly — the SW-420 is a threshold switch, not a measuring sensor. That said, counting pulses per second (as the examples do) gives a usable rough proxy: harder, longer shaking produces more pulses. For real amplitude and frequency data, use a digital accelerometer such as the ADXL345 or MPU6050 and sample it fast.
Should I power it with 3.3V or 5V?
Match your board: 5V on a classic Arduino, 3.3V on ESP32, Raspberry Pi, and Pico. The module runs happily at either voltage, and its DO output swings to whatever VCC you supply — which is exactly why 3.3V boards should power it from their 3.3V rail.
My sensor triggers constantly with no vibration. What is wrong?
Almost always sensitivity set too high or an unstable mounting. Back the potentiometer off until the output LED stays dark at rest, and mount the module rigidly — a module dangling from jumper wires triggers itself every time the wires sway. Nearby motors, fans, and subwoofers also count as "vibration" to this sensor.
What is the difference between the SW-420 and the SW-520D tilt switch?
The SW-420 detects shaking and returns to its resting state when motion stops. The SW-520D is a tilt ball switch — it changes state based on orientation and stays there, making it a "which way up am I?" sensor rather than a vibration detector. Use the SW-420 for knocks and rattles, the SW-520D for tip-over and orientation detection.
Do I need a library to use it?
No. DO is a plain digital signal, so digitalRead()/attachInterrupt() on Arduino, the machine module's Pin class in MicroPython, and RPi.GPIO on the Raspberry Pi cover everything. The interrupt-driven pulse counting shown in the examples is the only technique worth borrowing.

Related Tutorials