Sunteți pe pagina 1din 55

PROJECT REPORT ON

VISITOR COUNTER & AUTOMATIC LOAD CONTROLLER

Submitted in partial fulfillment of the requirements

For the award of the degree

BACHELOR OF ENGINEERING

IN

____________________________________ ENGINEERING

SUBMITTED BY

-------------------- (--------------)

--------------------- (---------------)

--------------------- (---------------)

DEPARTMENT OF _______________________ ENGINEERING

__________COLLEGE OF ENGINEERING

AFFILIATED TO ___________ UNIVERSITY

1
CERTIFICATE

This is to certify that the dissertation work entitled VISITOR COUNTER &
AUTOMATIC LOAD CONTROLLER is the work done by
_______________________________________________submitted in partial
fulfillment for the award of BACHELOR OF ENGINEERING (B.E)in
__________________________Engineering from______________ College of
Engineering affiliated to _________ University , Hyderabad .

________________ ____________
(Head of the department, ECE) (Assistant Professor)

EXTERNAL EXAMINER

2
ACKNOWLEDGEMENT

The satisfaction and euphoria that accompany the successful completion of any
task would be incomplete without the mentioning of the people whose constant
guidance and encouragement made it possible. We take pleasure in presenting
before you, our project, which is result of studied blend of both research and
knowledge.

We express our earnest gratitude to our internal guide, Assistant Professor


______________, Department of ECE, our project guide, for his constant support,
encouragement and guidance. We are grateful for his cooperation and his valuable
suggestions.

Finally, we express our gratitude to all other members who are involved either
directly or indirectly for the completion of this project.

3
DECLARATION

We, the undersigned, declare that the project entitled VISITOR COUNTER &
AUTOMATIC LOAD CONTROLLER, being submitted in partial fulfillment for the
award of Bachelor of Engineering Degree in Electronics and Communication
Engineering, affiliated to _________ University, is the work carried out by us.

__________ _________ _________

__________ _________ _________

4
VISITOR COUNTER AND ROOM LIGHT CONTROLLER

INDEX
Contents Page No.

Abstract.....

Introduction to Embedded systems

Microcontroller AT89S52.......................

Hardware Description.

Coding......

Software Description

Conclusion.

References.

5
VISITOR COUNTER AND ROOM LIGHT CONTROLLER

ABSTRACT

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 16*2
LCD. 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.

6
SOFTWARE

1) Keil Compiler.
2) EMBEDDED C CODE
3) ucFlash

HARDWARE TOOLS:

1) Microcontroller 89S52
2) Regulated Power Supply 5V.
3) 89S52 Microcontroller
4) BT136 Triac
5) MOC3021 Opto-Coupler IC
6) IR LED AND PHOTODIODE PAIR
7) 16*2 LCD DISPLAY

7
Block Diagram:

16*2 LCD
Micro- Display

IR controller
Sensors
AT89S52 MOC3021 BT136 TRIAC AC LAMPS
DRIVER
OPTO-COUPLER

8
EMBEDDED SYSEMS

Embedded systems have grown tremendously in recent years, not only in their popularity
but also in their complexity. Gadgets are increasingly becoming intelligent and autonomous.
Refrigerators, air-conditioners, automobiles, mobile phones etc are some of the common
examples of devices with built in intelligence. These devices function based on operating and
environmental parameters.

The intelligence of smart devices resides in embedded systems. An embedded system, in


general, in co-operates hardware, operating systems, low-level software binding the operating
system and peripheral devices, and communication software to enable the device to perform the
pre-defined functions. An embedded system performs a single, well-defined task, is tightly
constrained, is reactive and computes results in real time.

Let us take a detailed look at these features of embedded systems:

Single functioned: An embedded system executes a specific program repeatedly.


For example, a pager is always a pager. In contrast a desktop system executes a variety of
programs like spreadsheets, word processors, etc. However there are exceptions where in an
embedded systems program is updated with newer program versions. Cell phones are examples
of being updated in such a manner.
Tightly constrained: All computing systems have constraints on design metrics but
those on embedded systems can be especially tight. A design metric is a measure of an
implementations features, such as cost, size performance and power.
Reactive and real time: Many embedded systems must continually react to changes
in the systems environment and must compute certain results in real time without delay.

9
Embedded Hardware
All embedded systems need a microprocessor, and the kinds of microprocessors used in
them are quite varied. A list of some of the common microprocessor families is the ZILOG Z8
family, Intel 805/80188/x 86 families, Motorola 68k family and the PowerPC family.

