import time
from machine import pin,ADC
# Setup pins
LDR_PIN = ADC(Pin(26)) # LDR connected to GP26 (ADC0)
RELAY_PIN = Pin(2, Pin.OUT) # Relay conneted to GP2
# Relay the control theresholds
THRESHOLD = 20000 # Adjust based on your LDR sensitivity
while True
# Read the LDR value (0-65535)
ldr_value =LDR_PIN.read_u16()
# Control the relay based on light level1
if ldr_value < THRESHOLD:
RELAY_PIN.value(1) # Turn relay ON
else:
RELAY_PIN.value(0) # Turn relay OFF
time.sleep(0.5)