Automatic Day-Night Street Lighting System
Street light that follows ambient light level
Aim
To build a lighting controller that detects ambient light with an LDR/light sensor module and switches a street light ON at night and OFF during the day, without manual intervention.
Overview
The light-dependent resistor (LDR) based module gives a LOW analog voltage in bright light and a HIGH voltage in darkness (or the opposite, depending on module wiring). The Arduino reads the light level, applies a night/day threshold, and drives a relay connected to the street lamp. A small hysteresis band prevents the lamp from flickering at dusk when the light level hovers around the threshold.
Components Required
- Arduino Uno
- LDR / photoresistor sensor module (AO output)
- Relay module
- Street light (LED lamp or bulb)
- Yellow LED + 220 ohm resistor (lamp indicator)
- Breadboard and jumper wires
Circuit Connections
| From | To | Note |
|---|---|---|
| LDR module VCC | Arduino 5V | - |
| LDR module GND | Arduino GND | - |
| LDR module AO | Arduino A0 | 0 = bright, ~1023 = dark (module dependent) |
| Relay IN | Arduino D8 | - |
| Lamp LED (via 220R) | Arduino D9 | Simulates the street light in the diagram |
| Lamp LED cathode | Arduino GND | - |
Interactive Circuit Diagram
Simulate the circuit: adjust the sensor inputs below and watch the outputs react according to the control logic.
Loading Wokwi components...
Working
- The LDR resistance falls in bright light, so the analog value drops during the day.
- Every loop the Arduino averages several readings of A0.
- If the average is above the NIGHT threshold (dark), the relay energizes and the lamp turns ON.
- If the average is below the DAY threshold (bright), the relay de-energizes and the lamp turns OFF.
- The lamp state is shown on the indicator LED.
Control Logic
LAMP = ON when lux < NIGHT_LUX, OFF when lux > DAY_LUX. Using two thresholds (e.g. 150 lux and 250 lux) gives a hysteresis band around dusk/dawn so the lamp does not flicker when clouds pass by.
Arduino Code
1// Practical 2: Automatic Day-Night Street Lighting System2const int LDR_PIN = A0; // Analog output of the LDR module3const int RELAY_PIN = 8; // Relay that switches the street light4const int LAMP_PIN = 9; // Lamp indicator LED56const int NIGHT_LEVEL = 600; // ADC value above which it is "dark"7const int DAY_LEVEL = 400; // ADC value below which it is "bright"89int readLight() {10 long sum = 0;11 for (int i = 0; i < 10; i++) {12 sum += analogRead(LDR_PIN);13 delay(2);14 }15 return sum / 10;16}1718void setup() {19 pinMode(RELAY_PIN, OUTPUT);20 pinMode(LAMP_PIN, OUTPUT);21 Serial.begin(9600);22}2324void loop() {25 int light = readLight();26 Serial.print("Light level: ");27 Serial.println(light);2829 if (light > NIGHT_LEVEL) { // Darkness detected30 digitalWrite(RELAY_PIN, HIGH); // Street light ON31 digitalWrite(LAMP_PIN, HIGH);32 Serial.println("NIGHT - lamp ON");33 } else if (light < DAY_LEVEL) { // Daylight detected34 digitalWrite(RELAY_PIN, LOW); // Street light OFF35 digitalWrite(LAMP_PIN, LOW);36 Serial.println("DAY - lamp OFF");37 }38 delay(500);39}