Embedded Software
The software for the embedded systems is called firmware. The firmware will be written
in assembly languages for time or resource critical operations or using higher-level languages
like C or embedded C. The software will be simulated using micro code simulators for the target
processor. Since they are supposed to perform only specific tasks these programs are stored in
Read Only Memories (ROMs).

Application areas for embedded systems


Embedded software is present in almost every electronic device you use today. There is
embedded software inside your watch, cellular phone, automobile, thermostats, Industrial control
equipment and scientific and medical equipment. Defence services use embedded software to
guide missiles and detect aircrafts. Communication satellites, medical instruments and deep
space probes would have been nearly impossible without these systems. Embedded systems
cover such as broad range of products that generalization is difficult.

Here are some broad categories.

Aerospace and Defense Electronics (ADE)


Consumer/Internet applications
Data Communications
Digital imaging
Medical electronic Mobile data infrastructures

10
Block diagram of Embedded System:

Embedded

System

Software Hardware

ALP Processor
C Peripherals
VB memory
Etc.,

Figure 1.1: Embedded System Block Diagram

Software deals with the languages like ALP, C, and VB etc., and Hardware deals with
Processors, Peripherals, and Memory.

Memory: It is used to store data or address.


Peripherals: These are the external devices connected
Processor: It is an IC which is used to perform some task
Processors are classified into four types like:
1. Micro Processor (p)
2. Micro controller (c)
3. Digital Signal Processor (DSP)
4. Application Specific Integrated Circuits (ASIC)

11
MICROCONTROLLER

Basically, a microcontroller is a device which integrates a number of the components of a


microprocessor system onto a single microchip. So a microcontroller combines onto the same
microchip. The following components:

CPU Core
Memory (Both RAM and ROM)
Some Parallel Digital I/Os
The microprocessor is the integration of a number of useful functions into a single IC
package. Has the ability to execute a stored set of instructions to carry out user defined tasks;
also has ability to access external memory chips to both read and write data from and to the
memory.

Essentially, a microcontroller is obtained by integrating the key components of


microprocessor, RAM, ROM, and Digital I/O onto the same chip die. Modern microcontrollers
also contain a wealth of other modules such as Serial I/O, Timers, and Analogue to Digital
Converters. There are a large number of specialized devices with additional modules for specific
needs. E.g. CAN controllers.

12
MICROCONTOLLER (AT89S52)

FEATURES

Compatible with MCS-51Products

8K Bytes of In-System Programmable (ISP) Flash Memory

4.0V to 5.5V Operating Range

Fully Static Operation: 0 Hz to 33 MHz

256Bytes Internal RAM

32 Programmable I/O Lines

3 16-bit Timer/Counters

Full Duplex UART Serial Channel

DESCRIPTION OF MICROCONTROLLER AT 89S52:

13
The AT89S52 is a low-power, high-performance CMOS 8-bit micro controller with 8Kbytes
of in-system programmable Flash memory. The device is manufactured

Using Atmels high-density non-volatile memory technology and is compatible with


the industry-standard 80C51 micro controller. The on-chip Flash allows the program memory to
be reprogrammed in-system or by a conventional non-volatile memory programmer. By
combining a versatile 8-bit CPU with in-system programmable flash one monolithic chip; the
Atmel AT89S52 is a powerful micro controller, which provides a highly flexible and cost-
effective solution to many embedded control applications.

14
The AT89S52 provides the following standard features: 8K bytes of Flash, 256 bytes of
RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit timer/counters, full
duplex serial port, on-chip oscillator, and clock circuitry. In addition, the AT89S52 is
designed with static logic for perationdown to zero frequency and supports two software
selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM
timer/counters, serial port, and interrupt system to continue functioning. The Power-down
mode saves the RAM contents but freezes the oscillator, disabling all other chip functions
until the next interrupt or hardware reset.

PIN DESCRIPTION OF MICROCONTROLLER AT89S52


15
VCC

Supply voltage.

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 1sare 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. 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, as shown in


the following table. Port 1 also receives the low-order address bytes during Flash programming .

16
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. Port 2 emits the high-order address
byte during fetches from external program memory and during accesses to external data
memory that uses 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 2emits 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 (IIL) because of the pull-ups. Port 3 also serves the functions of various
special features of the AT89S52, as shown in the following table.

Port 3 also receives some control signals for Flash programming and verification.

17
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 (ALE) 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 of1/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 micro controller is in external execution mode.

PSEN

Program Store Enable (PSEN) is the read strobe to external program memory. When the
AT89S52 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. A should be
strapped to VCC for internal program executions. This pin also receives the 12-
voltProgramming enables voltage (VPP) during Flash programming.

