from machine import Pin, ADC
import time
# Define LDR (Analog Input)
ldr = ADC(Pin(35)) # Use GPIO 36 (ADC0) for LDR
ldr.atten(ADC.ATTN_11DB) # Configure for full 3.3V range
# Define LED (Digital Output)
led = Pin(25, Pin.OUT) # Use GPIO 25 for LED
# Threshold for light intensity (adjust based on your setup)
THRESHOLD = 2000 # Adjust this value as needed (0-4095 for 12-bit ADC)
while True:
# Read the LDR value
light_value = ldr.read() # Value ranges from 0 to 4095
print(f"Light Intensity: {light_value}")
# Control the LED based on the threshold
if light_value < THRESHOLD:
led.value(1) # Turn on LED (low light detected)
print("LED ON")
else:
led.value(0) # Turn off LED (sufficient light detected)
print("LED OFF")
time.sleep(0.5) # Delay for readability