Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » RTC Based Automatic Street Light Using Arduino & LDR
Arduino Projects

RTC Based Automatic Street Light Using Arduino & LDR

Mamtaz AlamBy Mamtaz AlamUpdated:November 27, 20237 Comments3 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
RTC Based Street Light Control Using Arduino & LDR
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

RTC Based Automatic Street Light Using Arduino & LDR

In this project, we will learn how to design RTC Based Automatic Street Light Using Arduino & LDR. The concept of this project is based on a low consumption of energy. In this project, street lights turn on or off on the basis of day & night timing controlled by real-time clock module DS3231. The timing is set via programming to determine ON and OFF time. Similarly, LDR is used to detect the quantity of light and on that basis, the street Light intensity is controlled. The LDR Arduino works well here.

The main advantage of street lights is that they increase safety and prevent accidents and collisions. Generally, street lights are turned on during evening time and will continue to glow till morning. This might result in unnecessary usage of power as the lights will be glowing at full intensity all the time. But using the Auto Intensity Control of Street Lights, the intensity of light can be controlled on light conditions.




Components Required:

1. Arduino UNO Board
2. DS3231 RTC Module
3. LDR
4. 16*2 LCD Display
5. Push Button
6. 10K Resistor
7. LED – 3 to 5
8. Connecting wires
9. Breadboard


Circuit: RTC Based Automatic Street Light Using Arduino & LDR

RTC Based Street Light Control Using Arduino & LDR

First, connect the SDA and SCL pins of the DS3231 RTC Module to A4 (SDA) and A5 (SCL) pins of Arduino. A 10KΩ Resistor and an LDR are connected in a voltage divider format and its output is given to the A0 pin of Arduino.

The data pins of 16×2 LCD Module i.e. D4 – D7 are connected to 5, 4, 3 & 2 pins of Arduino respectively. The RS and E pins are connected to pins 12 and 11.


Working of the circuit:

The project RTC Based Automatic Street Light Using Arduino & LDR operates in two modes i.e. RTC Mode and LDR Mode. In RTC Mode, the street lights turn on automatically based on the ON Time set in the code and turn off based on the OFF Time. In the LDR Mode, the street lights have an intensity control based on the ambient light near the LDR.

After the code is uploaded the project runs in RTC Mode. There are two times set in the code, i.e. the ON TIME and the OFF TIME.

Arduino compares the ON TIME with the time from RTC Module and when they match, the LED is turned ON. After this, the Arduino waits for the OFF TIME and once the time from RTC Module reaches the OFF TIME, the LED is turned OFF.

But during any time of this operation, if the push button is pressed, the Arduino enters LDR Mode. In this mode, the Arduino reads the value of the LDR on the basis of the quantity of light falling on LDR, then it adjusts the intensity of the LED. In order to switch back to RTC Mode, you need to press the push-button again.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6




Source Code/Programs:

The code for RTC Based Automatic Street Light Using Arduino & LDR is given below. But before that upload the library for RTC. Download the library from here: DS3231 RTC Library

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#include <Wire.h>
#include <LiquidCrystal.h>
#include "RTClib.h"
#define ON 0
#define OFF 1
DateTime now;
 
RTC_DS3231 rtc;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // (rs, e, d4, d5, d6, d7)
 
const int buttonPin = 7;
const int led=8;
int nob = A0;
int val = 0;
int val1 = 0;
int path=1;
int a=1;
int previousState = HIGH;
unsigned int previousPress;
volatile int buttonFlag;
int buttonDebounce = 20;
 
int on_hour=12;
int on_minute=45;
int on_second=00;
 
int off_hour=12;
int off_minute=42;
int off_second=10;
 
int c_hour=00;
int c_minute=00;
int c_second=00;
 
int onOrOffFlag = ON;
 
void showDate(void);
void showTime(void);
void showDay(void);
 
void loadHandler(int, int , int , int , int , int , int , int , int );
 
typedef struct userTime
{
int temp_hour;
int temp_minute;
int temp_second;
}userTime_t;
unsigned char checkLessThanOrEqual(userTime_t , userTime_t);
 
