Level 3 · Sense · project 1 of 17 · 35 min · ●●●○○

Automatic Night Light

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

new here? Start with First Light — one battery, one resistor, one LED. It teaches the loop, LED direction, and why the 220 Ω resistor matters.

You'll make a lamp that turns itself on at dark
You'll learn LDR + transistor as a switch
Watch for swap the LDR and the resistor and the lamp fires backwards

What you need

🔧 Try before wiring →

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

Circuit map

The circuit you'll build, running on the Workbench right now — shown with the lights off.

simulating…

If it doesn't work

The boring ways this circuit actually breaks — check these first before you unwire everything.

  • LED never lights, even in a dark room. 2N2222 pins with the flat face toward you: E-B-C, left to right. Swap two and it won't switch. Also confirm the base 1 kΩ is between the divider midpoint and pin B.
  • LED always on, even in bright light. Divider is upside down — the LDR must sit on the BOTTOM (Sunrise Alarm is the flipped version). Swap the LDR and the 10 kΩ.
  • Threshold feels wrong for your room. Your room's 'dark' isn't the design's. Try cupping a hand over the LDR to force dark, or nudge the top 10 kΩ up (fires later) or down (fires earlier).
  • LED very dim when it does turn on. Wrong resistor in the LED lane. 220 Ω = red-red-brown; a 1 kΩ (brown-black-red) makes it a ghost.
  • LED lights, then fades, then quits. The LDR is picking up ambient. Cup a hand over it — the LED should snap fully on. If it flickers only, a jumper is loose; push every leg firmly.

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. It uses two tricks you'll see all through sensor circuits.

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 — the base-emitter junction starts conducting at about 0.7–0.8 V and drinks the extra push as current instead. Because the 1 kΩ base resistor sits between the middle row and the base, the middle row itself settles around 1.0–1.1 V in the dark, with the base just below 0.8 V. That still works. The divider only has 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

Keep building