18
XTAL1

Input to the inverting oscillator amplifier and input to the internal clock operating circuit.

XTAL2

Output from the inverting oscillator amplifier.

Oscillator Characteristics

XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier
that can be configured for use as an on-chip oscillator, as shown in Figure 1. Either a
quartz crystal or ceramic resonator may be used. To drive the device from an
External clock source, XTAL2 should be left unconnected while XTAL1 is driven, as
shown in Figure 2.

Circuit Description:
19
The circuit shows the microcontroller based bidirectional visitor counter,
wherein the transmitter and the receiver form the IR detection circuit. Control logic
is built around transistors, operational amplifier LM393 (IC)

The IR transmitter-receiver setup at the entrance-cum-exit of the passage is


shown at the block diagram. Two similar sections detect interruption of the IR beam
and generate clock pulse for the microcontroller. The microcontroller controls
counting and displays the number of persons present inside the hall. When nobody is
passing through the entry/exit point, the IR beam continuously falls on
phototransistor T1. When infrared beam is interrupted, comparator output becomes
low which is given to microcontroller. If someone interrupts the first the IR beam,
counter increases and similarly when second infrared beam is interrupted counter
decreases.

The AT89C52 us an 8-bit microcontroller with 8 kb of flash based program


memory, 256 bytes of RAM, 32 input/output lines, three 16 bits timers/counters, on-
chip oscillator and clock circuitry. A 12MHz crystal is used fro providing clock.
Four Digit 7-Segment Display is interfaced with the microcontroller

20
Hardware Description

Power supply description:


As the microcontroller operating voltage is +5V DC. Through this power supply circuit
we have to create a +5V DC which is given to the micro controller. The below components are
used to create the power supply

Filter
230V AC Step down Bridge Regulator
supply transformer rectifier
Block Diagram of
Power Supply

Description:

230V AC supply is given to the step down transformer of 12A type. It may be a 230V to
9V or 12V step down transformer. The output of the step down transformer is given to bridge
rectifier. The bridge rectifier is formed with 1N4007 diodes. The bridge rectifier converts the AC
Voltage into DC Voltage. But the output DC Voltage contains some AC component (ripples). So
we use a capacitors-2200uF/25V, 0.1uF/D and resistor of 10K as a filter for removing ripples.
That output DC Voltage is given to the positive voltage regulator LM7805 (i.e., 78 represents the
positive series and 5 represent the output voltage it can provide). So the output of the regulator
will be the regulated +5V DC. To indicate the condition of the circuit we place a LED at the end
of the circuit.

Schematic of Power Supply

21
Voltage Regulators

Voltage regulators comprise a class of widely used ICs. Regulator IC units contain the
circuitry for reference source, comparator amplifier, control device, and overload protection all
in a single IC. IC units provide regulation of either a fixed positive voltage, a fixed negative
voltage, or an adjustably set voltage. A fixed three-terminal voltage regulator has an unregulated
dc input voltage, Vi, applied to one input terminal, a regulated dc output voltage, Vo, from a
second terminal, with the third terminal connected to ground.

The series 78 regulators provide fixed positive regulated voltages from 5 to 24 volts.
Similarly, the series 79 regulators provide fixed negative regulated voltages from 5 to 24 volts.

IC Voltage Regulators

Voltage regulator ICs are available with fixed (typically 5, 12 and 15V) or variable output
voltages. They are also rated by the maximum current they can pass. Negative voltage regulators
are available, mainly for use in dual supplies. Most regulators include some automatic protection
from excessive current ('overload protection') and overheating ('thermal protection').

Many of the fixed voltage regulator ICs has 3 leads and look like power transistors,

LIQUID CRYSTAL DISPLAY


22
Basic LCD Interfacing Circuit

Pin Configuration:

Pin Configuration of 16X2 LCD

23
VCC, VSS and VEE:

While VCC and VSS provide +5V and ground respectively, VEE is used for controlling

LCD contrast.

RS (REGISTER SELECT):

There are two important registers inside the LCD. When RS is low (0), the data is to be treated
as a command or special instruction (such as clear screen, position cursor, etc.). When RS is high
(1), the data that is sent is a text data which should be displayed on the screen. For example, to
display the letter "T" on the screen you would set RS high.

RW (READ/WRITE):

The RW line is the "Read/Write" control line. When RW is low (0), the information on the data
bus is being written to the LCD. When RW is high (1), the program is effectively querying (or
reading) the LCD. Only one instruction ("Get LCD status") is a read command. All others are
write commands, so RW will almost be low.

