from machine import Pin
import time
# Initialize hardware pins
led = Pin(1, Pin.OUT)
pir = Pin(28, Pin.IN)
motion_count = 0
while True:
if pir.value() == 1:
motion_count += 1
print(f"Motion Detected! | Total Count: {motion_count}")
led.value(1)
time.sleep(2) # Keep LED on for 2 seconds to prevent double-counting
else:
print("Area Clear (No Motion)")
led.value(0)
time.sleep(0.2) # Short polling delay for faster response