Sensing the world · Lesson
10 min read
Light sensor (LDR)
Turn changing resistance into a voltage with a divider, and build a night light.
What You Will Learn
- Build a voltage divider with an LDR
- Choose a threshold
- Make decisions from sensor data
An LDR (light-dependent resistor) has high resistance in the dark (hundreds of kΩ) and low resistance in bright light (a few hundred Ω). The Arduino can't measure resistance directly, so we pair it with a fixed 10 kΩ resistor to make a voltage divider.
With the LDR from 5 V to A0 and 10 kΩ from A0 to GND, more light means a higher reading.
Automatic night lightarduino-uno
Note: Lower the Light slider until the lamp turns on. Adjust DARK_BELOW in the code to change the switching point.
Add hysteresis (two thresholds, e.g. on below 380, off above 420) so the lamp doesn't flicker at dusk.
Check Your Understanding
Test what you learned in this lesson