Sensors Part 3: The LDR — the resistor that sees light
Build an automatic night light with an LDR divider.
A resistor that can SEE light? Meet the LDR 💡🌙
1️⃣ THE LDR (light-dependent resistor): in bright light it's about 1 kΩ. In the dark it goes up to about 1 MΩ — a million ohms! More light = less resistance.
2️⃣ THE DIVIDER: 5 V → LDR → A0 → 10 kΩ → GND. Now the voltage at A0 follows the light: about 4.5 V in bright light, about 0.05 V in the dark.
3️⃣ THE CODE — an automatic night light:int light = analogRead(A0);if (light < 300) digitalWrite(13, HIGH);else digitalWrite(13, LOW);
(pinMode(13, OUTPUT) in setup)
More light, less resistance!
int light = analogRead(A0);
if (light < 300) digitalWrite(13, HIGH);
else digitalWrite(13, LOW);Read the voiceover (transcript)
- A resistor that can see light?
- This is an LDR. Bright light: about a thousand ohms. Dark: up to a million!
- Put it in a divider with a ten k resistor. The voltage at A zero follows the light.
- Dark? The reading drops below three hundred, so the LED turns on. A night light!
- More light, less resistance!
- Next: distance with sound! Follow for part four!
Related lessons
EP.31 · Sensors · 1NTC thermistor: the resistor that feels heat
EP.115 · Workbench Skills · 2Workbench Skills Part 2: Measure voltage — is this battery dead?
EP.113 · LED Series · 12millis() vs delay(): blink without freezing
EP.110 · Maths for Electronics · 13Maths for Electronics L13: Radians — why 360° = 2π
Get new lessons + early access to the full course
One email when new lessons drop. No spam, unsubscribe any time.
✓ You're on the list! We'll email you when new lessons drop.
By joining you agree to the privacy policy.
