Arduino UNO Q - SW-420 Vibration Sensor

The SW-420 vibration sensor module watches for shock or vibration and reports it as a clean digital signal, so your program never has to interpret a noisy analog wave. Inside the module, a small spring-based switch sits close to a metal contact; the onboard LM393 comparator keeps an eye on that switch and flips its output the instant vibration disturbs it, while a small potentiometer on the board lets you dial in how much shaking counts as an event. Paired with the Arduino UNO Q's Bridge and Telegram integration, you can get an instant phone alert the moment something is bumped, shaken, or tampered with.

In this tutorial, you will learn:

Arduino UNO Q SW-420 Vibration Sensor

Hardware Preparation

1×Arduino UNO Q
1×USB Cable for Arduino Uno Q
1×SW-420 Vibration Sensor Module
1×Jumper Wires
1×Recommended: Screw Terminal Block Shield for Arduino Uno
1×Recommended: Sensors/Servo Expansion Shield for Arduino Uno
1×Recommended: Breadboard Shield for Arduino Uno
1×Recommended: Enclosure for Arduino Uno
1×Recommended: Prototyping Base Plate & Breadboard Kit for Arduino UNO

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 the SW-420 Vibration Sensor

The SW-420 vibration sensor module is built around a tiny spring-based vibration switch. While the module sits still, the switch stays in one resting position; the moment vibration or shock disturbs it, the switch's contact state flips. An onboard LM393 comparator turns that mechanical change into a clean digital signal, and a small potentiometer lets you adjust exactly how much shaking is needed before the output triggers. The module outputs a simple digital signal:

  • LOW: No vibration — module is idle
  • HIGH: Vibration or shock detected

The module includes:

  • VCC pin: 3.3V to 5V power supply
  • GND pin: Ground
  • DO pin: Digital output — LOW = idle, HIGH = vibration detected
  • PWR LED: Power indicator
  • Status LED: Lights up whenever the output goes HIGH
SW-420 Vibration Sensor Pinout
image source: diyables.io

Wiring Diagram

The wiring diagram between Arduino UNO Q SW-420 Vibration Sensor

This image is created using Fritzing. Click to enlarge image

SW-420 Vibration Sensor Pin Arduino UNO Q MCU
GND GND
VCC 5V
DO D8

How To Program For SW-420 Vibration Sensor

  • Configure the sensor pin as a digital input:
pinMode(SENSOR_PIN, INPUT);
  • Read the digital output:
int vibration_state = digitalRead(SENSOR_PIN);
  • Detect vibration events by comparing to the previous state:
if (prev_state == LOW && vibration_state == HIGH) Serial.println("Vibration DETECTED"); else if (prev_state == HIGH && vibration_state == LOW) Serial.println("Vibration stopped — idle again"); prev_state = vibration_state;

Arduino UNO Q Code

The Arduino UNO Q has two processors working together:

  • The STM32 MCU reads the SW-420 vibration sensor's digital output and detects vibration events
  • The Qualcomm MPU runs Debian Linux with Wi-Fi — in this section, only the MCU is programmed. A later section shows how both processors work together via Bridge.
/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-sw-420-vibration-sensor */ // SW-420 vibration sensor DO pin: LOW = idle, HIGH = vibration detected #define SENSOR_PIN 8 // The Arduino UNO Q MCU pin connected to DO of the SW-420 vibration sensor int prev_vibration_state = LOW; int vibration_state; void setup() { Serial.begin(9600); pinMode(SENSOR_PIN, INPUT); Serial.println("Arduino UNO Q SW-420 Vibration Sensor ready"); } void loop() { 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 — idle again"); prev_vibration_state = vibration_state; }

Detailed Instructions

First time with Arduino UNO Q? Follow the Getting Started with Arduino UNO Q tutorial before proceeding.

  • Connect: Wire the SW-420 vibration sensor to the Arduino UNO Q MCU as shown in the wiring diagram.
  • Open Arduino App Lab: Launch Arduino App Lab and wait until it detects your Arduino UNO Q.
  • Create a new App: Click the Create New App button.
Create New App in Arduino App Lab on Arduino UNO Q
  • Give the App a name, for example: SW420VibrationSensor
  • Click Create to confirm.
Arduino App Lab App folders and files on Arduino UNO Q
  • Paste the sketch: Copy the MCU code above and paste it into sketch/sketch.ino.
  • Upload: Click the Run button in Arduino App Lab.
