# Arduino based Automatic Light Controller

- Link: https://studyelectrical.com/2016/11/arduino-based-automatic-light-bulb-controller.html
- Published: 2016-11-27T17:59:00+00:00
- Author: 

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](https://studyelectrical.com/2016/04/an-introduction-to-arduino-for-beginners.html).
Light Load is connected to Relay. Manual on off is possible with given switches.

![Automatic Light Controller Circuit Diagram](https://3.bp.blogspot.com/-JjJZURXhKdQ/
WDsVWSLS9OI/AAAAAAAACGk/0WQyyTtAS0gK7e_ZgV0EtYPn1V9YYqzmACLcB/s1600/ard.bmp "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 setpoints_if( 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_ }// ==========================
> =======================================

### Related posts:

No related posts.
