Arduino Automatic Street Light with LDR
Level 33 · Street Light · 35 minutes
A street lamp with two lines instead of one: on at dusk, off at dawn, and steady when headlights or clouds pass.

Preview the project free; a course seat is required to run and submit. No hardware kit needed.
Your project challenge
Make the street lamp switch on when it gets dark. Wire it up: - Light sensor: 5V to 5V, GND to GND, signal to A0 - Relay: VCC to 5V, GND to GND, IN to D7 - Lamp LED: long leg D9, short leg GND ON below 350. OFF above 650. In between, leave it alone. Switch within 2 seconds.
Components you’ll use
- Arduino Uno
- LDR (Light-Dependent Resistor)
- Relay Module
- LED (Light-Emitting Diode)
What you’ll build
A street lamp that switches itself on at dusk and off again at dawn.
How it works
- The light sensor reads
0in the dark and1023in full sun. - Below
350the lamp switches ON. Above650it switches OFF. - Between the two lines, the lamp keeps doing what it was doing.
- Switch within
2seconds of the light crossing a line. - The relay is active low. The coil pulls in when IN goes LOW, not HIGH.
- The LED is the lamp. It shows you what the relay just did.
The key idea
One line gives you a lamp that flickers every time headlights sweep the sensor.
Use two lines, 350 and 650, with a gap of 300 between them.
Inside the gap your sketch keeps its last answer, so it has to remember it.
⚠ Watch out
Before dawn the lamp must stay ON, although the sky is brighter than on a cloudy afternoon when it had to stay OFF. One line cannot do both, wherever you put it. Nor can a lamp that switches on whenever the light gets brighter.
The interactive editor includes the wiring guide, code editor and simulation controls.