Click Run button in Arduino App Lab on Arduino UNO Q
  • Tap or shake the sensor gently — observe the Serial Monitor output.
  • Turn the onboard potentiometer if the sensor feels too sensitive or not sensitive enough.

App Lab Console Output

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
Message (Enter to send a message to "Newbiely" on usb(2820070321))
New Line
9600 baud
[2026-05-06 14:20:01] Arduino UNO Q SW-420 Vibration Sensor ready [2026-05-06 14:20:07] Vibration DETECTED [2026-05-06 14:20:07] Vibration stopped — idle again [2026-05-06 14:20:12] Vibration DETECTED [2026-05-06 14:20:13] Vibration stopped — idle again

Bridge: Linux + MCU

This section shows how to program both processors of the Arduino UNO Q so the Linux side can read vibration state and receive vibration events via Bridge:

  • The SW-420 vibration sensor is connected to the MCU — the MCU monitors the digital output continuously and caches the current state
  • The MPU cannot read the sensor pin directly — it calls Bridge functions to get the current state or check for new vibration events
  • The MPU has Wi-Fi — running full Debian Linux, it can send Telegram alerts the moment vibration is detected
  • Arduino_RouterBridge enables RPC communication between the two processors
  • ⚠️ /dev/ttyHS1 (Linux) and Serial1 (MCU) are RESERVED by the router — never open them in user code

In short: MCU detects vibration via DO pin → sets event flag → MPU polls Bridge → MPU sends Telegram alert.

MCU Code (Bridge)

/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-sw-420-vibration-sensor */ #include "Arduino_RouterBridge.h" #define SENSOR_PIN 8 // The Arduino UNO Q MCU pin connected to DO of the SW-420 vibration sensor bool cached_vibration = false; // true = vibration present bool vibration_event = false; // true = new vibration detected (rising edge) int prev_state = LOW; String get_state(String arg) { return cached_vibration ? "vibrating" : "idle"; } String get_event(String arg) { if (vibration_event) { vibration_event = false; return "vibration_detected"; } return "none"; } void setup() { Bridge.begin(); Monitor.begin(); pinMode(SENSOR_PIN, INPUT); Bridge.provide("get_state", get_state); Bridge.provide("get_event", get_event); Monitor.println("Arduino UNO Q SW-420 Vibration Sensor Bridge ready"); } void loop() { int current = digitalRead(SENSOR_PIN); if (prev_state == LOW && current == HIGH) { // Idle → Vibrating cached_vibration = true; vibration_event = true; Monitor.println("Vibration detected!"); } else if (prev_state == HIGH && current == LOW) { // Vibrating → Idle cached_vibration = false; Monitor.println("Idle again."); } prev_state = current; }

Python Code (Bridge)

""" This Arduino UNO Q script was developed by newbiely.com This Arduino UNO Q script is made available for public use without any restriction For comprehensive instructions and wiring diagrams, please visit: https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-sw-420-vibration-sensor """ from arduino.app_utils import * import time def loop(): state = Bridge.call("get_state") print(f"Vibration state: {state}") time.sleep(0.5) App.run(user_loop=loop)

Detailed Instructions

  • Connect: Wire the SW-420 vibration sensor to the Arduino UNO Q as shown in the wiring diagram.
  • Open Arduino App Lab and create a new App named VibrationSensorBridge.
  • Paste the MCU sketch into sketch/sketch.ino.
  • Paste the Python code into the Python file.
  • Install the library: Click the Add sketch library button (the open book icon with a + sign) in the left sidebar.
Add sketch library in Arduino App Lab on Arduino UNO Q
  • Search for Arduino_RouterBridge created by Arduino and click the Install button.
My Apps / DIYables Apps
Run
Bricks
No bricks added...
Sketch Libraries
No sketch libra...
Files
python
sketch
.gitignore
README.md
app.yaml
sketch.ino
Add sketch library
Arduino_RouterBridge Arduino

This library provides a simple RPC bridge for Arduino UNO Q boards, allowing communication between the board and other devices using MsgPack serialization.

0.4.1
Install
More Info
  • Upload: Click the Run button.
Click Run button in Arduino App Lab on Arduino UNO Q
  • Tap the sensor — observe the event appear in both consoles.

