from machine import Pin
import time
# Setup Pins
pir = Pin(15, Pin.IN)
buzzer = Pin(14, Pin.OUT)
print("System Active: Monitoring for movement...")
while True:
if pir.value() == 1:
# What happens when motion is detected
print("ALARM! Motion detected in the room.")
buzzer.value(1) # Turn buzzer ON
time.sleep(1) # Sound for 1 second
else:
# What happens when no motion is detected
buzzer.value(0) # Ensure buzzer is OFF
time.sleep(0.1) # Tiny delay to save processing power