Arduino UNO R4 - SW-420 Vibration Sensor
In this guide, we will learn how to use a SW-420 vibration sensor with the Arduino UNO R4. In detail, we will learn:
- How to wire a SW-420 vibration sensor module to an Arduino UNO R4
- How to write a program for Arduino UNO R4 to detect vibration or shock using a SW-420 sensor

Once this basic sketch is running, you can extend it to sound a buzzer, flash an LED, or send an alert whenever your project gets bumped or shaken.
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables STEM V4 IoT Starter Kit (Arduino included) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of SW-420 Vibration Sensor
The SW-420 vibration sensor module (also known as a shock sensor or vibration switch module) is built around a small spring-based switch mounted close to a metal contact inside its metal casing. An onboard LM393 comparator continuously watches that switch and turns any disturbance into a clean digital signal, while a small potentiometer on the board lets you dial in how much shaking or shock is needed before the output changes state.
The SW-420 Vibration Sensor Pinout
The SW-420 vibration sensor module has three pins:
- VCC pin: Connect to VCC (3.3V to 5V).
- GND pin: Connect to GND (0V).
- DO pin: This is an output pin. It stays LOW while the module is still and goes HIGH the moment vibration or shock is detected. Connect this pin to the input pin of Arduino UNO R4.

The SW-420 vibration sensor module also has two LED indicators.
- One LED indicator for power
- One LED indicator that lights up whenever vibration is detected
How It Works
- While nothing is shaking the module, the spring switch stays in its resting position and the LM393 comparator keeps the output pin LOW.
- As soon as vibration or shock disturbs the spring switch, the comparator flips the output pin to HIGH. Turning the onboard potentiometer raises or lowers how strong that disturbance needs to be before this happens.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Uno R4 and other components.
How To Program For SW-420 Vibration Sensor
- Sets up the Arduino UNO R4 pin as a digital input using the pinMode() function. For instance, pin 8
- Uses the digitalRead() function to check the status of a pin on the Arduino UNO R4.
Arduino UNO R4 Code - Detecting vibration
Detailed Instructions
Follow these instructions step by step:
- If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
- Connect the SW-420 vibration sensor to the Arduino Uno R4 according to the provided diagram.
- Connect the Arduino Uno R4 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
- Copy the code and open it in Arduino IDE.
- Click the Upload button in Arduino IDE to send the code to the Arduino UNO R4.
- Tap the table or gently shake the SW-420 sensor to trigger it.
- Check the results on the Serial Monitor.
Troubleshooting
If the SW-420 vibration sensor isn't behaving as expected, try these steps:
- Adjust the sensitivity: Turn the onboard potentiometer to raise or lower how much shaking or shock is needed to trigger the output.
- Isolate it from ambient vibration: Mount the sensor away from motors, fans, or other steady vibration sources that could cause false triggers.
- Check the wiring: Make sure the VCC, GND, and DO pins are connected correctly.
- Check the power supply: Make sure the power supply is stable for reliable readings.