EN (ENABLE):

The EN line is called "Enable". This control line is used to tell the LCD that you are sending it
data. To send data to the LCD, your program should first set this line high (1) and then set the
other two control lines and/or put data on the data bus. When the other lines are completely
ready, bring EN low (0) again. The 1-0 transition tells the 44780 to take the data currently found
on the other control lines and on the data bus and to treat it as a command.

D0-D7 (DATA LINES):

The 8-bit data pins, D0-D7 are used to send information to the LCD or read the content of the
LCDs internal registers.

To display letters and numbers, we send ASCII codes for the letters A-Z, a-z and numbers 0-9 to
these pins while making RS=1.

24
There are also instruction command codes that can be sent to the LCD to clear the display or
force the cursor to the home position or blink the cursor.

We also use RS=0 to check the busy flag bit to see if the LCD is ready to receive the information.
The busy flag is D7 and can be read when R/W = 1 and RS=0, as follows: if R/W = 1, RS = 0.
When D7=1 (busy flag = 1), the LCD is busy taking care of internal operations and will not
accept any new information. When D7 = 0, the LCD is ready to receive new information.

LCD COMMAND CODES:

CODE (HEX) COMMAND TO LCD INSTRUCTION REGISTER

0X01 CLEAR DISPLAY SCREEN

0X02 RETURN HOME

0X04 DECREMENT CURSOR(SHIFT CURSOR TO LEFT)

0X06 INCREMENT CURSOR(SHIFT CURSOR TO RIGHT)

0X05 SHIFT DISPLAY RIGHT

0X07 SHIFT DISPLAY LEFT

0X08 DISPLAY OFF,CURSOR OFF

0X0A DISPLAY OFF,CURSOR ON

0X0C DISPLAY ON,CURSOR OFF

0X0E DISPLAY ON CURSOR BLINKING

0X0F DISPLAY ON CURSOR BLINKING

0X10 SHIFT CURSOR POSITION TO LEFT

0X14 SHIFT CURSOR POSITION TO RIGHT

0X18 SHIFT THE ENTIRE DISPLAY TO THE LEFT

0X1C SHIFT THE ENTIRE DISPLAY TO THE RIGHT

0X80 FORCE CURSOR TO BEGINNING OF 1ST LINE

0XC0 FORCE CURSOR TO BEGINNING OF 2ND LINE

25
0X38 8-BIT INTERFACE, 2 LINES, 5*7 PIXELS

0X30 8-BIT INTERFACE, 1 LINE, 5*7 PIXELS

0X28 4-BIT INTERFACE, 2 LINES, 5*7 PIXELS

0X20 4-BIT INTERFACE, 1 LINE, 5*7 PIXELS

CURSOR ADDRESSES FOR LCDS: 16x2 LCD

First Row 80 81 82 83 84 85 8 8F

Second Row C0 C1 C2 C3 C4 C5 C6 CF

I. Sensors

Here a pair of IR transmitter receiver is used as sensor. Photo transistors are used as IR receiver, since
it has sensitivity to receive IR rays.

IR Transmitter:

Infrared (IR) radiation is electromagnetic radiation of a wavelength longer than that of visible
light, but shorter than that of microwaves. Objects generally emit infrared radiation across a spectrum of

26
wavelengths, but only a specific region of the spectrum is of interest because sensors are usually designed
only to collect radiation within a specific bandwidth.

Remote controls and IrDA devices use infrared light-emitting diodes (LEDs) to emit infrared
radiation which is focused by a plastic lens into a narrow beam. The receiver uses a silicon photodiode to
convert the infrared radiation to an electric current. It responds only to the rapidly pulsing signal created
by the transmitter, and filters out slowly changing infrared radiation from ambient light. IR does not
penetrate walls and so does not interfere with other devices in adjoining rooms.

Photo-transistors:

Phototransistors are examples of photodiode-amplifier combinations integrated within a single


silicon ship. These combinations are put together in order to overcome the major fault of photodiodes:
unity gain. Many applications demand a greater output signal from photodiode can always be amplified
through use of an external op-amp or other circuitry, this approach is often not as practical or as cost
effective as the use of phototransistors.

The phototransistor can be viewed as a photodiode whose output photocurrent is fed into the base
of a conventional small signal transistor. While not required for operation of the device as a photo
detector, a base connection is often provided allowing the designer the option of using base current to bias
the transistor.

Basics of IR transmitter

Infra red transmitter emits IR rays in planar wave front manner.


