from machine import Pin
from time import sleep
# Define pin numbers for the PIR sensor, LED bulb, and buzzer
pir_pin = 10
led_pin = 11
buzzer_pin = 12
# Create PIR, LED, and buzzer objects, setting PIR as IN, LED as OUT, and buzzer as OUT
pir = Pin(pir_pin, Pin.IN)
led = Pin(led_pin, Pin.OUT)
buzzer = Pin(buzzer_pin, Pin.OUT)
# Initialize the LED and buzzer states as off
led.value(0)
buzzer.value(0)
# Continuously read data from the PIR sensor
while True:
if pir.value() == 1:
print(f"PIR value: {pir.value()} Status: Motion detected!")
# Turn on the LED bulb and buzzer
led.value(1)
buzzer.value(1)
else:
print(f"PIR value: {pir.value()} Status: Waiting for movement...")
# Turn off the LED bulb and buzzer
led.value(0)
buzzer.value(0)
# PIR sensor checks for movement every second
sleep(1)