Project
Detecting Motion with HC-SR501 PIR Sensor on Raspberry Pi Pico
Overview
Learn how to use the HC-SR501 PIR motion sensor with a Raspberry Pi Pico to detect movement. This project is useful for security systems, automatic lights, and motion-activated alarms.
Instructions
Step by step
1. Connect the PIR VCC pin to 3.3V.
2. Connect the PIR GND pin to GND.
3. Connect the PIR OUT pin to GP16.
4. Run the code and open the Serial/console output.
5. Click or toggle the PIR sensor in the simulator to change its motion state.
6. When motion is detected, the output should print "Motion detected!".
7. When there is no motion, the output should print "No motion".
Code
Source code
from machine import Pin
import utime
pir = Pin(16, Pin.IN)
while True:
if pir.value() == 1:
print("Motion detected!")
else:
print("No motion")
utime.sleep(1)
Related