WHAT'S NEW?
Loading...

Intelligent Room Lightening Control System



Wouldn’t it be amazing if the light in a room gets automatically switched on when there are people in the room and automatically gets switched off when the last person leaves the room!! This would save a lot of energy. Especially in bathrooms where we always forget to switch off the lights. Well this is one such projects which used Atmega 168 as micro-controller and 2 LDRs as sensor.

APPARATUS


•    Atmega 168
•    2 LDR
•    4 resistance 2 of 100kohm 2 of 330ohm
•    Relay 12v
•    Transistor 2N222
•    16*2 LCD
•    Potentiometer 10k
•    12V source
•    5v source
•    Light source for the LDRs.
•    2 capacitors 1uF

Circuit Diagram

 LDC pinout diagram:



Code:

AVR C code

main 

lcd header file 

Logic

 

I have used the ADC in free running mode. The value from both the LDRs are read and then converted to binary form depending on whether it is above threshold value (1) or below (0). Depending upon which LDR is cut first, we could find whether the person is entering of leaving the room. If LDR 1 is cut first then I assumed that the person is entering while when LDR 2 is cut first then the person is leaving the room.
How to write this in program? That is the main question which might be eating your brain now, isn’t it? Let me help you out.
Consider the light is falling on the LDR continuously. The value will be below threshold or binary 0. The difference between them will be 0. If have set the value of previous difference to 0 considering there is no person in the room initially. Let the person enter the room. First LDR 1 will be cut which means it will go high(1). Difference will be 1. As long as it is high it will be 1 but if you calculate the difference of difference, it will be 1 only once when the value just changed and then 0. After this both LDR1 and LDR 2 will be high. Third step LDR1 will go low and LDR 2 will still be high. Finally both LDR will be low. If you observe the sequence of non-zero values in the array diff_diff (difference of difference), it follows a regular pattern. Same with the case when going out. Now I have used this result to increase or decrease the counter. When the value of counter is less than 1, MCU sends the command to switch off the light (PC3).


The need of transistor relays and capacitors that I have used had been explained in my last project with lighting automation using sound (clapping). LCD connection is just for fine tuning purpose. You won’t require it once you are done. So you can remove the codes related to it.

More Intelligence you can add

If you want to use it only in night time not in day time. Then you could connect a third LDR and read it at regular interval using interrupt. When you find its value above which you can declare its night or evening, set a flag to 1 and 0 otherwise. In the main loop, put the while content inside another while(1). Change the condition of the inner while to check for flag==1. And you are done.

One another way could be to use a real time clock or even timer to set when to use it and when not to.

Or the simplest way I would say is to connect a switch to live wire in relay. Switch it off in day time and switch it on at night when you want the automation to work for you. Simple as that!


YouTube Link:




0 comments:

Post a Comment

Suggestions and Comments are welcome!