Arduino based Automatic Light Controller

The automatic light controller offers energy saving and convenience in the areas with a photosensor (LDR). LDR senses the ambient light conditions in the surrounding area and switches ON-OFF the lighting load. The darkness level in the surrounding is settable.

It is in-built with an additional PIR Sensor which TURNS ON Light in the presence of human and switches OFF after 10 seconds if no human detected for energy saving operation.

Thus it provides artificial light only when it is needed. This reduces a large amount of energy wastage and helps in making the most energy-efficient lighting.

Components Needed

The following components are required for making an automatic light bulb controller.
  1.  Arduino Uno
  2. PIR Sensor.
  3. LDR Sensor.
  4. 1k & 10k Resistors
  5. 12V Relay
  6. BC548 Transistor
  7. Switches.

Circuit Diagram of Automatic Light Controller

The circuit is constructed with PIR sensor, LDR and Arduino. Light Load is connected to Relay. Manual on off is possible with given switches.
Automatic Light Controller Circuit Diagram
Automatic Light Controller Circuit Diagram

Program Code

Day night Switch with Occupancy Sensor (Automatic Light Controller)

const int RELAY =12;   //Lock Relay or motor
//Key connections with arduino
const int on_key =3;
const int off_key =2;
int counter =0, manual =0;
//Sensor Connections
const int LDR = A5 ;
const int PIR =4;
//=================================================================
// SETUP
//=================================================================
void setup (){
pinMode ( RELAY , OUTPUT );
pinMode ( on_key , INPUT );
pinMode ( off_key , INPUT );
pinMode ( PIR , INPUT );
//Pull up for setpoint keys
digitalWrite ( on_key , HIGH );
digitalWrite ( off_key , HIGH );
digitalWrite ( PIR , HIGH );
digitalWrite ( RELAY , LOW );        //Turn off Relay
}   //
=================================================================
// LOOP
//=================================================================
void loop (){
//Turn on Lights if Motion is detected and Light intensity is low
if( digitalRead ( PIR )== HIGH )
{
counter =1000; //Set 10 Seconds time out counter
if( counter >15) //Motion detected for 1.5 Seconds
{
if( analogRead ( LDR )>512) //Light intensity is low
{
digitalWrite ( RELAY , HIGH ); //Turn on Lights
}
}
} counter –;
if( counter ==0)
{
if( manual ==0) //Check that it is not manually turned on
{
digitalWrite ( RELAY , LOW );
}
}
//Get user input for setpointsif( digitalRead ( on_key )== LOW )
{
digitalWrite ( RELAY , HIGH ); //Turn on Lights
manual =1; //Manually it is turned on
}     if(digitalRead ( off_key )== LOW )
{
digitalWrite ( RELAY , LOW ); //Turn off Lights
manual =0;
} delay (10); //Update at every 10mSeconds
}//
=================================================================