void setup ()
{
Serial.begin(9600);
lcd.begin(16,2);
 
pinMode(buttonPin, INPUT_PULLUP);
pinMode(led,OUTPUT);
attachInterrupt(digitalPinToInterrupt(buttonPin), button_ISR, CHANGE);
 
if (! rtc.begin())
{
Serial.println("Couldn't find RTC Module");
while (1);
}
 
if (rtc.lostPower())
{
Serial.println("RTC lost power, lets set the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
 
}
 
void loop ()
{
if(path)
{
if(a==1)
{
lcd.setCursor(0,0);
lcd.print(" RTC ");
lcd.setCursor(0,1);
lcd.print(" MODE ON ");
delay(2000);
a=0;
}
now = rtc.now();
showTime();
c_hour=now.hour();
c_minute=now.minute();
c_second=now.second();
loadHandler( on_hour, on_minute, on_second, off_hour, off_minute, off_second, c_hour, c_minute, c_second);
delay(1000);
}
else
{
if(a==0)
{
lcd.setCursor(0,0);
lcd.print(" LDR ");
lcd.setCursor(0,1);
lcd.print(" MODE ON ");
delay(2000);
a=1;
}
val = analogRead(nob);
if(val>300 && val<450)
{
lcd.setCursor(0,0);
lcd.print(" 30% ");
lcd.setCursor(0,1);
lcd.print(" Brightness ");
analogWrite(led, 400);
}
else if(val>450 && val<550)
{
lcd.setCursor(0,0);
lcd.print(" 60% ");
lcd.setCursor(0,1);
lcd.print(" Brightness ");
analogWrite(led, 600);
}
else if(val>550 && val<600)
{
lcd.setCursor(0,0);
lcd.print(" 100% ");;
lcd.setCursor(0,1);
lcd.print(" Brightness ");
analogWrite(led, 1023);
}
else if(val<300)
{
lcd.setCursor(0,0);
lcd.print(" 0% ");
lcd.setCursor(0,1);
lcd.print(" Brightness ");
analogWrite(led, 0);
}
}
}
 
void showTime()
{
lcd.setCursor(0,0);
lcd.print(" Time:");
lcd.print(now.hour());
lcd.print(':');
lcd.print(now.minute());
lcd.print(':');
lcd.print(now.second());
lcd.print(" ");
}
 
void button_ISR()
{
buttonFlag = 1;
if((millis() - previousPress) > buttonDebounce && buttonFlag)
{
previousPress = millis();
if(digitalRead(buttonPin) == LOW && previousState == HIGH)
{
path =! path;
previousState = LOW;
}
 
else if(digitalRead(buttonPin) == HIGH && previousState == LOW)
{
previousState = HIGH;
}
buttonFlag = 0;
}
}
 
unsigned char checkLessThanOrEqual(userTime_t a, userTime_t b)
{
if(a.temp_hour < b.temp_hour)
return true;
else
{
if ((a.temp_hour == b.temp_hour) && (a.temp_minute < b.temp_minute))
{
return true;
}
else
{
if(a.temp_hour > b.temp_hour)
return false;
else
{
if((a.temp_minute == b.temp_minute) && (a.temp_second < b.temp_second))
{
return true;
}
else
{
if(a.temp_minute > b.temp_minute)
return false;
else
{
if(a.temp_second == b.temp_second)
{
return true;
}
else
{
return false;
}
}
}
}
}
}
}
 
void loadHandler(int onTimeHr, int onTimeMin, int onTimeSec, int offTimeHr, int offTimeMin, int offTimeSec, int rtcTimeHr, int rtcTimeMin, int rtcTimeSec)
{
 
userTime_t in1 = {onTimeHr, onTimeMin, onTimeSec}, in2 = {offTimeHr, offTimeMin, offTimeSec}, rtc_hr = {rtcTimeHr, rtcTimeMin, rtcTimeSec}, a = {}, b = {};
 
if(checkLessThanOrEqual(in1, in2))
{
onOrOffFlag = ON;
memcpy(&a, &in1, sizeof(userTime_t));
memcpy(&b, &in2, sizeof(userTime_t));
}
else
{
onOrOffFlag = OFF;
memcpy(&a, &in2, sizeof(userTime_t));
memcpy(&b, &in1, sizeof(userTime_t));
 
}
 
if((checkLessThanOrEqual(a, rtc_hr)) && (checkLessThanOrEqual(rtc_hr, b)))
{
if(onOrOffFlag == ON)
{
// Switch on the load
digitalWrite(led,HIGH);
lcd.setCursor(0,1);
lcd.print("OffTime:");
lcd.print(off_hour);
lcd.print(':');
lcd.print(off_minute);
lcd.print(':');
lcd.print(off_second);
 
 
}
else
{
// Switch off the load
digitalWrite(led,LOW);
lcd.setCursor(0,1);
lcd.print(" OnTime:");
lcd.print(on_hour);
lcd.print(':');
lcd.print(on_minute);
lcd.print(':');
lcd.print(on_second);
 
}
}
else
{
if(onOrOffFlag == ON)
{
// Switch off the load
digitalWrite(led,LOW);
lcd.setCursor(0,1);
lcd.print(" OnTime:");
lcd.print(on_hour);
lcd.print(':');
lcd.print(on_minute);
lcd.print(':');
lcd.print(on_second);
}
else
{
// Switch on the load
digitalWrite(led,HIGH);
lcd.setCursor(0,1);
lcd.print("OffTime:");
lcd.print(off_hour);
lcd.print(':');
lcd.print(off_minute);
lcd.print(':');
lcd.print(off_second);
}
}
}

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleInterfacing PMS5003 PM2.5 Air Quality Sensor with Arduino
Next Article RFID RC522 Attendance System Using Arduino with Data Logger

Related Posts

DC Energy Meter using Arduino

Build a DC Energy Meter using Arduino – 32V/5A

Updated:August 26, 20252K
Interfacing ADXL375 Accelerometer with Arduino

Interfacing ADXL375 Accelerometer with Arduino (±200g)

Updated:June 28, 2025
PZEM-004T Arduino Energy Meter

DIY AC Energy Meter using PZEM-004T & Arduino

Updated:March 6, 20258K
Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Updated:February 2, 20259K
Password Based Door Lock Security System Using Arduino & Keypad

Password Based Door Lock Security System Using Arduino & Keypad

Updated:February 2, 20252436K
Earthquake Detector Alarm with with Accelerometer & Arduino

Earthquake Detector Alarm with Accelerometer & Arduino

Updated:February 2, 2025661K
View 7 Comments

7 Comments

  1. Sadokatkhon on October 22, 2019 8:12 PM

    That’s really useful. It helped me to choose a suitable theme for my final year project.
    But how can I control time just for one lamp that switches on in the darkness? Should I use real time clock or is there any simple way of doing this?

    Reply
    • Alex Newton on October 22, 2019 10:11 PM

      Use rtc. Or there is another way by using millis function in code.

      Reply
  2. yashashree on September 25, 2020 4:44 PM

    i am getting error on line no 8 . error is RTC_DS3231 does not name a type

    Reply
  3. Umar on October 15, 2020 7:42 PM

    Does it possible that light should be on for 12-16 hrs by automaticaly sensing sun hrs and if sun set remaining hrs used from artifical light source.

    Reply
  4. Karl Steeg on August 23, 2021 12:02 AM

    Hi

    Nice Project.
    how would i fit an I2C LCD2004 screen on it?

    Reply
  5. Karl Steeg on August 23, 2021 2:37 AM

    Hi
    Good Project.

    How can i use it on an I2C 2004LCD screen?

    Reply
  6. vakaswetha on March 4, 2022 11:08 PM

    Good project.
    Is this code working. Please tell me.

    Reply

CommentsCancel reply

Latest Posts
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

May 31, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

February 1, 2026
Top Posts & Pages
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
    ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • How to use INA226 DC Current Sensor with Arduino
    How to use INA226 DC Current Sensor with Arduino
  • Pulse Rate (BPM) Monitor using Arduino & Pulse Sensor
    Pulse Rate (BPM) Monitor using Arduino & Pulse Sensor
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • Earthquake Detector Alarm with Accelerometer & Arduino
    Earthquake Detector Alarm with Accelerometer & Arduino
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (204)
    • ESP32 MicroPython (7)
    • ESP32 Projects (81)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.