Documente Academic
Documente Profesional
Documente Cultură
This Project Bi-directional Visitor Counter and Home Automation using Microcontroller is
a reliable circuit that takes over the task of controlling the room lights as well as counting
number of persons/ visitors in the room very accurately. When somebody enters into the room
then the counter is incremented by one and the light in the room will be switched ON and
when any one leaves the room then the counter is decremented by one. The light will be only
switched OFF until all the persons in the room go out. The total number of persons inside the
room is also displayed on the seven segment displays.
The microcontroller does the above job. It receives the signals from the sensors, and this
signal is operated under the control of software which is stored in ROM. Microcontroller
AT89S52 continuously monitor the Infrared Receivers, When any object pass through the IR
Receivers then the IR Rays falling on the receiver are obstructed , this obstruction is sensed
by the Microcontroller.
1
Fig. 2 Circuit Diagram
2
2) Circuit Components:
4 Resistor of 680 ohms
Diode
2 Electrolytic Capacitor
2 Ceramic Capacitor
AT89C52
7805
5 LED
Relay
2 LDR
Transformer
7 segment Display
2.1) RESISTOR:
Resistors restrict the flow of electric current, for example a resistor is placed in series with a
light emitting diode(LED) to limit the current passing through the LED.
3
2.2)Diode:
A diode is a specialized electronic component with two electrodes called the anode and the
cathode. Most diodes are made with semiconductor materials such as silicon, germanium, or
selenium
Fig. 4 Diode
4
Fig. 5 Potentiometer
2.4)Electrolytic Capacitor:
An electrolytic capacitor is a capacitor in which one electrode is made of a special metal on
which an oxide layer is formed. This thin oxide layer acts as the dielectric of the capacitor. An
electrolyte covers the surface of the oxide layer and serves as the second electrode of the
capacitor.
2.5)Ceramic Capacitor:
5
A ceramic capacitor is a fixed value capacitor in which ceramic material acts as the dielectric.
It is constructed of two or more alternating layers of ceramic and a metal layer acting as the
electrodes. The composition of the ceramic material defines the electrical behavior and
therefore applications
6
Fig.9 Crystal Oscillator Schematic
2.7) AT89C51:
7
Fig. 10 AT89C51
2.7.1)Description:
The AT89C51 is a low-power, high-performance CMOS 8-bit microcomputer with 4K bytes
of Flash Programmable and Erasable Read Only Memory (PEROM). The device is
manufactured using Atmels high density nonvolatile memory technology and is compatible
with the industry standard MCS-51TM instruction set and pinout. The on-chip Flash allows
8
the program memory to be reprogrammed in-system or by a conventional nonvolatile
memory programmer. By combining a versatile 8-bit CPU with Flash on a monolithic chip,
the Atmel AT89C51 is a powerful microcomputer which provides a highly flexible and cost
effective solution to many embedded control applications.
GND: Ground.
Port 0: Port 0 is an 8-bit open drain bidirectional I/O port. As an output port each pin can
sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as high
impedance inputs. Port 0 may also be configured to be the multiplexed low order address/data
bus during accesses to external program and data memory. In this mode P0 has internal pull
ups. Port 0 also receives the code bytes during Flash programming, and outputs the code
bytes during program verification. External pull ups are required during program verification.
Port 1: Port 1 is an 8-bit bidirectional I/O port with internal pull ups. The Port 1 output
9
buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins they are pulled
high by the internal pull ups and can be used as inputs. As inputs, Port 1 pins that are
externally being pulled low will source current (IIL) because of the internal pull ups. Port 1
also receives the low-order address bytes low-order address bytes during Flash programming
and verification.
Port 2: Port 2 is an 8-bit bidirectional I/O port with internal pull ups. The Port 2 output
buffers can sink/source four TTL inputs. When 1s are written to Port 2 pins they are pulled
high by the internal pull ups and can be used as inputs. As inputs, Port 2 pins that are
externally being pulled low will source current (IIL) because of the internal pull ups. Port 2
emits the high-order address byte during fetches from external program memory and during
accesses to external data memory that use 16-bit addresses (MOVX @DPTR). In this
application it uses strong internal pull ups when emitting 1s. During accesses to external data
memory that use 8-bit addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special
Function Register. Port 2 also receives the high-order address bits and some control signals
during Flash programming and verification.
Port 3: Port 3 is an 8-bit bidirectional I/O port with internal pull ups. The Port 3 output
buffers can sink/source four TTL inputs. When 1s are written to Port 3 pins they are pulled
high by the internal pull ups and can be used as inputs. As inputs, Port 3 pins that are
externally being pulled low will source current (IIL) because of the pull ups. Port 3 also
serves the functions of various special features of the AT89C51 as listed below:
10
P3.6 WR (external data memory write strobe)
Port 3 also receives some control signals for Flash programming and verification.
RST: Reset input. A high on this pin for two machine cycles while the oscillator is running
resets the device.
ALE/PROG: Address Latch Enable output pulse for latching the low byte of the address
during accesses to external memory. This pin is also the program pulse input (PROG) during
Flash programming. In normal operation ALE is emitted at a constant rate of 1/6 the
oscillator frequency, and may be used for external timing or clocking purposes. Note,
however, that one ALE pulse is skipped during each access to external Data Memory. If
desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set,
ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin is weakly
pulled high. Setting the ALE-disable bit has no effect if the microcontroller is in external
execution mode.
PSEN: Program Store Enable is the read strobe to external program memory. When the
AT89C51 is executing code from external program memory, PSEN is activated twice each
machine cycle, except that two PSEN activations are skipped during each access to external
data memory.
EA/VPP: External Access Enable. EA must be strapped to GND in order to enable the
device to fetch code from external program memory locations starting at 0000H up to
FFFFH. Note, however, that if lock bit 1 is programmed, EA will be internally latched on
reset. EA should be strapped to VCC for internal program executions. This pin also receives
the 12-volt programming enable voltage (VPP) during Flash programming, for parts that
require 12-volt VPP.
XTAL1: Input to the inverting oscillator amplifier and input to the internal clock operating
circuit.
11
MEMORY SPACE ALLOCATION:
The 8051 has three very general types of memory. To effectively program the 8051 it is
necessary to have a basic understanding of these memory types. The memory types are
illustrated in the following graphic. They are: On-Chip Memory, External Code Memory, and
External RAM.
On-chip ROM
The 89C51 has a 4K bytes of on-chip ROM. This 4K bytes ROM memory has memory
addresses of 0000 to 0FFFh. Program addresses higher than 0FFFh, which exceed the internal
ROM capacity will cause the microcontroller to automatically fetch code bytes from external
memory. Code bytes can also be fetched exclusively from an external memory, addresses
0000h to FFFFh, by connecting the external access pin to ground. The program counter
doesnt care where the code is: the circuit designer decides whether the code is found totally
in internal ROM, totally in external ROM or in a combination of internal and external ROM.
On-chip RAM
The 1289 bytes of RAM inside the 8051 are assigned addresses 00 to 7Fh. These 128 bytes
can be divided into three different groups as follows:
A total of 32 bytes from locations 00 to 1Fh are set aside for register banks and the stack. A
total of 16 bytes from locations 20h to 2Fh are set aside for bit addressable read/write
memory and instructions. A total of 80 bytes from locations 30h to 7Fh are used for read and
write storage, or what is normally called a scratch pad. These 80 locations of RAM are
widely used for the purpose of storing data and parameters by 8051 programmers.
12
Fig. 12 ROM & RAM in 8051 Microcontroller
External RAM :
External RAM is RAM memory that resides off-chip. This is often in the form of standard
static RAM or flash refers to any memory (Code, RAM, or other) that physically exists on the
microcontroller itself. On-chip memory can be of several types, but we'll get into that shortly.
External RAM As an obvious opposite of Internal RAM, the 8051 also supports what is
called External RAM. As the name suggests, External RAM is any random access memory
which is found off-chip. Since the memory is off-chip it is not as flexible in terms of
accessing, and is also slower. For example, to increment an Internal RAM location by 1
requires only 1 instruction and 1 instruction cycle. To increment a 1-byte value stored in
External RAM requires 4 instructions and 7 instruction cycles. In this case, external memory
13
is 7 times slower!
Code Memory :
Code memory is the memory that holds the actual 8051 program that is to be run. This
memory is limited to 64K and comes in many shapes and sizes: Code memory may be found
on-chip, either burned into the microcontroller as ROM or EPROM. Code may also be stored
completely off-chip in an external ROM or, more commonly, an external EPROM. Flash
RAM is also another popular method of storing a program. Various combinations of these
memory types may also be used-- that is to say, it is possible to have 4K of code memory on-
chip and 64k of code memory off-chip in an EPROM.
Registers:
In the CPU, registers are used to store information temporarily. That information could be a
byte of data to be processed, or an address pointing to the data to be fetched. In the 8051
there us only one data type: 8 bits. With an 8- bit data type, any data larger than 8 bits has to
be broken into 8-bit chunks before it is processed.
The most commonly used registers of the 8051 are A(accumulator), B, R0, R1, R2, R3, R4,
R5, R6, R7, DPTR (data pointer) and PC (program counter). All the above registers are 8-bit
registers except DPTR and the program counter. The accumulator A is used for all arithmetic
and logic instructions.
14
Fig. 13 Some 8-bit registers & some 16-bit registers
The program status word (PSW) register is an 8-bit register. It is also referred as the flag
register. Although the PSW register is 8-bit wide, only 6 bits of it are used by the
microcontroller. The two unused bits are user definable flags. Four of the flags are
conditional flags, meaning they indicate some conditions that resulted
after an instruction was executed. These four are CY (carry), AC (auxiliary carry), P (parity),
and OV (overflow). The bits of the PSW register are shown below:
Fig.14 AT89S52
16
Fig.15 AT89S52 Pin Description
2.8)78XX
The 78xx (sometimes L78xx, LM78xx, MC78xx...) is a family of self-contained fixed linear
voltage regulator integrated circuits. The 78xx family is commonly used in electronic circuits
requiring a regulated power supply due to their ease-of- use and low cost. For ICs within the
family, the xx is replaced with two digits, indicating the output voltage (for example, the
7805 has a 5 volt output, while the 7812 produces 12 volts). The 78xx line are positive
voltage regulators: they produce a voltage that is positive relative to a common ground. There
is a related line of 79xx devices which are complementary negative voltage regulators. 78xx
and 79xx ICs can be used in combination to provide positive and negative supply voltages in
the same circuit.
Pin Description:
17
Fig.16 12V Regulated Power Supply Using 7812
2.9)LED
A light-emitting diode (LED) is a two-lead semiconductor light source. It is a basic pn-
junction diode, which emits light when activated.When a suitable voltage is applied to the
leads, electrons are able to recombine with electron holes within the device, releasing energy
in the form of photons. This effect is called electroluminescence, and the color of the light
(corresponding to the energy of the photon) is determined by the energy band gap of the
semiconductor.
Fig.17 LED
18
2.10)Relay
A relay is an electrically operated switch. Many relays use an electromagnet to mechanically
operate a switch, but other operating principles are also used, such as solid-state relays.
Relays are used where it is necessary to control a circuit by a low-power signal (with
complete electrical isolation between control and controlled circuits), or where several
circuits must be controlled by one signal
Fig.19 Relay
2.11)ULN2803
IC ULN2803 consists of octal high voltage, high current darlington transistor arrays. The
eight NPN Darlington connected transistors in this family of arrays are ideally suited for
interfacing between low logic level digital circuitry (such as TTL, CMOS or PMOS/NMOS)
and the higher current/voltage requirements of lamps, relays, printer hammers or other similar
loads for a broad range of computer, industrial, and consumer applications.
19
Fig.20 ULN2803
The ULN 2803 IC consists of eight NPN Darlington connected transistors (often called a
Darlington pair). Darlington pair consists of two bipolar transistors such that the current
amplified by the first is amplified further by the second to get a high current gain or hFE
The figure shown below is one of the eight Darlington pairs of ULN 2803 IC.
Q1 and Q2 both will not conduct as there is no base current provided to them. Thus, nothing
20
will appear at the output (OUT).
Input current will increase and both transistors Q1 and Q2 will begin to conduct. Now, input
current of Q2 is combination of input current and emitter current of Q1, so Q2 will conduct
more than Q1 resulting in higher current gain which is very much required to meet the higher
current requirements of devices like motors, relays etc. Output current flows through Q2
providing a path (sink) to ground for the external circuit that the output is applied to. Thus,
when a 5V input is applied to any of the input pins (1 to 8), output voltage at corresponding
output pin (11 to 18) drops down to zero providing GND for the external circuit. Thus, the
external circuit gets grounded at one end while it is provided +V at its other end. So, the
circuit gets completed and starts operating.
2.12) Transformer
Transformers convert AC electricity from one voltage to another with little loss of power.
Transformers work only with AC and this is one of the reasons why mains electricity is AC.
The two types of transformers Step-up transformers increase voltage, Step-down transformers
reduce voltage. Most power supplies use a step-down transformer to reduce the dangerously
high mains voltage (230V in UK) to a safer low voltage. The input coil is called the primary
and the output coil is called the secondary. There is no electrical connection between the two
coils, instead they are linked by an alternating magnetic field created in the soft-iron core of
the transformer. The two lines in the middle of the circuit symbol represent the core.
Transformers waste very little power so the power out is (almost) equal to the power in. Note
that as voltage is stepped down current is stepped up. The ratio of the number of turns on
each coil, called the turns ratio, determines the ratio of the voltages. A step-down transformer
has a large number of turns on its primary (input) coil which is connected to the high voltage
mains supply, and a small number of turns on its secondary (output) coil to give a low output
voltage.
21
Fig.23 Transformer
2.13)7-Segment Display
The LTS 542 is a 0.52 inch digit height single digit seven-segment display. This device
utilizes Hi-eff. Red LED chips, which are made from GaAsP on GaP substrate, and has a red
face.
Features:
Common Anode
22
Fig.24 Common Cathode & Common Anode 7-Segment Display
23
3) Circuit layout:
The heart of the circuit design lies in designing the microcontroller interface. Here we use the
microcontroller AT89S52. The microcontroller AT89S52 is interfaced to the IR sensor pairs at
two ports pins P1.0 and P1.1 respectively. The 7 segment display is interfaced to the
microcontroller at port P2.Another important aspect of the design involves designing the
oscillator circuit and the reset circuit. The oscillator circuit is designed by selecting a
11.0592MHz quartz crystal and two ceramic capacitors-each 33pF. The reset circuit is
designed by selecting an electrolyte capacitor of 10uF to ensure a reset pulse width of 100ms
and reset pin voltage drop of 1.2V.The sensor circuit is designed by selecting appropriate
value of resistors for both the LED and the phototransistor.
24
4) Operation:
When the system is powered, the compiler initially initializes the stack pointer and all other
variables. It then scans the input ports (PortP1.0 first). In the meantime, when there is no
interruption between the IR LED and the phototransistor of the first sensor pair, the output of
the phototransistor is always at low voltage. In other words port P1.0 is at logic low level.
Now when a transition takes place, i.e. a logic high level is received at port P1.0, the compiler
sees this as an interruption to sense the passage of a person or an object between the LDR and
the phototransistor. As per the program, the count value is increased and this value is
displayed on the Counter. Now the compiler starts scanning the other input pin- P1.1. Similar
to the first sensor pair, for this sensor pair also the phototransistor conducts in absence of any
interruption and P1.1 is at logic low level. In case of an interruption, the pin P1.1 goes high
and this interruption is perceived by decreasing the value of count.The program ensures that
the scanning of both the port pins is done at certain delays so as to avoid confusion of
reading. For instance port P1.0 is scanned for two or three interruptions so as to ensure the
count value is above 1 or 2
25
5) Flow Chart
26
5)Software:
LCD EQU P1
CTL EQU P3
RS EQU P3.0
RW EQU P3.1
E EQU P3.2
LDR1 EQU P0.0
LDR2 EQU P0.1
ORG 0400H
NAME1:DB 'AUTOMATIC ROOM',0DH
NAME2:DB 'LIGHT CONTROLLER',0DH
NAME10:DB 'ENTER_00',0DH
NAME11:DB 'ROOM EMPTY',0DH
NAME12:DB 'ENTER_100',0DH
NAME13:DB 'ROOM FULL',0DH
NAME14:DB 'ENTER_99',0DH
NAME15:DB 'ROOM EMPTY',0DH
ORG 00H
START: ACALL DELAY
ACALL DELAY
MOV R6,#30H
MOV R5,#30H
MOV R4,#34H
MOV P2,#0FFH
ACALL LCD_INT
MOV DPTR,#NAME1
ACALL LCD_STR
ACALL LCDDO
MOV DPTR,#NAME2
ACALL LCD_STR
ACALL TIME
ACALL TIME
ACALL LCD_CLR
27
MOV DPTR,#NAME10
ACALL LCD_STR
SJMP LP
LP: JB LDR1,SEN1
SJMP LP
MAIN: JB LDR1,SEN1
JB LDR2,SEN2
SJMP MAIN
SEN1: JB LDR2,UPCUNT
SJMP SEN1
UPCUNT: NOP
CLR P2.0
INC R6
CJNE R6,#3AH,CUNT9
MOV R6,#30H
ACALL A87
MOV A,R6
ACALL LCD_CHR
ACALL A86
INC R5
MOV A,R5
ACALL LCD_CHR
WAT1: JB LDR2,WAT1
CJNE R5,#3AH,MAIN
ACALL LCD_CLR
MOV DPTR,#NAME12
ACALL LCD_STR
ACALL LCDDO
MOV DPTR,#NAME13
28
ACALL LCD_STR
MOV R5,#39H
MOV R6,#39H
SJMP CON
CON: JB LDR2,C99
SJMP CON
C99: ACALL LCD_CLR
MOV DPTR,#NAME14
ACALL LCD_STR
LJMP MAIN
29
JB LDR2,DON11
SJMP GO4
DON11: DEC R5
ACALL A86
MOV A,R5
ACALL LCD_CHR
DEC R6
ACALL A87
MOV A,R6
ACALL LCD_CHR
WAT4: JB LDR1,WAT4
CJNE R5,#30H,MAIN1
SJMP DOWN9
DOWN9: JB LDR2,DO9
JB LDR1,SEN14
SJMP DOWN9
SEN14: LJMP SEN1
DO9: JB LDR1,D9
SJMP DO9
D9: DEC R6
ACALL A87
MOV A,R6
ACALL LCD_CHR
WAT7: JB LDR1,WAT7
CJNE R6,#31H,DOWN9
NOP
LJMP START
MAIN1: JB LDR1,SEN11
JB LDR2,SEN22
SJMP MAIN1
SEN11: LJMP SEN1
SEN22: JB LDR1,SEN
30
SJMP SEN22
SEN: JB LDR1,SEN
LJMP SEN2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DEC1: DEC R2
RET
31
MOV A,#0C0H
ACALL LCD_CMD
ACALL DELAY
MOV A,#80H
ACALL LCD_CMD
ACALL DELAY
RET
LCD_CLR:MOV A,#01H
ACALL LCD_CMD
ACALL DELAY
RET
LCD_CMD:MOV LCD,A
ACALL LCD_D
CLR RS
ACALL LCD_D
CLR RW
ACALL LCD_D
SETB E
ACALL LCD_D
CLR E
ACALL LCD_D
RET
LCD_CHR:MOV LCD,A
SETB RS
CLR RW
SETB E
32
CLR E
RET
LCD_STR:NOP
LOOP: MOV A,#00H
MOVC A,@A+DPTR
CJNE A,#0DH,NEXT
RET
NEXT: ACALL LCD_CHR
MOV A,#50
ACALL DELAY
INC DPTR
SJMP LOOP
6) Applications:
33
1. This circuit can be used domestically to get an indication of number of persons entering a
party.
3. It can be used at homes and other places to keep a check on the number of persons entering
a secured place.
4. It can also be used as home automation system to ensure energy saving by switching on the
loads and fans only when needed.
7) Limitations:
1. It is a theoretical circuit and may require few changes in practical implementation.
3. More than one candidate should not enter or exit the room. If it happens it will count it as
a single person.
4. With frequent change in the count value, after a certain time the output may look
confusing
5. In this Module we are using a room having capacity of 9 candidates. So we are using only
one segment that can show from 0 to 9 only. For a large room we will use a no. of segments.
For example for 9999 candidate we will use 4 segments
8)Advantages:
1. The Most advantage is that it will help to save electricity. When no one is there in room the
appliances will be off.
2.For School/colleges/companies it will help to check if somebody is there in the zone or not.
If the data on display unit is zero the peons or security guards can shut the gate easily.
Conclusion
34
In our project We have designed and implemented a Automatic Room Light Controller With
Bi-Directional Visitor counter. This project helps us to control the light of a room
automatically and counts the number of persons/visitors entering and leaving the room. By
using this circuit and proper power supply we can implement various applications such as
fans, tube lights etc.
35
Bibliography
Reference Site:
1.www.google.co.in
2.www.wikipedia.com
3.www.cmcjaipur.com
4.www.electronicsforyou.com
5.www.encyclpedia.com
Reference Books:
36