Even though infra red rays spread in all directions, it propagates along straight line in forward direction.
IR rays have the characteristics of producing secondary wavelets when it collides with any obstacles in its
path. This property of IR is discussed here.

27
.

Fig 5.8 IR Transmitter Circuit

When IR rays gets emitted from LED, it moves in the direction it is angled. When any
obstacle interferes in the path, the IR rays get cut and it produces secondary wavelets which propagates
mostly in return direction or in a direction opposite to that of the primary waves, which produces the net
result like reflection of IR rays.

Basics of IR receiver:

Infrared photo receiver is a two terminal PN junction device, which operates in a reverse bias. It
has a small transparent window, which allows light to strike the PN junction. A photodiode is a type of
photo detector capable of converting light into either current or voltage, depending upon the mode of
operation. Most photodiodes will look similar to a light emitting diode. They will have two leads, or
wires, coming from the bottom.
28
Infrared Detectors Basics

IR Detector Specifications

An infrared emitter is an LED made from gallium arsenide, which emits near-infrared energy at
about 880nm.

The infrared phototransistor acts as a transistor with the base voltage determined by the amount
of light hitting the transistor. Hence it acts as a variable current source. Greater amount of IR
light cause greater current to flow through the collector-emitter leads. As shown in the diagram
below, the phototransistor is wired in a similar configuration to the voltage divider. The variable
current traveling through the resistor causes a voltage drop in the pull-up resistor.

29
IR Pair Circuit

Symbol and typical view of photo-transistor:

30
Features:

Low-cost visible and near-IR photo detector.

Available with gains from 100 to over 1500.

Moderately fast response times.

Available in a wide range of packages including epoxy-coated, transfer-molded,


cast, hermetic, and in chip form.

Usable with almost any visible or near-infrared light source such as IREDs; neon;
fluorescent, incandescent bulbs; lasers; flame sources; sunlight; etc.

Same general electrical characteristics as familiar signal transistors.

31
MOC3021

1. Introduction:
Opto-isolators, or Opto-couplers, are made up of a light emitting device, and a light
sensitive device, all wrapped up in one package, but with no electrical connection between the
two, just a beam of light. The light emitter is nearly always an LED. The light sensitive device
may be a photodiode, phototransistor, or more esoteric devices such as thyristors, triacs e.t.c.

2. Opto-isolator parameters

Collector-emitter voltage
This is the maximum voltage that can be present from the collector to the emitter of the
receiving phototransistor (when it is turned off no light) before it may break-down.
Cree page distance
This is physically how far a spark would have to travel around the outside of the package
to get from one side to the other. If the package has contaminants on it, solder flux, or dampness,
then a lower-resistance path can be created for noise signals to travel along.

Forward current
This is the current passing through the sending LED. Typically, an Opto-isolator will
require about 5Ma to turn the output transistor on.

Forward voltage
This is the voltage that is dropped across the LED when it is turned on. Most normal
diodes drop about 0.7v, but with LEDs it is typically 1 2 volts.

Collector dark current


This is the current that can flow through the output phototransistor when it is turned off.

32
Collector-emitter saturation voltage
When the output transistor is fully turned on (saturated), this is the voltage there will be
between the collector and emitter.

Isolation resistance
This is the resistance from a pin in the input side to a pin on the output side. It should be
very high.
Response time
The rise and fall times are the times that the output voltage takes to get from zero to
maximum. The rise time is very much dependant on the load resistor, since it is this that is
pulling the output up. Therefore this value is always quoted with a fixed load resistance. Note
however that the value, 100 Ohms, is much less than you are likely to use in practice. This is
another of the manufacturers attempts to make the product look better than it is!

Cutoff frequency
This is effectively the highest frequency of square wave that can be sent through the
Opto-isolator. It is actually the frequency at which the output voltage is only swinging half the
amplitude than at DC levels (-3Db = half). It is therefore linked with the rise and fall times.

Current Transfer Ratio (CTR)


This is the ratio of how much collector current in the output transistor that you get given
a certain amount of forward current in the input side LED. It is affected by how close the LED
and phototransistor are inside the device, how efficient they both are, and many other factors. In
fact it is not a constant but varies wildly with LED forward current.

