from machine import Pin, ADC
import time
# Define the pins
ldr_pin = ADC(26) # LDR connected to GP26 (ADC0)
led_pin = Pin(11, Pin.OUT) # LED connected to GP15
# Threshold for turning the LED on/off
ldr_threshold = 30000 # Change based on light conditions
# Function to simulate LDR readings (in Wokwi)
def read_ldr():
# Simulate LDR reading with varying values
simulated_value = int(input("Enter simulated LDR value (0 to 65535): "))
return simulated_value
# Main loop
while True:
ldr_value = read_ldr() # Get the simulated LDR reading
print("LDR Value:", ldr_value) # Print to check the readings
# LED logic based on LDR value
if ldr_value > ldr_threshold: # If light is strong enough
led_pin.value(1) # Turn on the LED
else:
led_pin.value(0) # Turn off the LED
time.sleep(1) # Small delay