from machine import Pin
import time
# Set up the PIR sensor
pir_sensor = Pin(15, Pin.IN) # GP15 as input pin
buzzer = Pin(16, Pin.OUT)
# Main loop
print("PIR Sensor Test: Waiting for motion...")
while True:
if pir_sensor.value() == 1: # Motion detected
print("Motion Detected!")
buzzer.value(1)
time.sleep(2) # Delay to avoid multiple detections
else:
print("No motion...")
buzzer.value(0)
time.sleep(0.1) # Short delay to check again