Automatic Light Controller with Arduino

 Here an automatic light controller with Arduino is build. The automatic light controller turns on bulb only when it is required and is thus useful in saving power. The light bulb is connected to Arduino which is automatically turned on when the ambient light in the room is low or a somebody is near a PIR(Passive Infrared) sensor. User can also turn on or off the bulb manually using two switches. 

The following shows the circuit diagram of the automatic light controller.


In the above circuit diagram, the LDR(Light Dependent Resistor) is connected to the analog pin A1. The LDR resistance is inversely related to the ambient light in the room. When the ambient light in the room is low then the LDR resistance increases which is detected by the ADC pin A1. When low light in the room is detected by the Arduino ADC, the relay which is connected to digital pin 10 is turned on. The light bulb is connected relay using BC548 and diode. 

Similarly a PIR sensor with Arduino is used in order to control the light bulb based on motion detection. The PIR sensor is connected to Arduino digital pin 5. When motion is detected in the range of the PIR then the bulb light connected to the relay is turned on. 

Finally for manual control of the light bulb two push button switch are used. 

Program code

The following is the Arduino code for the automatic light controller.

//Lock Relay or motor
const int RelayPin = 10; 

//Push button connections
const int OnKeyPin=4;
const int OffKeyPin=3;
int counter=0, manual=0;

//Sensor Connections
const int LDRpin = A1;
const int PIRpin = 5;

void setup (){
   pinMode(RelayPin,OUTPUT);
   pinMode(OnKeyPin,INPUT);
   pinMode(OffKeyPin,INPUT);
   pinMode(PIRpin,INPUT);
   
   //Pull up for setpoint keys
   digitalWrite(OnKeyPin,HIGH );
   digitalWrite(OffKeyPin,HIGH );
   digitalWrite(PIRpin,HIGH);
   digitalWrite(RelayPin,LOW); //Turn off Relay
}

void loop (){
   //Turn on Lights if Motion is detected and Light intensity is low
   if(digitalRead(PIRpin)==HIGH){
      counter =1000; //Set 10 Seconds time out counter
      //Motion detected for 1.5 Seconds
      if(counter>15){
	 //Light intensity is low
	 if(analogRead(LDRpin)>512){
	 digitalWrite(RelayPin,HIGH); //Turn on Lights
	 }
      }
   }

counter --;

   if(counter==0){
   //Check that it is not manually turned on
      if(manual==0){
	 digitalWrite(RelayPin,LOW);
      }
   }
   
   //Get user input for setpoints
   if( digitalRead (OnKeyPin)==LOW ){
      digitalWrite(RelayPin,HIGH); //Turn on Lights
      manual=1; //Manually it is turned on
   }
   
   if(digitalRead(OffKeyPin)==LOW){
   digitalWrite(RelayPin,LOW); //Turn off Lights
   manual =0;
   }
   
delay (10); //Update at every 10ms
}

In this tutorial we have used PIR sensor with Arduino but one can also use ATmega32A as in the tutorial PIR Sensor with AVR Interfacing and Programming.One can also create Light Dependent Resistor (LDR) Light Detector Alarm with Arduino which is similar to this tutorial.

Post a Comment

Previous Post Next Post