Practical 2

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

FromToNote
LDR module VCCArduino 5V-
LDR module GNDArduino GND-
LDR module AOArduino A00 = bright, ~1023 = dark (module dependent)
Relay INArduino D8-
Lamp LED (via 220R)Arduino D9Simulates the street light in the diagram
Lamp LED cathodeArduino 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

  1. The LDR resistance falls in bright light, so the analog value drops during the day.
  2. Every loop the Arduino averages several readings of A0.
  3. If the average is above the NIGHT threshold (dark), the relay energizes and the lamp turns ON.
  4. If the average is below the DAY threshold (bright), the relay de-energizes and the lamp turns OFF.
  5. 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 System
2const int LDR_PIN = A0; // Analog output of the LDR module
3const int RELAY_PIN = 8; // Relay that switches the street light
4const int LAMP_PIN = 9; // Lamp indicator LED
5
6const int NIGHT_LEVEL = 600; // ADC value above which it is "dark"
7const int DAY_LEVEL = 400; // ADC value below which it is "bright"
8
9int 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}
17
18void setup() {
19 pinMode(RELAY_PIN, OUTPUT);
20 pinMode(LAMP_PIN, OUTPUT);
21 Serial.begin(9600);
22}
23
24void loop() {
25 int light = readLight();
26 Serial.print("Light level: ");
27 Serial.println(light);
28
29 if (light > NIGHT_LEVEL) { // Darkness detected
30 digitalWrite(RELAY_PIN, HIGH); // Street light ON
31 digitalWrite(LAMP_PIN, HIGH);
32 Serial.println("NIGHT - lamp ON");
33 } else if (light < DAY_LEVEL) { // Daylight detected
34 digitalWrite(RELAY_PIN, LOW); // Street light OFF
35 digitalWrite(LAMP_PIN, LOW);
36 Serial.println("DAY - lamp OFF");
37 }
38 delay(500);
39}