LESSONSensors · Part 3EP.118 · 24 s

Sensors Part 3: The LDR — the resistor that sees light

// WHAT YOU WILL LEARN

Build an automatic night light with an LDR divider.

// LESSON NOTES

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!

CODE FROM THIS LESSON
int light = analogRead(A0);
if (light < 300) digitalWrite(13, HIGH);
else digitalWrite(13, LOW);
Read the voiceover (transcript)
  1. A resistor that can see light?
  2. This is an LDR. Bright light: about a thousand ohms. Dark: up to a million!
  3. Put it in a divider with a ten k resistor. The voltage at A zero follows the light.
  4. Dark? The reading drops below three hundred, so the LED turns on. A night light!
  5. More light, less resistance!
  6. Next: distance with sound! Follow for part four!

Related lessons