from machine import Pin
from time import sleep
motion = False
def handle_interrupt(pin):
    global motion
    motion=True
    global interrupt_pin
    interrupt_pin=pin
led =Pin(12,Pin.OUT)
pir=Pin(14,Pin.IN)
pir.irq(trigger=Pin.IRQ_RISING,handler=handle_interrupt)
while True:
    if motion:
        print('Motion detected! Interrupt caused by:',interrupt_pin)
        led.value(1)
        sleep(20)
        led.value(0)
        print('Motion Stopped!')
        motion = False