App Lab Console Output

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
Message (Enter to send a message to "Newbiely" on usb(2820070321))
New Line
9600 baud
[2026-05-06 14:25:01] Arduino UNO Q SW-420 Vibration Sensor Bridge ready [2026-05-06 14:25:09] Vibration detected! [2026-05-06 14:25:10] Idle again.
DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-05-06 14:25:02] Vibration state: idle [2026-05-06 14:25:04] Vibration state: idle [2026-05-06 14:25:09] Vibration state: vibrating [2026-05-06 14:25:11] Vibration state: idle

Telegram

Receive instant Telegram alerts when vibration is detected on the Arduino UNO Q SW-420 vibration sensor.

MCU sketch: Keep the same MCU sketch from the previous Bridge section.

Python Code (Telegram)

""" This Arduino UNO Q script was developed by newbiely.com This Arduino UNO Q script is made available for public use without any restriction For comprehensive instructions and wiring diagrams, please visit: https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-sw-420-vibration-sensor """ from arduino.app_utils import * import requests import time TELEGRAM_BOT_TOKEN = "YOUR_TELEGRAM_BOT_TOKEN" CHAT_ID = "YOUR_CHAT_ID" last_update_id = 0 def get_updates(): global last_update_id url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/getUpdates" params = {"offset": last_update_id + 1, "timeout": 5} try: response = requests.get(url, params=params, timeout=10) data = response.json() if data["ok"]: return data["result"] except Exception as e: print(f"Error getting updates: {e}") return [] def send_message(chat_id, text): url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage" payload = {"chat_id": chat_id, "text": text} try: requests.post(url, data=payload, timeout=10) except Exception as e: print(f"Error sending message: {e}") def loop(): # Auto-alert on new vibration detection event = Bridge.call("get_event") if event == "vibration_detected": print("Vibration detected! Sending Telegram alert.") send_message(CHAT_ID, "🔨 Vibration detected by Arduino UNO Q!") # Handle Telegram commands updates = get_updates() for update in updates: last_update_id = update["update_id"] if "message" not in update: continue message = update["message"] chat_id = message["chat"]["id"] text = message.get("text", "").strip() print(f"Received: {text}") if text == "/start": send_message(chat_id, "Arduino UNO Q SW-420 Vibration Sensor Bot\n" "/state - Current vibration state (vibrating / idle)\n" "Automatic alert when vibration is detected") elif text == "/state": result = Bridge.call("get_state") send_message(chat_id, f"Vibration state: {result}") App.run(user_loop=loop)

Detailed Instructions

  • Replace YOUR_TELEGRAM_BOT_TOKEN with your actual bot token from BotFather.
  • Replace YOUR_CHAT_ID with your Telegram chat ID.
  • Paste this Python code into your App's Python file (keep the same MCU sketch).
  • Click the Run button — tap or shake the sensor to trigger a Telegram alert.

App Lab Console Output

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-05-06 14:30:00] Waiting for Telegram messages... [2026-05-06 14:30:06] Vibration detected! Sending Telegram alert. [2026-05-06 14:30:15] Received: /state
Telegram
Telegram 12:45
Welcome to Telegram!
ArduinoBot 10:19
Chatting with Arduino...
telegram-botfather
BotFather Yesterday
Your bot has been created.

ArduinoBot

bot
Today
🔨 Vibration detected by Arduino UNO Q!
10:15 AM
/state
10:16 AM ✓✓
Vibration state: idle
10:17 AM
/state
10:18 AM ✓✓
Vibration state: vibrating
10:19 AM

OpenClaw

You can adapt the OpenClaw to this tutorial by refering the instruction on Arduino Uno Q - OpenClaw Tutorial

Project Ideas

You can build many useful projects with the SW-420 vibration sensor and Arduino UNO Q:

  • Door/Window Tamper Alert: Stick the sensor to a door or window — if someone forces or knocks on it, the MPU sends an instant Telegram alert so you know right away
  • Parcel Shock Logger: Tape the sensor inside a shipping box — the MPU timestamps every shock event to a log file on Linux so you can tell if a package was mishandled in transit
  • Washing Machine Watchdog: Mount the sensor on an appliance — the MPU tracks vibration events via Bridge and sends a Telegram message if the machine shakes abnormally hard or won't stop at the expected time
  • Earthquake/Impact Demo Toy: Use the sensor as a simple early-warning demo — the MCU flags any sudden shock instantly, and the MPU broadcasts a Telegram warning within moments
  • Tutorial Equipment Monitor: Attach the sensor to a running tool or machine — the MPU polls Bridge continuously and alerts you by Telegram the moment unexpected vibration suggests the equipment needs attention

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!