print("This program integrates PIR sensor with ESP32")
from machine import Pin
from utime import sleep
motion = False
def handle_interrupt(pin):
global motion
motion = True
global interrupt_pin
interrupt_pin = pin
led_red = Pin(12, Pin.OUT)
pir = Pin(14, Pin.IN)
buzzer = Pin(18, Pin.OUT)
pir.irq(trigger=Pin.IRQ_RISING, handler=handle_interrupt)
while True:
if motion == True:
print('Movimiento detectado:', interrupt_pin, 'LED rojo = Encendido' )
for i in range (10):
buzzer.duty(100)
sleep(1)
buzzer.duty(0)
led_red.on()
sleep(0.5)
led_red.off()
sleep(0.5)
print('Movimiento detenido LED rojo = apagado')
motion = False