from machine import Pin
from time import sleep
pir_pin = Pin(14, Pin.IN)
led_pin = Pin(13, Pin.OUT)
buzzer_pin = Pin(12, Pin.OUT)
while True:
if pir_pin.value() == 1:
print("Motion Detected")
buzzer_pin.value(1)
led_pin.value(1)
sleep(3) # Keep buzzer and LED on for 3 seconds
buzzer_pin.value(0)
led_pin.value(0)
print("Motion Stopped")
sleep(0.1) # Add a slight delay to reduce CPU usage
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4
pir1:VCC
pir1:OUT
pir1:GND
led1:A
led1:C
r1:1
r1:2
bz1:1
bz1:2