import machine
import time
from machine import Pin as pin
from time import sleep
pir_pin = machine.Pin(14, machine.Pin.IN)
led_pin = machine.Pin(13, machine.Pin.OUT)
def motion_detected(pin):
print("Motion detected!")
# Turn on the LED (optional)
led_pin.on()
pir_pin.irq(trigger=machine.Pin.IRQ_RISING, handler=motion_detected)
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("Interrupted")
finally:
pir_pin.irq(handler=None)
led_pin.off()