LDR based Automatic Street Light using Microcontroller

Street light or flood light which is completely automatic makes life easy. Nowadays powerful LEDs are using as flood lights. They have many advantages over old lights like least power consumption, long life, DC operated etc. As they work on DC therefore we can directly use them with batteries without any AC DC conversion losses. Lets see how to build a completely automatic street light.

20W 12Volt LED
Figure 1: 20W 12Volt LED


Auto Street Light project  has the following specifications:

I am calling this project as “Auto Street Light” due to its complete automatic features. When sun rises it will turn off and when sun will goes down it will turn on automatically. Moreover as I included the battery feature in it therefore in case of interruption of power mains it will not turn off during night until you want to.

 Required Components:

Only battery included in this Auto Street Light project is expensive but other things are of very low cost. Components you will be needed to build this project are as follows:

  • Battery12 Volt 7AH
  • Transformer 12 Volt 3 Amps
  • 12 Volt LED Flood Light (20-30 Watt)
  • 3 x Connectors
  • 2 x MOSFETs IRF530
  • 1 x ATmega8
  • 1 x 7 Pin Header
  • 1 x SPDT Button
  • 2 x 100nF Capacitor
  • 2 x 10uF Capacitor
  • 1 x 0.33uF Capacitor
  • 1 x 1000uF Capacitor
  • 2 x 100uF Capacitor
  • 4 x 1k Resistor
  • 5 x 10k Resistor
  • 1 LDR (Light Dependent Resistor)
  • PCB and other wires etc
  • Soldering components

Circuit Diagram:

Automatic Street Light circuit diagram
Figure 2: Automatic Street Light circuit diagram


Let’s start with the brain of the Auto Street Light which is this microcontroller IC1. I chose the ATmega8 which is in very small size yet powerful microcontroller from the family of Atmel AVR Microcontrollers. This microcontroller will control all the functionalities of the system. Functionalities like it will control the voltage level tocharge the battery at constant voltage and to turn on/off the load according to the status of LDR. We will discuss these functionalities in details in Coding Part.


The second main components of the system are the MOSFETs. I used two IRF530 MOSFETS in the circuit. IRF530 Q1 is used to control the charging voltage level of the battery and IRF530 Q2 is used here to control the load i.e. 20W LED.

LDR (light depended resistor) is used here to know the light level of the surrounding. During day it tells the system to turn off the LED and during night, it tells the system to turn on the LED.


I am using a 7AH sealed lead acid battery. A 7 AH battery means if the battery will give 7 amps then it will work for an hour ideally. A 7 AH lead acid battery should be charge at 7/10 = 0.7 Amps. So I am charging the battery at this current level. I will recommend you to study the following articles first if you want to completely understand the battery charging procedure:

Power Sources

There are two power sources in the circuit, one from the Grid and other from thebattery. Grid can be cut off but battery will be always there that’s why I gave the voltage to the circuitry from the battery. Battery is of 12 volts so I used 7805 voltage regulator to make 5 volts.  The other power source is grid which will charge the battery and energize the 20W LED.

To step down the voltage we will need a transformer. Transformer comes in many ranges of voltage and current. We will need at least 12 volt / 3 Amp ratedtransformer. Its reason is as  I am charging the battery at 0.7 amps and LED is of 20 Watts, 12Volt which means it needs 20/12 = 1.67 Amps to glow fully. So the total current requirement of our system is 1.67 + 0.7 = 2.367 Amps. Therefore I used 26 VA transformer for the system.

Complete Circuit Diagram of Automatic Street Light
Figure 3: Complete Circuit Diagram of Automatic Street Light

Coding part

Coding part is the really easy part. If you know the basic use of Atmel AVR microcontrollers and timers of Atmel AVR microcontrollers then it will be really easy for you to understand the coding area. I will explain the area of coding which are directly related to the Auto Street Light circuit.

Charging Area

if (conv_grid > 15){
     if (conv_bat < 14.3 )
     OCR1A = OCR1A +1;
           if (conv_bat  >14.5)
     OCR1A = OCR1A -1;
     if (OCR1A >1020)
     OCR1A = 1020;

To charge the battery the voltage level coming from grid should be greater than 14.5 volts that’s why I used a check here that if ‘conv_grid’ is greater than 15 then it will change the value of the timer to control the charging voltage level.

As I am charging the battery at 14.4 volts therefore I made two checks here to maintain the charging level at 14.4 volts. Voltage will be control by the timers of Atmel AVRs in software part and through MOSFET in hardware part.

Controlling Part

if ((PIND & (1 << 7))==0){
     if (conv_ldr < 11.5){
     if (conv_bat < 11) 
     PORTB |= 1 << 0;
     PORTB &= ~(1<<0);
     else {
           PORTB |= 1 << 0;}
           PORTB &= ~(1<<0);

There is a SPDT button interfaced with the system. If that button is at low level then LDR will control the load otherwise not.

If that SPDT button is at HIGH level then LDR will check its value for every instant and work according to the function given above.

You can download the whole code from the button present below.

Complete Code



Don’t forget to give us feedback about the project and do like our facebook page 🙂


Electrical engineering is my profession, my hobby and my passion. I completed bachelors of electrical engineering in 2015. Currently I am working with a utility company which provides electricity to its consumers. Power Electronics, Embedded Systems and Energy Metering are my fields of specialization. In free time I listen music and watch movies.

What do you think?