33
TRIAC
TRIAC, from Triode for Alternating Current, is a generalized trade name for an electronic
component which can conduct current in either direction when it is triggered (turned on), and is
formally called a bidirectional triode thyristor or bilateral triode thyristor.
A TRIAC is approximately equivalent to two complementary unilateral thyristors (one is
anode triggered and another is cathode triggered SCR) joined in inverse parallel (paralleled but
with the polarity reversed) and with their gates connected together. It can be triggered by either a
positive or a negative voltage being applied to its gate electrode (with respect to A1, otherwise
known as MT1). Once triggered, the device continues to conduct until the current through it
drops below a certain threshold value, the holding current, such as at the end of a half-cycle of
alternating current (AC) mains power. This makes the TRIAC a very convenient switch for AC
circuits, allowing the control of very large power flows with milliampere-scale control currents.
In addition, applying a trigger pulse at a controllable point in an AC cycle allows one to control
the percentage of current that flows through the TRIAC to the load (phase control).

Application

Low power TRIACs are used in many applications such as light dimmers, speed controls
for electric fans and other electric motors, and in the modern computerized control circuits of
many household small and major appliances.
However, when used with inductive loads such as electric fans, care must be taken to
assure that the TRIAC will turn off correctly at the end of each half-cycle of the AC power.
A snubber circuit (usually of the RC type) is often used between A1 and A2 to assist this turn-off.
Snubber circuits are also used to prevent premature triggering, caused for example by voltage
spikes in the mains supply. Also, a gate resistor or capacitor (or both in parallel) may be
connected between gate and A1 to further prevent false triggering. That, however, increases the
required trigger current and / or adds latency (capacitor charging).

For higher-powered, more-demanding loads, two SCRs in inverse parallel may be used
instead of one TRIAC. Because each SCR will have an entire half-cycle of reverse polarity

34
voltage applied to it, turn-off of the SCRs is assured, no matter what the character of the load.
However, due to the separate gates, proper triggering of the SCRs is more complex than
triggering a TRIAC.

In addition to commutation, a TRIAC may also not turn on reliably with non-resistive
loads if the phase shift of the current prevents achieving holding current at trigger time. To
overcome that, pulse trains may be used to repeatedly try to trigger the TRIAC until it finally
turns on. The advantage is that the gate current does not need to be maintained throughout the
entire conduction angle, which can be beneficial when there is only limited drive capability
available.

35
CODING :

#include<reg51.h>

#include<string.h>

#define LCD_clear() LCD_command(0x01) // Clear LCD Display

#define LCD_orgin()LCD_command(0x02) // set to orgin LCD

#define LCD_row1() LCD_command(0x80) // Begin at 1st line

#define LCD_row2()LCD_command(0xc0) // Begin at 2nd line

void LCD_command(unsigned char command);

void lcd_delay(unsigned char ms);

void LCD_puts(unsigned char *lcd_string);


36
void disp(unsigned char name1);

sbit sensor1=P1^0; //IR Sensor Input increament

sbit sensor2=P1^1; //IR Sensor Input decreament

sbit rs=P0^0; //Lcd Register Select Pin

sbit en=P0^2; //Lcd Enable Pin

sbit RELAY1=P0^3; //OUTPUT LOAD

sbit RELAY2=P0^4; //OUTPUT LOAD

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++)

