Raspberry Pi Pico
Passive Infrared Sensor
Passive Infrared Sensors (PIR) are commonly used in burglar alarm systems to detect the motion of humans. They work by detecting changes in the infrared radiation that they are measuring. The one I used is called the AM312, works at 3V3 and costs a couple of pounds.
This is an image of a generic PIR sensor. It has 3 pins. One will go to 3V3, one to GND and, usually the middle one, connects to the pin you are going to use to take your readings.
I connected my sensor to GP16.
from machine import Pin from time import sleep pir = Pin(16, Pin.IN, Pin.PULL_UP) def pause(): print("Pausing") sleep(5) print("Ready") pause() while True: reading = pir.value() if reading==1: print("Motion detected.") pause() sleep(0.05)
The code uses a waiting period of 5 seconds at the start and each time the sensor is triggered.