from machine import Pin, ADC
from time import sleep_ms
# 1. Create a Pin object for GPIO 32
ldr_pin = Pin(32)
# 2. Create an ADC object for that pin
adc = ADC(ldr_pin)
# 3. Set ADC resolution to 12 bits (0–4095)
adc.width(ADC.WIDTH_12BIT)
# 4. Set attenuation to 11dB → allows full range ~0–3.6V
adc.atten(ADC.ATTN_11DB)
# 5. Loop forever reading values
while True:
sensor_value = adc.read()
print("LDR Sensor Value:", sensor_value)
sleep_ms(1000)