Projects / Automatic night lamp with LDR and relay

Automatic night lamp with LDR and relay

Beginner1.5 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. Build the divider

    Check its voltage in light and dark with a multimeter.

  2. Set the reference

    Turn the trimmer to mid position.

  3. LM393387 lux

    Add the comparator

    Confirm pin 1 changes when you cover the LDR.

  4. BC547ON

    Add the transistor and relay

    Hear the click and check the diode direction.

  5. Add hysteresis

    Fit the 100 kΩ feedback resistor.

  6. Connect a 12 V lamp

    Use a separate low-voltage supply for the lamp.

  7. Tune at dusk

    Turn the trimmer until it switches at the light level you want.

In short

How do you build an automatic night lamp with LDR and relay?

An LDR and transistor switch a relay at dusk, and an LM393 comparator gives a clean on and off without flicker. You need LM393 Comparator, LDR Photoresistor, Resistor 10 kΩ × 2, Trimmer potentiometer 10 kΩ (3296), Resistor 100 kΩ, BC547 NPN transistor, Resistor 1 kΩ, Relay 5 V SPDT (sugar cube), Rectifier Diode 1N4007, 5 V 2 A USB adapter and Perfboard (dot PCB) 7 × 9 cm. It takes 7 steps and about 90 minutes.

Level
Beginner
Time
About 90 min
Parts
11
See the electronics first. This build uses transistor switch. Try a transistor switch in the circuit builder and watch the voltages and currents before you wire it.

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
5 VLM393 pin 8 and pin 4 to GNDPower for the comparator
5 V to LDR to a node, 10 kΩ from the node to GNDLM393 pin 3 (+ input)Light divider (high in light)
5 V to the trimmer, wiperLM393 pin 2 (− input)Threshold reference
100 kΩBetween LM393 pin 1 (output) and pin 3 (+ input)Hysteresis feedback
10 kΩFrom 5 V to LM393 pin 1Pull-up for the open-collector output
LM393 pin 11 kΩ to BC547 baseRelay driver
BC547 collectorRelay coil, other coil end to 5 VRelay switching
1N4007Across the coil, stripe to 5 VFlyback protection
Relay contactsA 12 V lamp and its supply, in seriesLow-voltage load only

No code needed

The LDR and 10 kΩ resistor form a divider whose voltage is high in daylight and low in the dark. The comparator compares it with the trimmer's voltage. When it falls below the setting the output goes low, which would leave the relay off, so wire the divider the other way round (LDR to ground, resistor to 5 V) if you want the lamp on in the dark: test with the lamp and swap the two if it behaves backwards. The 100 kΩ feedback gives hysteresis, so the lamp does not flicker as light slowly changes at dusk. Switch only a low-voltage lamp, such as a 12 V LED lamp with its own supply. This build never switches mains; if you want a mains lamp, a qualified electrician must wire the mains side with an approved relay unit in an enclosure.

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Cover the LDRRelay clicks and the lamp changes state
Uncover itRelay clicks back
Slowly shade the LDROne clean click, no chatter
Torch near the LDR at nightLamp turns off (see the note)

If it does not work

Relay chatters

Check the 100 kΩ feedback resistor and the pull-up.

Behaves backwards

Swap the LDR and the 10 kΩ resistor.

Relay stays on

Check the BC547 pins (flat side view: E, B, C).

Switches at the wrong light

Adjust the trimmer.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the automatic night lamp with LDR and relay?

LM393 Comparator, LDR Photoresistor, Resistor 10 kΩ × 2, Trimmer potentiometer 10 kΩ (3296), Resistor 100 kΩ, BC547 NPN transistor, Resistor 1 kΩ, Relay 5 V SPDT (sugar cube), Rectifier Diode 1N4007, 5 V 2 A USB adapter and Perfboard (dot PCB) 7 × 9 cm.

How long does the automatic night lamp with LDR and relay take to build?

About 90 minutes for a beginner maker, in 7 steps.

How do I know the automatic night lamp with LDR and relay works?

Cover the LDR: Relay clicks and the lamp changes state. Uncover it: Relay clicks back. Slowly shade the LDR: One clean click, no chatter.

Relay chatters: what should I check?

Check the 100 kΩ feedback resistor and the pull-up.

Behaves backwards: what should I check?

Swap the LDR and the 10 kΩ resistor.

Relay stays on: what should I check?

Check the BC547 pins (flat side view: E, B, C).

Switches at the wrong light: what should I check?

Adjust the trimmer.