Level 3 · Sense · 35 min · ●●●○○

Automatic Night Light

A light that switches itself on when the room gets dark — no hands, no code.

What you need

  • 3×AA battery pack (4.5 V) L1
  • Solderless breadboard L1
  • Jumper wires L1
  • Light sensor (LDR) L3
  • 10 kΩ resistor the top half of the voltage divider L1
  • 1 kΩ resistor protects the transistor base L1
  • NPN transistor (2N2222) flat face toward you: legs are E-B-C L3
  • Red LED (5 mm) L1
  • 220 Ω resistor L1

you'll learn: Voltage dividers · Transistor switching · Ohm's law

4.5 V + 10 kΩ middle LDR light 1 kΩ B C E 2N2222 220 Ω +4.5 V rail 0 V rail middle ≈ 0.4 V in light (LED off) · pushes past 0.7 V in dark (LED on)
the divider turns darkness into voltage; past ~0.7 V the transistor lets the LED lane flow

What you're building

A light with no switch at all. Cover the sensor (or wait for sunset) and the LED fades on by itself. This is your first circuit that decides something on its own — and it does it with two tricks that run the entire world of sensors.

Trick 1: the voltage divider

Stack two resistors between + and , and the point between them sits at a voltage decided by the ratio of the two:

middle voltage = 4.5 V × (bottom ÷ (top + bottom))

Now the sneaky part: your LDR is a resistor that changes with light — about 1 kΩ in bright light, over 100 kΩ in darkness. Put the fixed 10 kΩ on top and the LDR on the bottom, and the middle point moves:

  • Bright room: LDR ≈ 1 kΩ → middle ≈ 4.5 × (1 ÷ 11) ≈ 0.4 V
  • Dark room: LDR ≈ 100 kΩ → middle tries to rise toward 4.5 × (100 ÷ 110) ≈ 4.1 V

Light has become a voltage. Nearly every sensor you'll ever meet — game controller sticks, thermostat probes — is some version of this trick.

(One honest detail: once the transistor is connected, its base won't let the middle point actually reach 4.1 V — past about 0.7 V the base clamps it there and drinks the extra push as current instead. That's fine: the divider's whole job is just to shove the middle point past that 0.7 V line when it gets dark.)

Trick 2: the transistor

The divider's middle point can't power an LED by itself (the 10 kΩ chokes the current — you proved how little gets through 10 kΩ in the Brightness Lab). It needs a helper: the transistor, an electrically-flipped switch. Feed its base leg a small current and it lets a much larger current pour across from collector to emitter. Roughly 0.7 V at the base is the "wake-up" threshold: our 0.4 V bright-room voltage stays below it (LED off), our 4.1 V dark voltage sails past it (LED on).

Build it

  1. The sensing half: battery + → 10 kΩ → middle row → LDR → battery .
  2. The deciding part: transistor flat face toward you; legs left to right are Emitter, Base, Collector. Middle row → 1 kΩ → Base. (The 1 kΩ keeps the base current small and polite — the transistor only needs a trickle.)
  3. The output half: battery + → 220 Ω → LED (long leg first) → Collector. Then Emitter → battery .
  4. Lights on in the room: LED off. Cup your hands over the LDR: LED on.

Notice it doesn't snap — it fades as your hand closes over the sensor. Between full-off and full-on the transistor passes through an in-between region. (Level 6's chips will turn this mush into a crisp snap.)

Debug like an engineer

Not working? Don't rewire everything — test the halves separately. Wire a spare LED lane (220 Ω included!) from the divider's middle row to battery −: does covering the LDR change its glow? If yes, the sensing half works and your bug lives in the transistor half — check E-B-C order first; backwards transistors are the #1 classic. Splitting a problem in half is the fastest debugging tool ever invented.

🧠 Your challenge

No single right answer. That's the point.

  • Swap the 10 kΩ and the LDR. Predict what the circuit becomes before you power it. (You've just built the other half of a security system.)
  • Make it less jumpy at dusk: what could you change so it only triggers in proper darkness? You have a 1 kΩ resistor spare — where could it go in the divider, and what does the math say it does to the middle voltage?
  • Combine with the Door Buzzer: a drawer alarm that buzzes when opened in a dark room. Which project supplies which half?

For grown-ups: safety notes

  • Still battery-safe: 4.5 V can't shock you, sensor or not.
  • The transistor can warm up slightly if wired backwards for a long time — if it's ever hot to the touch, disconnect and re-check E-B-C.
  • Leave it running overnight only on a breadboard placed on a hard surface, not bedding — good practice for any always-on project.

Checked against