import machine
import time
# -------- PINS ----------
ldr = machine.ADC(26) # LDR connected to ADC0
pir = machine.Pin(16, machine.Pin.IN) # PIR sensor
led = machine.PWM(machine.Pin(15)) # LED using PWM
led.freq(1000)
# -------- Threshold Values ----------
LDR_THRESHOLD = 25000 # below this = night (adjust based on your LDR)
BRIGHTNESS_NORMAL = 30000 # dim mode
BRIGHTNESS_HIGH = 65000 # full brightness
print("Smart Street Light System Started...\n")
while True:
ldr_value = ldr.read_u16()
motion = pir.value()
if ldr_value < LDR_THRESHOLD:
# NIGHT
if motion == 1:
# Movement detected → full brightness
led.duty_u16(BRIGHTNESS_HIGH)
print("Night | Motion Detected | LED High Brightness")
else:
# No motion → dim brightness
led.duty_u16(BRIGHTNESS_NORMAL)
print("Night | No Motion | LED Dim")
else:
# DAY
led.duty_u16(0)
print("Daytime | LED OFF")
time.sleep(0.5)