Want to know why your monthly electricity bills are “so high”? This is because when a person inside the room leaves in a hurry, they unknowingly leave the lights and fans on.
So what comes next? The only way to solve this is to use a Smart Automated Home Lighting System. In this system, when a person enters the room, the fluorescent lights turn on automatically and turn off automatically when there is no body inside the room. This implies that the entire system is now at the peak of its movement.
Here we use 8051 microcontroller along with two sensors. These are IR sensors or LED light that fall on the LDR that work together to detect movement within the room, while the microcontroller acts as a people counter and increases or decreases depending on the number of people inside the room. If the room is empty, lamps, fluorescent lamps, fans, etc. They automatically turn off when the last person who was there leaves.
Block Diagram:

Figure 1: Automatic Home Light System Overview
Circuit Component Description
Before explaining how they work, let’s find out what LDR Sensors are:
• When the light level is less intense, the LDR resistance is high
• But when light falls on the LDR, the resistance drops

Figure 2: Typical light-dependent resistor image
Explanation of the block diagram of each LDR working

Figure 3: Block diagram representing the operating principle of the LDR with microcontroller

Figure 4: Block diagram representing the microcontroller’s response to LDR circuit signals
Sensor working
As the properties are already indicated
Case 1
When no one interrupts the light falling on the LDR:
The resistance of LDR is low and therefore the base of the transistor does not receive enough voltage to turn on the transistor and therefore the collector voltage is almost equal to the supply voltage which is 5V in this case .
Case 2
When a person interrupts the light falling on the LDR:
The resistance of LDR is high and therefore the transistor turns on and the collector voltage almost becomes equal to zero voltage.
These different collector voltages are picked up by the microcontroller pins that decide whether the person enters or leaves the room.
The LDR sensor is used for experimental purposes only. In reality, phototransistors like IR sensors should be used because of good sensitivity.
Like this:

Fig. 5: Typical image of IR transmitter and receiver
Features of 8051 Microcontroller
1) 8051 has 128 bytes of RAM
2) 8051 has 128 user-defined flags
3) Consists of a 16-bit address bus
4) It also consists of 3 internal and two external interrupts
5) Less power consumption in 8051 compared to other microcontroller
6) Consists of a 16-bit program counter and a data pointer
7) 8051 can process 1 million one-cycle instructions per second
8) It also consists of 32 general purpose registers, each with 8 bits
9) The ROM on the 8051 is 4 Kbytes in size
10) Also consists of two 16-bit timers/counters

Fig. 6: Block diagram of 8051 microcontroller
Fnd: There are two types:
Common Anode and Common Cathode
I used common cathode in this project. Therefore, for the display to light up, logic “1” must be sent.
Final Image with all Circuit Components

Fig. 7: Image showing circuit for detecting visitor entry or exit in action
Detecting whether a person is entering the room or leaving the room
Case 1:
When the person enters the room – when the person enters the room, first sensor1 is interrupted and then sensor 2
The decoding of these two signals takes place as follows: If a first minimum is detected due to sensor-1, then the second minimum detected by the microcontroller due to sensor-2 will indicate that a person is entering the room and hence the counter will increase on one and the lamp will turn on.
Case 2:
When the person leaves the room – he will stop sensor2 and then stop sensor-1.
The decoding of these two signals occurs as follows: if one low fist is detected due to sensor-2, then the second low detected by the microcontroller due to sensor-1 will indicate that the person is leaving the room and hence the counter will decrease by one and the lamp will turn off if the counter value reaches zero.
Software and project overview
Software Overview

Fig. 8: Flowchart of Code C used for Visitor Detection and Automatic Light Switching
Other features that can be included
1) During the day, when the person enters the room, the lights (lamps) should not turn on automatically
2) If the person inside the room wants to intentionally reverse the state of the room, this can be done using the remote control interfaced with the microcontroller.
Project Overview

