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:

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.

Arduino Nano 33 IoT SW-420 vibration sensor

Hardware Preparation

1×Arduino Nano 33 IoT
1×Micro USB Cable
1×SW-420 Vibration Sensor Module
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano

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 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.
SW-420 Vibration Sensor Pinout
image source: diyables.io

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

The wiring diagram between Arduino Nano and 33 IoT SW-420 Vibration Sensor

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.
pinMode(3, INPUT);
  • Read whether that pin is currently HIGH or LOW with the digitalRead() function.
int vibrationState = digitalRead(D3);

Arduino Nano 33 IoT Code - Detecting vibration

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-sw-420-vibration-sensor */ #define SENSOR_PIN 3 // The Arduino Nano 33 IoT pin D3 connected to the DO pin of the SW-420 vibration sensor int prev_vibration_state = LOW; // The previous state from the input pin int vibration_state; // The current reading from the input pin void setup() { // Initialize the Serial to communicate with the Serial Monitor. Serial.begin(9600); // initialize the Arduino Nano 33 IoT's pin as an input pinMode(SENSOR_PIN, INPUT); } void loop() { // read the state of the Arduino Nano 33 IoT's input pin vibration_state = digitalRead(SENSOR_PIN); if (prev_vibration_state == LOW && vibration_state == HIGH) Serial.println("Vibration detected!"); else if (prev_vibration_state == HIGH && vibration_state == LOW) Serial.println("Vibration stopped"); // save the last state prev_vibration_state = vibration_state; }

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.
Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
Arduino Nano 33 IoT
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Nano 33 IoT' on 'COM15')
New Line
9600 baud
Vibration detected! Vibration stopped Vibration detected! Vibration stopped
Ln 11, Col 1
Arduino Nano 33 IoT on COM15
2

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.

Video Tutorial

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!