from machine import Pin
import utime
# Setup
LED = Pin(14, Pin.OUT)
PIR = Pin(13, Pin.IN, Pin.PULL_DOWN) # Most PIR sensors work better with PULL_DOWN
LED.low() # Turn off LED initially
print("PIR Sensor warming up...")
utime.sleep(2) # Warm-up time for PIR sensor
# Loop to detect motion
while True:
motion = PIR.value()
print("Motion value:", motion)
if motion == 1:
print("Motion detected!")
LED.high()
utime.sleep(3) # Keep LED on for 3 seconds
else:
print("No motion")
LED.low()
utime.sleep(0.5)