Fig. 9: Overview of the Automatic Light System working algorithm
Project source code
###
CODE: IT IS WRITTEN IN ASM LANGUAGE:
organization 0000h
main ljmp
organization 0100h
main:mov p0,#00h //make p0 as port o/p BULB IS CONNECTED HERE
mov p3,#0ffh //make p3 as i/p port LDR SENSORS ARE CONNECTED HERE
mov p2,#00h //make p2 as o/p port FND IS CONNECTED HERE
movement r0,#00h
mov p2,#0ffh
above:
call delay
call delay
call delay
call delay
call delay
call delay
f2:jb p3.0,f1 // CONTINUOUSLY CHECK IF THERE IS LOW IN SENSOR-1 AND SENSOR-2 ALTERNATELY
call delay
//
lcall delay // DELAY TO CAPTURE THIS EVENT CORRECTLY
call delay //
call delay //
call delay //
k2:jb p3.2,k2 // AFTER A DOWN OCCURS IN SENSOR-1 THEN CHECK ON SENSOR-2 IF THE PERSON IS REALLY ENTERING THE ROOM
call delay
call delay
call delay
call delay
call delay
inc r0
set p0.0
call delay
call delay
call delay
sjmp fnd1 // DISPLAY THE INCREASED VALUE IN FND
call delay
call delay
call delay
call delay
call delay
call delay
f1:jb p3.2,f2 // CONTINUOUSLY CHECK IF THERE IS LOW IN SENSOR-1 AND SENSOR-2 ALTERNATELY
call delay //
lcall delay // DELAY TO CAPTURE THE EVENT
call delay //
call delay //
call delay //
k1:jb p3.0,k1 //AFTER THE DOWN OCCURRED IN SENSOR-2, CHECK IN SENSOR-1 IF THE PERSON IS REALLY LEAVING THE ROOM.
call delay
call delay
call delay
call delay
call delay
December r0
call delay
call delay
call delay
call delay
call delay
call delay
ljmp fnd2 // DISPLAY DECREASED COUNT
c2:
cjne r0,#00h,j1
clr p0.0
ljmp up
j1:ljmp up
find1:
cjne r0,#01h,a1
movement p2,#0f9h
ljmp up
a1:cjne r0,#02h,a2
movement p2,#0a4h
ljmp up
a2:cjne r0,#03h,a3
movement p2,#0b0h
ljmp up
a3:cjne r0,#04h,a4
movement p2,#7pm
ljmp up
a4:cjne r0,#05h,a5
movement p2,#92h
ljmp up
a5:cjne r0,#06h,a6
movement p2,#82h
ljmp up
a6:cjne r0,#07h,a7
movement p2,#0f8h
ljmp up
a7:cjne r0,#08h,a8
movement p2,#00h
ljmp up
a8:cjne r0,#09h,a9
movement p2,#10h
a9:ljmp up
find2:
cjne r0,#00h,ac1
mov p2,#0ffh
ljmp c2
ac1:cjne r0,#01h,b1
movement p2,#0f9h
ljmp c2
b1:cjne r0,#02h,b2
movement p2,#0a4h
ljmp c2
b2:cjne r0,#03h,b3
movement p2,#0b0h
ljmp c2
b3:cjne r0,#04h,b4
movement p2,#7pm
ljmp c2
b4:cjne r0,#05h,b5
movement p2,#92h
ljmp c2
b5:cjne r0,#06h,b6
movement p2,#82h
ljmp c2
b6:cjne r0,#07h,b7
movement p2,#0f8h
ljmp c2
b7:cjne r0,#08h,b8
movement p2,#00h
ljmp c2
b8:cjne r0,#09h,b9
movement p2,#10h
ljmp c2
b9:ljmp c2
delay:mov r2,#128
up1:mov r1,#0ffh
here:djnz r1, here
djnz r2,up1
ret
end
###
Circuit diagrams
Circuit Diagram-8051-Microcontroller Based Auto Lights |
 |
Project video