Arduino Nano 33 IoT - SW-420 Vibration Sensor
The SW-420 vibration sensor module can catch sudden shocks or shaking that a project needs to react to, for example a knock-alert box, a package that must stay still during shipping, or a simple burglar alarm. Combined with the Arduino Nano 33 IoT, it makes a compact way to notice motion events without any moving parts to wear out. In this guide, we will explore:
- How to wire the SW-420 vibration sensor module to the Arduino Nano 33 IoT
- How to write Arduino Nano 33 IoT code that reports vibration events from the sensor
Once the basic detection works, you could extend the sketch to sound a buzzer, flash an LED, or push a notification whenever vibration is picked up.

Hardware Preparation
Or you can buy the following kits:
| 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 reacts to shaking or shock and reports it as a clean digital signal. Inside the module sits a small spring-based switch positioned close to a metal contact; an onboard LM393 comparator watches that switch and flips its output whenever vibration disturbs it, while a small potentiometer on the board lets you dial in how strong the shaking must be before it counts.
The SW-420 Vibration Sensor Pinout
This module exposes three pins.
- VCC pin: Connect this pin to a power supply between 3.3V and 5V.
- GND pin: Connect this pin to ground (0V).
- DO pin: This pin outputs the vibration reading — it stays LOW while the module is still and switches to HIGH once vibration or shock is picked up. Connect it to an input pin on the Arduino Nano 33 IoT.

The board also carries two onboard LEDs.
- One LED simply confirms the module is powered.
- The other LED mirrors the DO pin, lighting up whenever vibration is currently detected.
How It Works
The heart of the sensor is a tiny spring switch tuned by the onboard comparator. Here is what happens on the output pin:
- While the module sits still, the spring switch stays open and the LM393 comparator holds the output pin LOW.
- The instant vibration or a knock disturbs the spring, the switch closes and the comparator drives the output pin HIGH.
Turning the onboard potentiometer changes the trigger threshold, so you can make the module ignore light taps or, conversely, catch even faint shaking.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
How To Program For SW-420 Vibration Sensor
- Configure the chosen Arduino Nano 33 IoT pin as a digital input with the pinMode() function. This example uses pin D3.
Arduino Nano 33 IoT Code - Detecting vibration
Detailed Instructions
If you are new to the Arduino Nano 33 IoT, be sure to check out our Getting Started with Arduino Nano 33 IoT tutorial. Then, follow these steps:
- Wire up the sensor module and the Arduino Nano 33 IoT following the diagram above.
- Use a USB cable to connect the Arduino Nano 33 IoT board to your computer.
- Launch the Arduino IDE on your computer.
- Select the Arduino Nano 33 IoT board and choose its corresponding COM port.
- Copy the above code and open it in the Arduino IDE.
- Click the Upload button in the Arduino IDE to send the code to the Arduino Nano 33 IoT.
- Give the SW-420 module a light tap or shake it gently.
- Watch the readings appear in the Serial Monitor.
From here, you could trigger a buzzer, blink an LED, or log an event whenever vibration shows up. For more details and easy step-by-step instructions, check the tutorials at the end of this guide.
Troubleshooting
If the SW-420 vibration sensor is not behaving as expected, work through these checks:
- Adjust the sensitivity: Turn the onboard potentiometer to raise or lower how much shaking is needed before the DO pin switches HIGH.
- Isolate ambient vibration: Nearby motors, footsteps, or a wobbly surface can trigger false readings, so mount the module on a stable base away from unrelated sources of shaking.
- Check the wiring: Confirm the VCC, GND, and DO pins are connected exactly as shown in the diagram.
- Check the power supply: An unstable or noisy supply can make the comparator's output unreliable, so verify the Arduino Nano 33 IoT is receiving clean, steady power.