37
{

for(i=0;i<200;i++);

void LCD_command(unsigned char command) //LCD Command Pass Funtion

rs=0;

P2=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(unsigned char ascii)

rs=1;

38
P2=ascii;

lcd_en();

LCD_delay(2);

void LCD_puts(unsigned char *lcd_string)

while(*lcd_string)

LCD_putc(*lcd_string++);

void disp(unsigned char name1)

rs=1;

P2=name1;

lcd_en();

lcd_delay(100);

void main()

RELAY1=1; //INITIALLY LOW OUTPUT

39
RELAY2=1;

LCD_init(); //call LCD initialization function

LCD_command(0x80); //LCD command for display first line

LCD_puts("VISITOR COUNTER"); //String display in the LCD

while(1) //Run forever always true

if(sensor1==0)

counter++;

LCD_command(0xC0); //LCD command for display first line

LCD_puts("COUNTS:"); //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);

if(counter>=1 && counter<=10) //limit exceeds condition

40
RELAY1=0;

LCD_command(0xC0);

// LCD_puts("LIGHTS ON"); //String display in the LCD

if(counter>10) //limit exceeds condition

RELAY1=0;

RELAY2=0;

LCD_command(0xC0);

// LCD_puts("LIGHTS ON"); //String display in the LCD

if(counter==0) //limit exceeds condition

RELAY1=1;

RELAY2=1;

LCD_command(0xC0);

// LCD_puts("LIGHTS ON"); //String display in the LCD

41
if(sensor2==0)

counter--;

LCD_command(0xC0); //LCD command for display first line

LCD_puts("COUNTS:"); //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);

if(counter>0 && counter<=10) //limit exceeds condition

RELAY1=0;

LCD_command(0xC0);

// LCD_puts("LIGHTS ON"); //String display in the LCD

42
if(counter>10) //limit exceeds condition

RELAY1=0;

RELAY2=0;

LCD_command(0xC0);

// LCD_puts("LIGHTS ON"); //String display in the LCD

if(counter>0 && counter<=10) //limit exceeds condition

RELAY1=0;

RELAY2=1;

LCD_command(0xC0);

// LCD_puts("LIGHTS ON"); //String display in the LCD

if(counter==0) //limit exceeds condition

RELAY1=1;

RELAY2=1;

LCD_command(0xC0);

43
// LCD_puts("LIGHTS ON"); //String display in the LCD

Software Description

KEIL uVision is a standard Windows application.

KEIL SOFTWARE:

Keil compiler is a software used where the machine language code is written and
compiled. After compilation, the machine source code is converted into hex code which is to be
dumped into the microcontroller for further processing. Keil compiler also supports C language
code.

STEPS TO WRITE AN ASSEMBLY LANGUAGE PROGRAM IN KEIL AND HOW TO COMPILE IT:

1. Install the Keil Software in the PC in any of the drives.


2. After installation, an icon will be created with the name Keil uVision3. Just drag this icon onto
the desktop so that it becomes easy whenever you try to write programs in keil.
3. Double click on this icon to start the keil compiler.

44
4. A page opens with different options in it showing the project workspace at the leftmost corner
side, output window in the bottom and space for the program to be written.
5. Now to start using the keil, click on the option project.
6. A small window opens showing the options like new project, import project, open project etc.
Click on New project.
7. A small window with the title bar Create new project opens. The window asks the user to give
the project name with which it should be created and the destination location. The project can
be created in any of the drives available. You can create a new folder and then a new file or can
create directly a new file.
8. After the file is saved in the given destination location, a window opens where a list of vendors
will be displayed and you have to select the device for the target you have created.
9. The most widely used vendor is Atmel. So click on Atmel and now the family of microcontrollers
manufactured by Atmel opens. You can select any one of the microcontrollers according to the
requirement.

10. When you click on any one of the microcontrollers, the features of that particular
microcontroller will be displayed on the right side of the page. The most appropriate
microcontroller with which most of the projects can be implemented is the AT89C51. Click on
this microcontroller and have a look at its features. Now click on OK to select this
microcontroller.
11. A small window opens asking whether to copy the startup code into the file you have created
just now. Just click on No to proceed further.
12. Now you can see the TARGET and SOURCE GROUP created in the project workspace.
13. Now click on File and in that New. A new page opens and you can start writing program in it.
14. After the program is completed, save it with any name but with the .asm extension. Save the
program in the file you have created earlier.
15. You can notice that after you save the program, the predefined keywords will be highlighted in
bold letters.
16. Now add this file to the target by giving a right click on the source group. A list of options open
and in that select Add files to the source group. Check for this file where you have saved and
add it.

45
17. Right click on the target and select the first option Options for target. A window opens with
different options like device, target, output etc. First click on target.
18. Since the set frequency of the microcontroller is 11.0592 MHz to interface with the PC, just enter
this frequency value in the Xtal (MHz) text area and put a tick on the Use on-chip ROM. This is
because the program what we write here in the keil will later be dumped into the
microcontroller and will be stored in the inbuilt ROM in the microcontroller.
19. Now click the option Output and give any name to the hex file to be created in the Name of
executable text area and put a tick to the Create HEX file option present in the same window.
The hex file can be created in any of the drives. You can change the folder by clicking on Select
folder for Objects.
20. Now to check whether the program you have written is errorless or not, click on the icon exactly
below the Open file icon which is nothing but Build Target icon. You can even use the shortcut
key F7 to compile the program written.
21. To check for the output, there are several windows like serial window, memory window, project
window etc. Depending on the program you have written, select the appropriate window to see
the output by entering into debug mode.
22. The icon with the letter d indicates the debug mode.

23. Click on this icon and now click on the option View and select the appropriate window to
check for the output.
24. After this is done, click the icon debug again to come out of the debug mode.
25. The hex file created as shown earlier will be dumped into the microcontroller with the help of
another software called Proload.

46
Create a Project File

To create a new project file select from the Vision menu Project New Project. This opens a
standard Windows dialog that asks you for the new project file name.

We suggest that you use a separate folder for each project. You can simply use the icon Create
New Folder in this dialog to get a new empty folder. Then select this folder and enter the file
name for the new project, i.e. Project1. Vision creates a new project file with the name
PROJECT1.UV2 which contains a default target and file group name. You can see these names
in the Project Workspace Files.

Select a Device

When you create a new project Vision asks you to select a CPU for your project. The Select
Device dialog box shows the Vision device database. Just select the microcontroller you use.
We are using for our examples the Philips 80C51RD+ controller. This selection sets necessary
tool options for the 80C51RD+ device and simplifies in this way the tool configuration.

47
Once you have selected a CPU from the device database you can open the user manuals for that
device in the Project Workspace Books page.

These user manuals are part of the Keil Development Tools CD-ROM that should be present in

your CD drive..

Create New Source Files

You may create a new source file with the menu option File New. This opens an empty editor
window where you can enter your source code. Vision enables the C color syntax highlighting
when you save your file with the dialog File Save As under a filename with the extension
*.C. We are saving our example file under the name MAIN.C.

48
Add and Configure the Startup Code

The STARTUP.A51 file is the startup code for the most 8051 CPU variants. The startup code
clears the data memory and initializes hardware and reentrant stack pointers. In addition, some
8051 derivatives require a CPU initialization code that needs to match the configuration of your
hardware design. For example, the Philips 8051RD+ offers you on-chip xdata RAM that should
be enabled in the startup code. Since you need to modify that file to match your target hardware,
you should copy the STARTUP.A51 file from the folder C:\KEIL\C51\LIB to your project folder.

Group Project Files

File group allow you to organize large projects. For the CPU startup code and other system
configuration files you may create a own file group in the Project Components, Environment,
Books dialog box. Use the New (Insert) button to create a file group named System Files. In
the project window you may drag and drop the STARTUP.A51 file to this new file group.

49
Now, the Project Workspace Files lists all items of your project. To open a file for editing,
double click on the file name in the Project Workspace. You may need to configure the startup
STARTUP.A51 in the editor.

Set Tool Options for Target

Vision lets you set options for your target hardware. The dialog Options for Target opens via
the toolbar icon or via the Project - Options for Target menu item. In the Target tab you specify

50
all relevant parameters of your target hardware and the on-chip components of the device you
have selected. The following the settings for our example are shown.

Build Project and Create a HEX File

Typical, the tool settings under Options Target are all you need to start a new application. You
may translate all source files and line the application with a click on the Build Target toolbar
icon. When you build an application with syntax errors, Vision will display errors and warning
messages in the Output Window Build page. A double click on a message line opens the source
file on the correct location in a Vision editor window.

51
Once you have successfully generated your application you can start debugging as described
under Testing Programs with the Vision Debugger.

Now you may modify existing source code or add new source files to the project. The Build
Target toolbar button translates only modified or new source files and generates the executable
file. Vision maintains a file dependency list and knows all include files used within a source
file. Even the tool options are saved in the file dependency list, so that Vision rebuilds files only
when needed. With the Rebuild Target command, all source files are translated, regardless of
modifications.

After you have tested your application, it might be required to create an Intel HEX file and to
download the application software into the physical device using a Flash programming utility.
Vision creates HEX files with each build process when Create HEX file under Options for
Target Output is enabled. The Merge32K Hexfile option is available for Code Banking
Applications when you have selected the Extended Linker LX51. You may start your Flash
programming utility after the make process when you specify the program under the option Run
User Program #1.

52
Conclusion

The project entitled Visitor Counter and Room Light Controller helps to count number of
visitors entering and exiting a particular passage or way. The circuit counts both entering and exiting visitors
and displays the number of visitors present inside the hall. Visitor counting is not limited to the entry/exit
point of a company but has a wide range of applications that provide information to management on the
volume and flow of people throughout a location. This helps to maximize the efficiency and effectiveness of
employees, floor area and sales potential of an organization.

The circuit may also be enhanced with a wide counting range by modifying software section of
the system. It can also be enhanced for long and accurate sensing range using a laser torch instead of IR
transmission circuit. Thus the circuit can be used to monitor visitor flow in effective manner, where the
visitors have to counted and controlled.

53
REFERENCES

BOOKS:

[1] Kenneth .J. Ayala, The 8051 Microcontroller and its applications, prentice hall, new Edition,
2006.

[2] Frank Vahid, Embedded system design, Tata Mc Graw hill, 3 Edition, 1995.

[3] Raj Kamal, Embedded Systems, JWE, 4 Edition, 2000.

WEBSITES:

[5] www.google.com

[6] www.howstuffworks.com

[7] www.epanorama.net

[8] www.wikipedia.org

54
55

S-ar putea să vă placă și