ESP32 C3 Super Mini - SW-420 Vibration Sensor

The SW-420 vibration sensor module wakes up your ESP32 C3 Super Mini the moment something shakes, bumps, or knocks against it, making it a handy building block for shock alarms, impact counters, and shipment monitors. This tutorial walks through wiring an SW-420 module to your board and writing the sketch that reacts to vibration events.

In this tutorial, you'll learn:

ESP32 C3 Super Mini SW-420 vibration sensor

Once the basic sketch is running, you can extend it to sound a buzzer, send a notification, or log every shock event your project picks up.

Hardware Preparation

1×ESP32 C3 Super Mini
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×SW-420 Vibration Sensor Module
1×Breadboard
1×Jumper Wires
1×Optionally, 5V Power Adapter

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of SW-420 Vibration Sensor

The SW-420 is a shock-detection module built around a small spring-based vibration switch. Inside the module, the spring sits close to a metal contact; any knock or shake momentarily disturbs it, and the onboard LM393 comparator turns that disturbance into a clean digital pulse your ESP32 C3 Super Mini can read directly.

Key features:

  • Onboard LM393 comparator for a clean, debounced digital signal
  • Adjustable trigger threshold via an onboard potentiometer
  • Runs happily from 3.3V to 5V, matching the ESP32 C3 Super Mini logic level
  • Onboard LEDs show power and trigger status at a glance
  • No library required — just a couple of GPIO calls

The SW-420 Vibration Sensor Pinout

Wiring is simple since the module exposes only three pins.

  • VCC pin: Connect to power supply (3.3V to 5V)
  • GND pin: Connect to ground (0V)
  • DO pin: Digital output pin - stays LOW while idle, goes HIGH when vibration or shock is detected - connect to an ESP32 C3 Super Mini digital input pin
SW-420 Vibration Sensor Pinout
image source: diyables.io

Additional features:

  • Power LED stays lit whenever the board is powered
  • Trigger LED flashes on briefly each time the DO pin goes HIGH

How It Works

A small onboard trimmer potentiometer sets how strong a knock needs to be before the comparator flips its output, so you can tune the module from feather-light taps to hard impacts.

Digital output behavior:

  • At rest, no vibration → DO pin stays LOW
  • A knock, shake, or shock disturbs the internal switch → DO pin goes HIGH
  • Turn the onboard potentiometer clockwise or counter-clockwise → raises or lowers the sensitivity threshold

Wiring Diagram

Wire the SW-420 module to your ESP32 C3 Super Mini as shown below.

Important notes:

  • Note: Power down the board before connecting or disconnecting wires
  • Note: Only three wires are needed — VCC, GND, and DO
  • Note: No pull-up resistor is needed; the module's comparator already drives the DO line
The wiring diagram between ESP32 C3 Super Mini SW-420 Vibration Sensor

This image is created using Fritzing. Click to enlarge image

SW-420 Vibration Sensor Pin ESP32 C3 Super Mini Pin
VCC 3.3V or 5V
GND GND
DO D3 (GPIO3)

How To Program For SW-420 Vibration Sensor

Reading the SW-420 module only takes a digital input pin and a comparison against its previous state.

What the code does:

  • Sets up the ESP32 C3 Super Mini pin connected to DO as a digital input
  • Polls the pin on every loop iteration
  • Compares the new reading against the previous one to spot a change
  • Prints a message on Serial Monitor the instant vibration starts or stops

Step 1 - Initialize the pin:

pinMode(D3, INPUT);

Step 2 - Read the sensor state:

int vibrationState = digitalRead(D3);

ESP32 C3 Super Mini Code - Detecting the vibration

/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-sw-420-vibration-sensor */ #define SENSOR_PIN 3 // The ESP32 C3 SuperMini pin 3 connected to the DO pin of the SW-420 vibration sensor int prev_vibration_state = LOW; // The previous state from the input pin (LOW = idle, at rest) int vibration_state; // The current reading from the input pin void setup() { // Initialize the Serial to communicate with the Serial Monitor. Serial.begin(115200); // initialize the ESP32's pin as an input pinMode(SENSOR_PIN, INPUT); } void loop() { // read the state of the ESP32's input pin vibration_state = digitalRead(SENSOR_PIN); if (prev_vibration_state == LOW && vibration_state == HIGH) Serial.println("The vibration has been detected"); else if (prev_vibration_state == HIGH && vibration_state == LOW) Serial.println("The vibration has stopped"); // save the the last state prev_vibration_state = vibration_state; }

Detailed Instructions

  • New to ESP32 C3 Mini? Complete our Getting Started with ESP32 C3 Mini tutorial first to set up your development environment.
  • Check the wiring: Match every connection against the wiring diagram above
  • Copy the code: Copy the provided sketch into Arduino IDE
  • Select your board: Choose ESP32 C3 Super Mini from the boards menu
  • Upload the code: Click Upload to flash the sketch onto your ESP32 C3 Super Mini
  • Open Serial Monitor: Set the baud rate to 115200
  • Test the sensor: Tap or gently shake the SW-420 module
  • Observe the output: Watch Serial Monitor for the vibration messages
Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
09:41:02.118 - The vibration has been detected 09:41:02.436 - The vibration has stopped 09:41:07.902 - The vibration has been detected 09:41:08.510 - The vibration has stopped 09:41:15.271 - The vibration has been detected 09:41:16.049 - The vibration has stopped
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2

From here you can wire in a buzzer, blink an onboard LED, or push an alert over WiFi whenever a shock event fires. See the ideas and challenges below for inspiration.

Application and Project Ideas

Put your ESP32 C3 Super Mini and SW-420 module to work in projects that react to shock and movement.

  • Build a vibration-triggered alarm that sounds a buzzer when someone bumps a door or window
  • Log every shock a package takes in transit to catch rough handling during shipping
  • Monitor a washing machine or motor for abnormal vibration that signals an imbalance
  • Turn knocks on a door into a doorbell trigger or smart-lock wake-up signal
  • Build a simple impact counter that tallies how many times an object has been struck

Video Tutorial

Watch the video below for a visual walkthrough of this project.

Challenge Yourself

Push your ESP32 C3 Super Mini SW-420 project further with these challenges.

  • Easy: Light an LED for two seconds every time vibration is detected
  • Easy: Print a running total of vibration events instead of just on/off messages
  • Medium: Add a debounce timer so a single knock doesn't register as several events
  • Medium: Combine the sensor with a buzzer to build a simple shock alarm
  • Advanced: Log timestamped shock events to an SD card or send them over WiFi to a server

Troubleshooting

If your ESP32 C3 Super Mini isn't catching vibration events correctly, work through these checks.

Common issues and fixes:

  • Adjust the potentiometer: Too sensitive or not sensitive enough — turn the onboard trimmer to tune the trigger threshold
  • Isolate ambient vibration: Mount the module away from motors, fans, or surfaces that shake on their own to avoid constant false triggers
  • Check the wiring: Confirm VCC, GND, and DO match the wiring diagram — a loose DO connection reads as constant LOW
  • Verify the power supply: Unstable power can cause the comparator to chatter or miss real events
  • Watch the trigger LED: It should flash whenever DO goes HIGH — if it never lights up during a hard tap, recheck the sensitivity setting

Function References

Learn More

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!