Professional Documents
Culture Documents
This Project “Automatic Room Light Controller with Visitor Counter using
Microcontroller” is a reliable circuit that takes over the task of controlling the room lights
as well us 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 Receiver's then the IR Rays falling on the receivers are obstructed
this obstruction is sensed by the Microcontroller.
CONTENTS
CHAPTER 1: INTRODUCTION
1.3 Methodology
3.2 Characteristics:
3.3 Platform:
3.4 Tools:
3.6 Debugging:
3.8 Start-up:
4.3 DESCRIPTION
5.2 Description
CHAPTER6: IR SENSORS
CHAPTER11: REFERENCES
CHAPTER 1
INTRODUCTION
1.1 Aim of the project:
The main objective of this project is to make a controller based model to
count number of persons visiting particular room and accordingly light up
the room using IR sensors.
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 Receiver's then the IR Rays falling on the receiver
are obstructed, this obstruction is sensed by the Microcontroller.
1.3 Methodology:
According to our project requirements, the following modules are
essential.
Power supply
Microcontroller
IR sensors
Relay
CHAPTER 2
BLOCK DIAGRAM AND ITS DESCRIPTION
2.1 Basic Block Diagram:
The basic block diagram of the Automatic Room Light Controller with Visitor
Counter is shown in the above figure. Mainly this block diagram consists
of the following essential blocks.
1. Power Supply
2. AT89S52 micro-controller
3. Entry and Exit sensor circuit
4. Relay driver circuit
1. Power Supply:
Here we used +12V and +5V dc power supply. The main
function of this block is to provide the required amount of voltage to
essential circuits. +12 voltage is given. +12V is given to relay driver. To
get the +5V dc power supply we have used here IC 7805, which provides
the +5V dc regulated power supply.
2. 89S52 Microcontroller:
It is a low-power, high performance CMOS 8-bit
microcontroller with 8KB of Flash Programmable and Erasable Read Only
Memory (PEROM). The device is manufactured using Atmel’s high-
density nonvolatile memory technology and is compatible with the MCS-
51TM instruction set and pin out. The on-chip Flash allows 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 hip, the Atmel AT89S52 is a powerful microcontroller, which
provides a highly flexible and cost effective solution to so many embedded
control applications.
3. Enter and Exit Circuits:
This is one of the main part of our project. The main intention of this
block is to sense the person. By using this sensor and its related circuit diagram we can
count the persons.
3.2 Characteristics:
Two major areas of differences are cost and power
consumption. Since many embedded systems are produced in the tens of
thousands to millions of units range, reducing cost is a major concern.
Embedded systems often use a (relatively) slow processor and small
memory size to minimize costs.
The slowness is not just clock speed. The whole architecture of the
computer is often intentionally simplified to lower costs. For example,
embedded systems often use peripherals controlled by synchronous serial
interfaces, which are ten to hundreds of times slower than comparable
peripherals used in PCs.
Programs on an embedded system often must run with real-time
constraints with limited hardware resources: often there is no disk drive,
operating system, keyboard or screen.
A flash drive may replace rotating media, and a small keypad and LCD
screen may be used instead of a PC's keyboard and screen.
Firmware is the name for software that is embedded in hardware devices,
e.g. in one or more ROM/Flash memory IC chips.
Embedded systems are routinely expected to maintain 100% reliability
while running continuously for long periods, sometimes measured in
years. Firmware is usually developed and tested too much stricter
requirements than is general-purpose software, which can usually be easily
restarted if a problem occurs.
3.3 Platform:
There are many different CPU architectures used in embedded
designs. This in contrast to the desktop computer market, which as of this
writing (2003) is limited to just a few competing architectures, mainly the
Intel/AMD x86, and the Apple/Motorola/IBM PowerPC, used in the
Apple Macintosh.
One common configuration for embedded systems is the system on chip,
an application-specific integrated circuit, for which the CPU was
purchased as intellectual property to add to the IC's design.
3.4 Tools:
Like a typical computer programmer, embedded system designers use
compilers, assemblers and debuggers to develop an embedded system.
3.6 Debugging:
Debugging is usually performed with an in-circuit emulator,
or some type of debugger that can interrupt the micro controller’s internal
microcode.
The microcode interrupt lets the debugger operate in hardware in which
only the CPU works. The CPU-based debugger can be used to test and
debug the electronics of the computer from the viewpoint of the CPU.
This feature was pioneered on the PDP-11.
Developers should insist on debugging which shows the high-level
language, with breakpoints and single stepping, because these features are
widely available. Also, developers should write and use simple logging
facilities to debug sequences of real-time events.
PC or mainframe programmers first encountering this sort of
programming often become confused about design priorities and
acceptable methods. Mentoring, code-reviews and ego less programming
are recommended.
3.7 Design of embedded systems:
The electronics usually uses either a microprocessor or a micro
controller. Some large or old systems use general-purpose mainframes
computers or minicomputers.
3.8 Start-up:
All embedded systems have start-up code. Usually it disables
interrupts, sets up the electronics, tests the computer (RAM, CPU and
software), and then starts the application code. Many embedded systems
recover from short-term power failures by restarting (without recent self-
tests). Restart times under a tenth of a second are common.
Many designers have found one of more hardware plus software-
controlled LEDs useful to indicate errors during development (and in
some instances, after product release, to produce troubleshooting
diagnostics). A common scheme is to have the electronics turn off the
LED(s) at reset, whereupon the software turns it on at the first opportunity,
to prove that the hardware and start-up software have performed their job
so far. After that, the software blinks the LED(s) or sets up light patterns
during normal operation, to indicate program execution progress and/or
errors. This serves to reassure most technicians/engineers and some users.
4.3 DESCRIPTION:
This type of regulation is ideal for having a simple variable bench power supply. Actually
this is quite important because one of the first projects a hobbyist should undertake is the
construction of a variable regulated power supply. While a dedicated supply is quite
handy e.g. 5V or 12V, it's much handier to have a variable supply on hand, especially for
testing.
Most digital logic circuits and processors need a 5 volt power supply. To use these parts
we need to build a regulated 5 volt source. Usually you start with an unregulated power
supply ranging from 9 volts to 24 volts DC (A 12 volt power supply is included with the
Beginner Kit and the Microcontroller Beginner Kit.). To make a 5 volt power supply, we
use a LM7805 voltage regulator IC (Integrated Circuit). The IC is shown below.
The LM7805 is simple to use. You simply connect the positive lead of your unregulated
DC power supply (anything from 9VDC to 24VDC) to the Input pin, connect the
negative lead to the Common pin and then when you turn on the power, you get a 5 volt
supply from the Output pin.
Brief description of operation: Gives out well regulated +5V output, output
current capability of 100 mA
Circuit protection: Built-in overheating protection shuts down output when
regulator IC gets too hot
Circuit complexity: Very simple and easy to build
Circuit performance: Very stable +5V output voltage, reliable operation
Availability of components: Easy to get, uses only very common basic
components
Design testing: Based on datasheet example circuit, I have used this circuit
successfully as part of many electronics projects
Applications: Part of electronics devices, small laboratory power supply
Power supply voltage: Unregulated DC 8-18V power supply
Power supply current: Needed output current + 5 mA
Component costs: Few dollars for the electronics components + the input
transformer cost
The input to the circuit is applied from the regulated power supply. The a.c. input
i.e., 230V from the mains supply is step down by the transformer to 12V and is
fed to a rectifier. The output obtained from the rectifier is a pulsating d.c voltage.
So in order to get a pure d.c voltage, the output voltage from the rectifier is fed to
a filter to remove any a.c components present even after rectification. Now, this
voltage is given to a voltage regulator to obtain a pure constant dc voltage.
4.5.1Transformer:
4.5.3Filter:
4.5.4Voltage regulator:
As the name itself implies, it regulates the input applied to it. A voltage
regulator is an electrical regulator designed to automatically maintain a constant
voltage level. In this project, power supply of 5V and 12V are required. In order
to obtain these voltage levels, 7805 and 7812 voltage regulators are to be used.
The first number 78 represents positive supply and the numbers 05, 12 represent
the required output voltage levels.
CHAPTER 5
89S52 MICROCONTROLLER
5.1 Features:
• 8K Bytes of In-System Reprogrammable Flash Memory
• Endurance: 1,000 Write/Erase Cycles
• Fully Static Operation: 0 Hz to 24 MHz
• 256 x 8-bit Internal RAM
• 32 Programmable I/O Lines
• Three 16-bit Timer/Counters
• Eight Interrupt Sources
• Programmable Serial Channel
• Low-power Idle and Power-down Modes
5.2 Description:
The AT89C52 is a low-power, high-performance CMOS 8-
bit microcomputer with 8Kbytes of Flash programmable and erasable read
only memory (PEROM). The on-chip Flash allows 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 AT89C52 is a powerful microcomputer, which
provides a highly flexible and cost-effective solution to many embedded
control applications.
5.3 Pin Diagram - AT89S52:
GND - Ground.
Port 0
Port 0 is an 8-bit open drain bi-directional 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 can 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 bi-directional I/O port with internal pull-
ups. The Port 1 output 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 (I IL)
because of the internal pull-ups. In addition, P1.0 and P1.1 can be
configured to be the timer/counter 2 external count input (P1.0/T2)
and the timer/counter 2 trigger input (P1.1/T2EX), respectively.
Port 2
Port 2 is an 8-bit bi-directional 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 (I IL )
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, Port 2 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 bi-directional 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 (I IL )
because of the pull ups. Port 3 also serves the functions of various
special features of the AT89C51. 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 is an 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. 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 AT89C52 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 pro-gram
memory locations starting at 0000H up to FFFFH. 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 12V programming enable voltage (VPP)
during Flash programming when 12V programming is selected.
XTAL1:
Input to the inverting oscillator amplifier and input to the
internal clock operating circuit.
XTAL2:
Output from the inverting oscillator amplifier
5.5 ARCHITECHTURE OF 8052 MICROCONTROLLER:
Fig. 5.2 ARCHITECHTURE OF 8052 MICROCONTROLLER
6.3 Modulation :
Modulation is the answer to make our signal stand out above the
noise. With modulation we make the IR light source blink in a particular
frequency. The IR receiver will be tuned to that frequency, so it can ignore
everything.
Fig. 6.1 Modulation
In the picture above you can see a modulated signal driving the IR LED of
the transmitter on the left side. The detected signal is coming out of the
receiver at the other side.
In serial communication we usually speak of 'marks' and 'spaces'. The
'space' is the default signal, which is the off state in the transmitter case.
No light is emitted during the 'space' state. During the 'mark' state of the
signal the IR light is pulsed on and off at a particular frequency.
Frequencies between 30 kHz and 60 kHz are commonly used in consumer
electronics. At the receiver side a 'space' is represented by a high level of
the receiver's output. A 'mark' is then automatically represented by a low
level.
Please note that the 'marks' and 'spaces' are not the 1-s and 0-s we want to
transmit. The real relationship between the 'marks' and 'spaces' and the 1-s
and 0-s depends on the protocol that's being used. More information about
that can be found on the pages that describe the protocols.
In the picture above you can see a typical block diagram of such an IR
receiver. Don't be alarmed if you don't understand this part of the
description, for everything is built into one single electronic component.
The received IR signal is picked up by the IR detection diode on the left
side of the diagram. This signal is amplified and limited by the first 2
stages. The limiter acts as an AGC circuit to get a constant pulse level,
regardless of the distance to the handset. As you can see only the AC
signal is sent to the Band Pass Filter. The Band Pass Filter is tuned to the
modulation frequency of the handset unit. Common frequencies range
from 30 kHz to 60 kHz in consumer electronics. The next stages are a
detector, integrator and comparator. The purpose of these three blocks is
to detect the presence of the modulation frequency. If this modulation
frequency is present the output of the comparator will be pulled low. As I
said before, all these blocks are integrated into a single electronic
component. There are many different manufacturers of these components
on the market. And most devices are available in several versions each of
which are tuned to a particular modulation frequency.
Please note that the amplifier is set to a very high gain. Therefore the
system tends to start oscillating very easily. Placing a large capacitor of at
least 22µF close to the receiver's power connections is mandatory to
decouple the power lines. Some data sheets recommend a resistor of 330
Ohms in series with the power supply to further decouple the power
supply from the rest of the circuit.
There are several manufacturers of IR receivers on the market. Siemens,
Vishay and Telefunken are the main suppliers here in Europe. Siemens has
its SFH506-xx series, where xx denotes the modulation frequency of 30,
33, 36, 38, 40 or 56 kHz. Telefunken had its TFMS5xx0 and TK18xx
series, where xx again indicates the modulation frequency the device is
tuned to. It appears that these parts have now become obsolete. They are
replaced by the Vishay TSOP12xx, TSOP48xx and TSOP62xx product
series. Sharp, Xiamen Hualian and Japanese Electric are 3 Asian IR
receiver producing companies. Sharp has devices with very cryptic ID
names, like: GP1UD26xK, GP1UD27xK and GP1UD28xK, where x is
related to the modulation frequency. Hualian has it's HRMxx00 series, like
the HRM3700 and HRM3800. Japanese Electric has a series of devices
that don't include the modulation frequency in the part's ID. The PIC-
12042LM is tuned to 36.7 kHz, and the PIC12043LM is tuned to 37.9 kHz
IR Advantages:
Low power requirements: therefore ideal for laptops, telephones, personal digital
assistants
Low circuitry costs: $2-$5 for the entire coding/decoding circuitry
Simple circuitry: no special or proprietary hardware is required, can be
incorporated into the integrated circuit of a product
Higher security: directionality of the beam helps ensure that data isn't leaked or
spilled to nearby devices as it's transmitted
Portable
Few international regulatory constraints: IrDA (Infrared Data Association)
functional devices will ideally be usable by international travelers, no matter
where they may be
High noise immunity: not as likely to have interference from signals from other
devices
IR Disadvantages:
Line of sight: transmitters and receivers must be almost directly aligned (i.e. able
to see each other) to communicate
Blocked by common materials: people, walls, plants, etc. can block transmission
Short range: performance drops off with longer distances
Light, weather sensitive: direct sunlight, rain, fog, dust, pollution can affect
transmission
Speed: data rate transmission is lower than typical wired transmission
CHAPTER 7
RELAY DRIVER CIRCUIT
RELAY CIRCUIT:
A single pole dabble throw (SPDT) relay is connected to port RB1 of the
microcontroller through a driver transistor. The relay requires 12 volts at a
current of around 100ma, which cannot provide by the microcontroller. So
the driver transistor is added. The relay is used to operate the external
solenoid forming part of a locking device or for operating any other
electrical devices. Normally the relay remains off. As soon as pin of the
microcontroller goes high, the relay operates. When the relay operates and
releases. Diode D2 is the standard diode on a mechanical relay to prevent
back EMF from damaging Q3 when the relay releases. LED L2 indicates
relay on.
CHAPTER 8
SOURCE CODE
#include
#include
#define LCD_clear() LCD_command(0×01) /* Clear LCD Display
#define LCD_orgin()LCD_command(0×02) /* set to orgin LCD
#define LCD_row1() LCD_command(0×80) /* Begin at 1st line
#define LCD_row2()LCD_command(0xc0) /* Begin at 2nd line
sbit port10=P1^0; //IR Sensor Input
sbit rs=P3^6; //Lcd Register Select Pin
sbit en=P3^7; //Lcd Enable Pin
static unsigned char counter;
void lcd_en() //Funtion for LCD Enable
{
en=1;
en=0;
}
void LCD_delay(unsigned char ms) //Function for create Time Delay
{
unsigned int n,i;
for(n=0;n<ms;n++)
{
for(i=0;i<1536;i++);
}
}</ms;n++)
void LCD_command(unsinged char command) //LCD Command Pass Funtion
{
rs=0;
P0=command;
lcd_en();
LCD_delay(1);
}
void LCD_init() //LCD intialization funtion
{
LCD_command(0x38);
LCD_command(0x06);
LCD_command(0x0c);
LCD_command(0x01);
}
void LCD_putc(unasigned char ascii)
{
rs=1;
P0=ascii;
lcd_en();
LCD_delay(2);
}
void LCD_puts(unsigned char *lcd_string)
{
while(*lcd_string)
{
LCD_putc(*lcd_string++);
}
}
void disp(unsinged char name1)
{
rs=1;
P0=name1;
lcd_en();
lcd_delay(300);
}
void main()
{
port10=0; //make P1.0 as init=0, initially all port pins are high
P2=0; //make low for P2
LCD_init(); //call LCD initialization function
while(1) //Run forever always true
{
if(port10) //check condition P2.0 is high P2.0==1
{
LCD_command(0x80); //LCD command for display first line
LCD_puts("visit count="); //String display in the LCD
{
disp(((counter%10000)/1000)+48);
disp(((counter%1000)/100)+48);
disp(((counter%100)/10)+48);
disp(((counter%10)/1)+48);
}
}
P2=counter; // 8 LED's conneted in PORT 2
LCD_comman(0xc0) //LCD command for display 2nd line
}
}
CHAPTER 9
FUTURE EXPANSION
By using this circuit and proper power supply we can implement various
applications
Such as fans, tube lights, etc.
By modifying this circuit and using two relays we can achieve a task of
opening and closing the door.
CHAPTER 10
APPLICATIONS, ADVANTAGES & DISADVANTAGES
Applications
For counting purposes
For automatic room light control
Advantages
Low cost
Easy to use
Disadvantages
It is used only when one single person cuts the rays of the sensor hence
it cannot be used when two person cross simultaneously.
CHAPTER 11
REFERENCES
1. Embedded Systems - Raj Kamal
2. www.wikipedia.com
4. http://www.embed4u.com