Project
Detecting Vibration with SW-420 on Raspberry Pi Pico
Overview
Learn how to use the SW-420 vibration sensor with a Raspberry Pi Pico to detect shaking or movement. This project is useful for tamper alarms, vibration alerts, and simple security systems.
Instructions
Step by step
1. Connect the SW-420 VCC pin to 3.3V.
2. Connect the SW-420 GND pin to GND.
3. Connect the SW-420 DO pin to GP17.
4. Run the code and open the Serial/console output.
5. Click or toggle the SW-420 sensor in the simulator.
6. When vibration is detected, the output should print "Vibration detected!".
7. When stable, the output should print "No vibration".
Code
Source code
from machine import Pin
import utime
vibration = Pin(17, Pin.IN)
while True:
if vibration.value() == 1:
print("Vibration detected!")
else:
print("No vibration")
utime.sleep(0.5)
Related