Photoresistor (LDR)
light sensor
A resistor that changes its resistance with light: ~1 MΩ in the dark, ~1 kΩ in sunlight. Use it to make an automatic night light.
Open the course →How it works
By itself the ESP32 cannot read resistance, only voltage. So the LDR goes into a voltage divider with a fixed 10 kΩ resistor: 3V3 → LDR → (measuring point) → 10 kΩ → GND. In light the LDR has low resistance → the voltage at the measuring point is high; in the dark → low. The ESP32 reads it with analogRead().
Pins and wiring
| Pin | What it is | Where it connects / why |
|---|---|---|
| End 1 | No polarity | → 3V3. |
| End 2 | No polarity | → ADC pin (e.g. GPIO 35) AND to the 10 kΩ resistor to GND. |
Specifications
Resistance light~1 – 10 kΩ
Resistance dark~0.5 – 1 MΩ
Response time~20–30 ms
Max voltage150 V
Partner resistor10 kΩ
Tips and typical mistakes
- The values depend on the room — do not hard-code them; measure in light/dark and set a threshold in the middle.
- If the logic is inverted (high value in the dark), swap the LDR and the resistor in the divider.