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)

BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT
NOCOMNCVCCGNDINLED1PWRRelay Module