from machine import Pin
import utime
pir_pin = Pin(16, Pin.IN)
buzzer_pin = Pin(17, Pin.OUT)
def motion_detected(pin):
print("Motion detected!")
buzzer_pin.on()
utime.sleep(2)
buzzer_pin.off()
pir_pin.irq(trigger=Pin.IRQ_RISING, handler=motion_detected)
try:
while True:
print("Waiting for motion...")
utime.sleep(1)
except KeyboardInterrupt:
pir_pin.irq(handler=None)
buzzer_pin.off()
print("Exiting...")