from machine import Pin
from time import sleep
Motion_Detected = False
def handle_interrupt(Pin):
global Motion_Detected
Motion_Detected = True
led=Pin(14,Pin.OUT)
PIR_Interrupt=Pin(13,Pin.IN)
PIR_Interrupt.irq(trigger=Pin.IRQ_RISING, handler=handle_interrupt)
while True:
if Motion_Detected:
print('Motion is detected!')
led.value(1)
sleep(20)
led.value(0)
print('Motion is stopped!')
Motion_Detected = False
else:
led.value(1)
sleep(1)
led.value(0)
sleep(1)