from machine import Pin
import utime
# Set up the inputs and outputs
pir_sensor = Pin(18, Pin.IN)
led = Pin(11, Pin.OUT)
buzzer = Pin(14, Pin.OUT) # Added the buzzer on GP14
print("Sensor warming up... waiting for motion.")
utime.sleep(2) # Give the PIR sensor 2 seconds to stabilize
while True:
if pir_sensor.value() == 1:
print("Motion detected!")
led.value(1) # Turn LED ON
buzzer.value(1) # Turn Buzzer ON
utime.sleep(0.5) # Keep them on for half a second
else:
led.value(0) # Turn LED OFF
buzzer.value(0) # Turn Buzzer OFF
utime.sleep(0.1) # Short delay to keep the loop from running too fastLoading
pi-pico-w
pi-pico-w