Automatic Night Light
A light sensor and a transistor team up to switch on an LED when it gets dark, just like a streetlight.
What you’ll make
A light that switches itself on when it gets dark. A light sensor watches the room, and a transistor acts as an electronic switch to turn the LED on. It’s the same idea used in streetlights and yard lights.
What you need
- A battery holder for 3 AA batteries, with a switch, and 3 AA batteries (4.5 V)
- A solderless breadboard and jumper wires
- 1 NPN transistor, 2N3904
- 1 light-dependent resistor (LDR), also called a photoresistor or photocell: a 5 mm type of about 10 to 20 kΩ in dim light (for example, a GL5528)
- 1 resistor, 10 kΩ (bands: brown, black, orange; five-band: brown, black, black, red, brown)
- 1 trimmer potentiometer, 100 kΩ (a small adjustable resistor)
- 1 resistor, 220 Ω (bands: red, red, brown; five-band: red, red, black, black, brown)
- 1 LED, red or yellow, 5 mm
Cost: low. All of these are common, inexpensive parts.
Good to know: many LDRs contain cadmium compounds. They’re safe to handle, but don’t break them open, and take old ones to an electronics recycling depot rather than the garbage.
Safety numbers for this build
| Supply | 4.5 V (3 AA batteries) |
|---|---|
| LED current when on | about 10 mA |
| Transistor base current | well under 1 mA; the 10 kΩ resistor keeps it safe even with the trimmer turned to zero ohms |
| Supervision | An adult nearby; this build has more parts to place |
Know your transistor
Hold the 2N3904 with its flat side facing you and its legs pointing down. From left to right, the legs are: E (emitter), B (base), C (collector). Most 2N3904s use this order, but check the seller’s datasheet.
A trimmer potentiometer has three legs. You’ll use the middle leg and one outer leg, which makes it work as a resistor you can adjust with a small screwdriver.
Build it, step by step
- Power rails: battery pack off. Red lead to the red (+) rail, black lead to the blue (−) rail.
- Transistor: push it into the breadboard so each leg is in its own row. Note the E, B and C rows.
- Emitter: jumper wire from the E row to the blue (−) rail.
- LED and its resistor: 220 Ω resistor from the red (+) rail to an empty row. LED long leg into that same row; LED short leg into the C row.
- The sensor: LDR from the B row to the blue (−) rail. (An LDR works either way round.)
- The adjustable resistor: 10 kΩ resistor from the red (+) rail to an empty row. Put the trimmer in three empty rows of its own. With jumper wires, join one outer leg to the 10 kΩ row and the middle leg to the B row. Leave the other outer leg unconnected.
- Check everything against the diagram. Then switch on.
Set it up
- In a normally lit room, use a small screwdriver on the trimmer. If the LED is off, turn the trimmer until it comes on, then turn it back slowly until it just goes off.
- Now cover the LDR with your hand, or a small box. The LED should switch on.
- Uncover it, and the LED goes off again.
Why it works
BeginnerA sensor and an electronic switch
An LDR’s resistance changes with light. In bright light its resistance is low; in the dark it’s very high.
The LDR and the fixed and adjustable resistors form a voltage divider. In light, the LDR’s low resistance keeps the transistor’s base at a low voltage, so the transistor stays off. When it gets dark, the LDR’s resistance shoots up, the base voltage rises, and a tiny current flows into the base. That small current switches on a much bigger current from collector to emitter, and the LED lights.
IntermediateThe numbers
A silicon transistor like the 2N3904 starts to turn on when its base is about 0.6 to 0.7 V above its emitter. In darkness, the base current is at most (4.5 − 0.7) ÷ 10,000 ≈ 0.38 mA, when the trimmer is turned to zero ohms. The transistor amplifies that base current many times, more than enough for the LED’s roughly 10 mA, so the transistor usually turns fully on. (Near the trimmer’s top setting, the base current drops to about 35 µA, and the LED may light less brightly.) The LED current is then about (4.5 − 2.0 − 0.2) ÷ 220 ≈ 10 mA, where 0.2 V is the small voltage left across a fully-on transistor.
AdvancedDesign notes
The 10 kΩ fixed resistor sets a minimum resistance above the base, protecting the transistor if the trimmer is turned to zero. The trimmer moves the switching point: more resistance above the base means the LDR must get darker (higher resistance) before the base reaches about 0.65 V.
The switch-over isn’t perfectly sharp: at dusk the LED may glow dimly as the transistor passes through its active region. Real streetlight controllers add hysteresis, using different on and off thresholds, so they don’t flicker. A comparator circuit or a microcontroller can do that, a topic for later in Electronics School.
It doesn’t work? Check these
- LED never lights: is the LED backwards? Is the transistor in the right way (flat side, E-B-C)? Cover the LDR completely, and try turning the trimmer the other way.
- LED always on: the room may be too dark for your setting. Turn the trimmer until it goes off in normal light.
- Nothing at all: check the battery switch, the rails and that every part has its legs in separate rows.
For teachers and parents
Open the teacher guide
Time: 15 minutes to prepare; 45 to 60 minutes in class. Best after Projects 1 and 2.
Learners will: build a circuit from a schematic; describe how a sensor changes resistance; explain a transistor as an electronic switch controlled by a small current; adjust a threshold and test it.
Per student or pair: the parts list above, plus a small screwdriver. Pre-sort parts into bags; the transistor, LDR and trimmer are easy to confuse with each other.
Risk and supervision: low. Battery power only. Check transistor orientation before students switch on.
Discussion questions: Where have you seen lights that turn on by themselves at dusk? Why does the circuit need a sensor and a switch, not just one or the other? What would you change to make it turn on in light instead?
Common misconceptions: “The LDR makes the light” (it only senses light). “The transistor stores electricity” (it’s a switch, controlled by the base current). “More light makes the LED brighter” (here it’s the reverse: darkness turns it on).
Worksheet with answers:
- What happens to an LDR’s resistance in the dark? (It increases a lot.)
- Which transistor leg controls the switching? (The base.)
- Name two places this kind of circuit is used. (Streetlights, yard and porch lights, night lights; accept reasonable answers.)
- Why is the 10 kΩ resistor there? (To limit the base current and protect the transistor if the trimmer is turned to zero.)
Stretch: swap the LDR and the trimmer, keeping the 10 kΩ next to + so it always protects the base: + → 10 kΩ → LDR → base, and the trimmer from the base to −. Predict, then test: the circuit now turns the LED on in light. Why?
Learn more
- Science World (Vancouver): Current Electricity: eight hands-on circuit activities
- Lesson 5: LEDs and resistors
- Back to Electronics School
Electronics School is part of the Discovery Zone. Every activity here runs on small batteries or a USB cable: never wall outlets. The one plug-in tool is the optional soldering iron, set up by an adult.