Level 5 · Control · project 3 of 4 · 30 min · ●●●○○
The Night Gate
A night light switched by a MOSFET. The gate takes no current, so the moment it turns on is plain voltage-divider math you can work out exactly.
new here? Start with First Light — one battery, one resistor, one LED. It teaches the loop, LED direction, and why the 220 Ω resistor matters.
What you need
- 1× 3×AA battery pack (4.5 V) L1
- 1× Solderless breadboard L1
- 6× Jumper wires L1
- 1× MOSFET 2N7000 flat face toward you: legs are S-G-D, source to −
- 1× 10 kΩ resistor top half of the divider, from + to the gate L1
- 1× Light sensor (LDR) bottom half of the divider, from the gate to − L3
- 1× 220 Ω resistor L1
- 1× Yellow LED (5 mm) L1
you'll learn: MOSFET switching · Voltage dividers
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 with the LDR covered. Measure the gate covered: it should be over 3 V. If it is, check the lamp lane: LED long leg toward the 220 Ω, short leg to the DRAIN, and the SOURCE on the − rail.
- LED is on even in a bright room. The LDR is not reaching the − rail, so the 10 kΩ pulls the gate high. Or your MOSFET has a low threshold and your room is dim: try a 4.7 kΩ in place of the 10 kΩ.
- LED only comes on in pitch dark, or never quite fully. Your MOSFET's threshold is near the top of the 0.8–3 V range. Raise the top resistor so the covered gate climbs higher, or check the battery pack still reads over 4 V.
- LED glows faintly whatever the light, and the MOSFET is warm. Source and drain are swapped and the MOSFET's built-in diode is conducting. Turn it round: flat face toward you, S-G-D.
- Worked yesterday, dead today. Static may have killed the gate. Swap the 2N7000 and touch something earthed before handling the new one.
What you're building
A lamp that switches itself on when the room goes dark. You may have built one already with a 2N2222. This time a 2N7000 MOSFET does the switching, and that changes one important thing: you can work out exactly how dark it has to get before the lamp comes on, with nothing but the voltage-divider formula.
Two halves of a divider
A 10 kΩ resistor runs from + to a row we'll call the gate node. An LDR (light-dependent resistor) runs from the gate node to −. An LDR's resistance falls when light hits it: about 1 kΩ in a bright room, about 100 kΩ in the dark (the simulator uses those two figures; real ones vary). Together the two parts make a voltage divider, and the voltage in the middle is
V_gate = 4.5 V × R_LDR ÷ (10 kΩ + R_LDR)
The gate node is wired straight to the MOSFET's gate.
Why the gate makes the math honest
A MOSFET's gate is a metal plate sitting on a layer of glass. No current crosses it. So nothing leaks out of the middle of the divider, and the formula above is the whole story.
Compare the bipolar version. A 2N2222's base does draw current, and that current comes out of the middle of the divider and pulls it down. How hard it pulls depends on the transistor's gain, which varies from part to part. The MOSFET takes nothing, so the divider sits exactly where the formula puts it.
Bright room
V_gate = 4.5 × 1 ÷ (10 + 1) ≈ 0.41 V
The 2N7000 needs about 2 V between gate and source before its channel opens (the simulator uses 2.0 V). 0.41 V is nowhere near. The MOSFET is off and the LED is dark. The divider still passes a little current, 4.5 V ÷ 11 kΩ ≈ 0.41 mA, which is the price of watching the room.
Dark room
V_gate = 4.5 × 100 ÷ (10 + 100) ≈ 4.09 V
That's 2.09 V over threshold, enough for the MOSFET to pass about ½ × 0.1 × 2.09² ≈ 218 mA if the load asked for it. The LED lane asks for far less, so the MOSFET is fully on and acts like a resistor of about 1 ÷ (0.1 × 2.09) ≈ 4.8 Ω. The drain sits only about 0.05 V above −. The LED lane gets the rest:
I_LED ≈ (4.5 − 0.05 − 2.0) ÷ 220 ≈ 11 mA
The yellow LED's forward voltage, the voltage it takes to make it conduct, is about 2.0 V, the same as a red one. The Workbench shows 11.0 mA.
Where exactly does it switch?
Here's the payoff. The lamp starts to come on when V_gate reaches 2 V. Set the divider formula equal to 2 and solve for the LDR:
2 = 4.5 × R ÷ (10 kΩ + R)
2 × (10 kΩ + R) = 4.5 × R
20 kΩ = 2.5 × R, so R = 8 kΩ
Darker than that, with the LDR above 8 kΩ, and the lamp is on. Brighter, and it's off. On the Workbench, drag the light slider and watch:
- LDR ≈ 6.3 kΩ: gate at 1.74 V. Off.
- LDR ≈ 10 kΩ: gate at exactly half the battery, 2.25 V, a quarter-volt over threshold. The MOSFET is only partly on: ½ × 0.1 × 0.25² ≈ 3 mA, a dim glow.
- LDR ≈ 100 kΩ: fully on, 11 mA.
So the lamp doesn't snap on. It fades up over a narrow band of dusk. That's the MOSFET's square law, I ≈ ½ × 0.1 × (V_gate − 2)², at work.
Your MOSFET is not the simulator's
The 2N7000 datasheet allows a threshold anywhere from 0.8 V to 3 V. Put each end into the same formula:
- Threshold 0.8 V: R = 10 kΩ × 0.8 ÷ 3.7 ≈ 2.2 kΩ. Your lamp comes on at early dusk.
- Threshold 3 V: R = 10 kΩ × 3 ÷ 1.5 = 20 kΩ. It waits for real dark.
Real LDRs vary just as much. If yours switches at the wrong moment, change the 10 kΩ, not the MOSFET: a bigger top resistor needs a darker room before the gate reaches threshold, a smaller one switches sooner. The formula tells you which way to go and how far.
Build it
- Rails: + along the top, − along the bottom, battery between them.
- The MOSFET: flat face toward you, legs S-G-D left to right. S to the − rail. G and D in free rows.
- The divider: 10 kΩ from the + rail to the G row. LDR from the G row to the − rail. Either way round; an LDR has no polarity.
- The lamp: + rail → 220 Ω → LED long leg; LED short leg → D.
- Power up in a lit room: dark. Cup your hand over the LDR: the LED comes on. Take your hand away: off.
Debug like an engineer
Measure the gate with the room lit, then covered. Lit should read under 1 V, covered over 3 V. If both readings look right but the LED never lights, the fault is in the lamp lane: the LED is backwards, or the MOSFET's source and drain are swapped. If the gate reads near 4.5 V in a bright room, the LDR isn't reaching the − rail. If it reads near 0 V even when covered, the 10 kΩ isn't reaching +.
🧠 Your challenge
No single right answer. That's the point.
- Make it switch at the 6.3 kΩ point instead of 8 kΩ, assuming a 2 V threshold. What top resistor do you need? Is that value in your box? If not, which part you own gets closest, and which way does it move the switch point?
- Swap the LDR and the 10 kΩ. Work out the gate voltage bright and dark. What kind of lamp have you built now, and where does it switch?
- Put a 2N2222 in the MOSFET's place, base on the same gate node. A bipolar base starts conducting at about 0.7 V instead of 2 V. Using the divider formula, at what LDR resistance does the base reach 0.7 V? Is that a brighter or a darker room than the MOSFET's 8 kΩ? Once it conducts, the base clamps the node near 0.7 V and pulls current out of the divider. Work out that base current with the LDR at 100 kΩ.
- Harder: the lamp fades in over a band of dusk instead of snapping on. Using the square law, find the LDR value where the LED reaches 1 mA and the value where it reaches 10 mA. How wide is that band in kilohms?
For grown-ups: safety notes
- Battery power only: 4.5 V from three AA cells cannot shock you.
- The 2N7000's gate is a few nanometres of glass, and a static spark from a carpet can punch through it. Touch something earthed (a tap, a radiator) before handling it.
- At dusk the MOSFET is only partly on and drops about 1.9 V while passing 3 mA: under 6 mW, nothing you'll feel. It never needs a heat sink in this circuit.
- Keep the 220 Ω in the LED lane. Fully on, the MOSFET is close to a wire, and an LED straight across 4.5 V would burn out.
Checked against
Keep building
You might also like
shares ideas with this one