Dark-activated night light
No Arduino. No code. Just transistor switching and a voltage divider that reads the ambient light.
The idea
An LDR (photoresistor) changes resistance with light:
| Condition | Resistance |
|---|---|
| Pitch dark | ~1 MΩ |
| Indoors dim | ~50 kΩ |
| Bright room | ~1 kΩ |
| Direct sun | ~100 Ω |
Combine it with a fixed 10 kΩ resistor as a voltage divider, with the tap going to an NPN transistor's base:
9V ──[ 10kΩ ]──┬──[ LDR ]── GND
│
base of NPN
Dark → LDR is huge → most of 9 V drops across the LDR → base sees ≈ 9 V (well above the 0.7 V turn-on) → transistor turns ON → LED lights.
Bright → LDR is tiny → almost all of 9 V drops across the 10 kΩ → base sees ≈ 0 V → transistor OFF → LED dark.
Why the transistor?
You could wire the LED straight across the LDR+R divider, but the current through a voltage divider is tiny (microamps). A dim LED at best. The NPN acts as a current amplifier — a tiny base current controls a much larger collector current that actually lights the LED. Gain β ≈ 100 for a typical NPN, so 50 µA at the base drives 5 mA at the LED.
Try this
This circuit has an LDR lightLevel property. Click the LDR and
drag the slider:
lightLevel = 0.0(pitch dark) → LED full brightnesslightLevel = 0.5(moderate) → LED dimlightLevel = 1.0(direct sun) → LED off
Also try:
- Swap the 10 kΩ fixed resistor for 1 kΩ. Now the threshold shifts — the LED stays off until it's very dark. That's how you tune sensitivity in a real build.
- Reverse the divider (LDR on top, fixed resistor on bottom). Now it becomes a light-activated switch — useful for turning something on when a beam is broken.
Why this is everywhere
Automatic streetlights, garden path lights, that "turn off when I leave the room" LED under your desk — most of them are this exact circuit, sometimes with a different transistor or with a 555 for hysteresis. If you can read this one, you can read most of them.