Skip to content

Electronics

Build an automatic night light with an LDR and a MOSFET

An automatic night light needs three ideas: a light-dependent resistor (LDR) in a voltage divider, so the light level becomes a voltage; a MOSFET whose gate reads that voltage; and an LED the MOSFET switches. Put the LDR at the bottom of the divider and the gate voltage rises as the room gets dark, until the MOSFET turns on.

+5 VR110 kΩLDR1R2 120 ΩwhiteLEDM1gateday 0.43 Vnight 3.8 V
The night light: a light-sensing divider drives the MOSFET's gate, which switches the LED

The circuit

  • A 5 V supply, like a USB socket
  • 10 kΩ from 5 V down to the gate, and the LDR from the gate to ground
  • A logic-level MOSFET, threshold about 1.6 V, as a low-side switch
  • A white LED and 120 Ω from 5 V down to the MOSFET's drain

Work out the voltages

An LDR's resistance climbs as the light falls: a typical one is about 0.93 kΩ in a bright room (300 lux) and 31 kΩ at night (2 lux). The gate sits at the LDR's share of 5 V.

By day:

Vgate = 5 × 0.93 over 10 + 0.93 ≈ 0.43 V

That's below the 1.6 V threshold, so the MOSFET and the LED are off. At night:

Vgate = 5 × 31 over 10 + 31 ≈ 3.8 V

Well above threshold, so the MOSFET is fully on and the LED lights. It switches over where the gate crosses 1.6 V, when the LDR is about 4.7 kΩ, at around 30 lux: dusk.

Live experiment

Slide the sun down

5 V across 10 kΩ on top of a light sensor, whose middle drives a logic-level MOSFET's gate, switching a white LED through 120 Ω. Slide the sun from day to night: near 30 lux the gate passes 1.6 V and the light comes on. Then put the sensor on top.

Try it yourself: free lesson

“Project: Light-Sensing Night Light” is the project that ends Silicon Ridge, Electronics World 5. Free with an account. Lessons unlock in order, so you’ll do the 34 before it first.

The LED and the standby current

A white LED drops about 3.2 V. For 15 mA:

R = 5 − 3.2 over 0.015 = 120 Ω

By day the MOSFET is off and only the divider draws current, 5 V ÷ 10.93 kΩ ≈ 0.46 mA. The gate itself draws no steady current, because it's insulated from the channel, so the divider drives it directly without being pulled down.

Set where it switches

The gate reaches 1.6 V when the LDR is about 0.47 times the top resistor. Make the top resistor bigger and the LDR must climb higher before the light comes on, so it waits for a darker room. Swap the LDR and the 10 kΩ, and the whole thing runs backwards: on all day, off at night.

Free lesson

Now build it yourself

Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.

Try it yourself: free lesson

“Project: Light-Sensing Night Light” is the project that ends Silicon Ridge, Electronics World 5. Free with an account. Lessons unlock in order, so you’ll do the 34 before it first.

Or start from the very first lesson, no account needed

Practice questions

Three quick questions from the lessons. Pick an answer to check it.

  1. Question 1 of 3Which way up does the LDR go so the gate voltage rises in the dark?
    Show the answer

    Answer: at the bottom. In the dark the LDR's resistance rises and it takes a bigger share of the 5 V. At the bottom, its share is the gate voltage.

    • Why not “either way: it makes no difference”? Swapping the two parts reverses the divider: the gate voltage would rise with light instead of falling.
    • Why not “on top”? On top, the LDR's higher resistance in the dark takes the top share, so the gate voltage falls at night and the light comes on by day.
  2. Question 2 of 3Why can a divider drive a MOSFET's gate directly?
    Show the answer

    Answer: The gate draws no steady current. The gate is insulated, so it draws no steady current and doesn't load the divider. A BJT's base would pull the divider down.

    • Why not “The LDR supplies extra current”? An LDR only changes its resistance. It makes no current or voltage of its own.
    • Why not “It can't: the gate needs its own battery”? The divider's voltage is enough on its own, because the insulated gate needs a voltage, not a current.
  3. Question 3 of 3An LDR in a dark box is joined straight to a voltmeter, with no battery anywhere. What does the meter read?
    Show the answer

    Answer: 0 V. An LDR makes no voltage at all. It only changes its resistance. With no supply, nothing pushes charge round, so the meter reads 0 V.

    • Why not “About 5 V: the LDR makes a voltage in the dark”? An LDR isn't a solar cell. It makes no voltage at all, in the dark or in the light.
    • Why not “A voltage that rises as the box gets darker”? Darkness raises the LDR's resistance, but with no supply there's nothing to make a voltage from.
Keep practising: free lesson

“Project: Light-Sensing Night Light” is the project that ends Silicon Ridge, Electronics World 5. Free with an account. Lessons unlock in order, so you’ll do the 34 before it first.

Questions people ask

How do I make a night light turn on at a darker level?

Use a bigger resistor on top of the divider. The gate reaches the MOSFET's threshold when the LDR is about half the top resistor, so a bigger top resistor needs a bigger LDR resistance, which means darker. A trimmer pot on top makes it adjustable.

Can I use a transistor instead of a MOSFET?

Yes. Feed an NPN's base from the divider through about 2.2 kΩ. At night that gives about 0.3 mA, twice the 0.15 mA a 15 mA LED needs at a gain of 100. Unlike a MOSFET's gate, the base draws current, which pulls the divider down a little.

Why does my night light flicker or glow dimly at dusk?

Near the threshold the MOSFET is only half on, so the LED glows dimly and the reading wobbles with every shadow. A Schmitt trigger or a comparator with hysteresis gives two separate switching points, so the light snaps cleanly on and off.

Every topic