from machine import Pin # Enable input pin. We will put a button on this pin pir = Pin(34, Pin.IN) # Create handler def handle_interrupt(pin): print("You triggered the interrupt") # attach interrupt to pin pir.irq(trigger=Pin.IRQ_RISING, handler=handle_interrupt) # You don't need a While loop here. If you leave it off you will get a REPL with your objects still set.