print("Hello, ESP32!")
#####################################
###### IMPORT LIBRARIES
from machine import Pin
from time import sleep
#####################################
###### PIN CONFIGURATIONS
# Configure the LED and PIR motion sensor pins
pin_led = Pin(19, Pin.OUT)
pin_pir = Pin(23, Pin.IN) # PIR sensor output connected to GPIO2
#####################################
###### SUBROUTINE FOR INTERRUPT #####
def interrupt_motion(pin):
print('Motion detected:', pin)
pin_led.on()
sleep(5)
pin_led.off()
# Interrupt trigger when motion is detected (rising edge)
pin_pir.irq(trigger=Pin.IRQ_RISING, handler=interrupt_motion)
#####################################
###### MAIN ROUTINE
def main():
while True:
# LED stays off unless motion is detected
pin_led.off()
sleep(10)
#####################################
###### EXECUTE MAIN ROUTINE
if __name__ == '__main__':
main()