Density Based Traffic Light System
Density Based Traffic Light System
DENSITY BASED
TRAFFIC LIGHT
CONTROLLER
CATHERINE WANJIRU GICHUHI - CI/00040/014
FRANKLINE ODERO OTIENO - CI/00050/014
ARIANDA BASIL OTIENO - CI/00047/014
NAME OF SUPERVISOR
Mr. John Alwala
A project report submitted in partial fulfilment of the requirement for the Bachelor of Science
Degree (BSc.) in Computer Technology
1|Page
DECLARATION
We do hereby declare that this project report is our original work and to the best of our
knowledge, it has not been presented to any other examination body.
This project proposal is hereby presented for examination with the approval of the project
supervisor.
2|Page
Abstract
The project involves the use of IR sensors to measure the traffic density. The sensors are placed at
specific lane intersections and are interfaced to a microcontroller whereby if they detect an object
(such as car) it turns on (goes green) the traffic light for that particular lane, while turning off
(goes red) the rest. The system is a multistate input timed system whereby the inputs while
depend on the sensors output the microcontroller, whereas the timing while be provided within
the microcontroller itself. The microcontroller makes the decisions for the system, whereas the
sensors are used for object detection.
3|Page
Acknowledgement
Throughout the course of our project we received advice and assistance from many members of
staff at Maseno University. We would like to thank and acknowledge the following people for
their guidance:
Our academic supervisor, Mr. J. Alwala, for his continual support throughout the school
year. Significantly his help with the design of the project has saved us many frustrated
hours.
Our Co-Advisor, Mr. Antony, for giving us technical advice on our design
4|Page
Table of Contents
Introduction .............................................................................................................................................. 7
Objective ................................................................................................................................................ 7
Background Information ................................................................................................................... 7
Project Discussions ................................................................................................................................. 7
Software Components ......................................................................................................................... 7
Software Requirements Descriptions ............................................................................................... 8
Hardware Components....................................................................................................................... 8
Hardware Components Description ................................................................................................. 9
Project Design ......................................................................................................................................... 12
The 8051 Microcontroller Design ................................................................................................... 12
Features of 8051 ................................................................................................................................. 12
8051 Microcontroller Architecture in a block diagram style. ....................................................... 13
The Pins Description ........................................................................................................................ 13
Block Diagram of The 8051 .............................................................................................................. 15
Why we chose the 8051 .................................................................................................................... 16
Basic Circuit of the Microcontroller ............................................................................................... 16
LEDs Interfacing ................................................................................................................................. 23
The Infrared Sensor Design:............................................................................................................ 23
Types of IR Sensors ........................................................................................................................... 24
Components Required for the Design of the IR sensor ................................................................ 24
Infrared Transmitter Design ............................................................................................................ 25
Infrared Receiver Design (TSOP 1738 IR Receiver) ....................................................................... 25
Principles of Operation of the IR. ................................................................................................... 27
Objects Interactions ......................................................................................................................... 27
Transmitter and Sensor Placement................................................................................................. 28
Sensor Interfacing ............................................................................................................................. 31
The Circuit System Diagram ................................................................................................................ 32
Sensor and Lights Placements ........................................................................................................ 33
Circuit System Explanation ................................................................................................................. 33
Finding the delay between the states ........................................................................................... 34
Flowchart Showing the System Operation .................................................................................. 35
How Interrupts work in 8051 MCU ................................................................................................. 36
5|Page
Fail- Safe Engineering (Plus preventing Interlocks) ................................................................. 36
Limitations of this Circuit: .................................................................................................................. 36
Pedestrian Traffic Control ................................................................................................................... 37
Applications............................................................................................................................................. 37
Circuit Features/ Advantages .............................................................................................................. 37
Conclusion ............................................................................................................................................... 37
References................................................................................................................................................ 37
6|Page
Introduction
Nowadays, controlling the traffic becomes major issue because of rapid increase in automobiles
and also because of large time delays between traffic lights. So, in order to rectify this problem, we
opt for a density based traffic lights system, that controls the traffic based on the density (number
of vehicles).
Objective
In this system, we will use IR (Infrared) sensors to measure the traffic density. We have to
arrange one IR sensor one for each road; these sensors always sense the traffic on that
particular road. All these sensors are interfaced to a microcontroller. Based on these sensors,
controller detects the traffic and controls the traffic system.
The important considerations in the development of traffic light control systems are
Automation, Power consumption and Cost Effectiveness.
Background Information
Before this invention of traffic lights, the roads were pretty chaotic. Later after the inventions,
during the olden days Traffic lights were controlled manually, these was really time
consuming and was encountered with many errors.
But these days’ automation of traffic lights has emerged, which has played vital roles when it
comes to safety in our everyday lives. Automatic traffic lights control system provides various
benefits as opposed to the manual system like safer movement for cars to help them avoid
collisions with cars and people. They help movement and help conduct an orderly flow by
giving right of way to some cars and not others which helps in reducing the number of
accidents and make collisions at intersections a lot less frequent.
Nowadays some lights don't have detectors for example in large cities, the traffic lights may
simply operate on timers! Since no matter what time of the day it is, there is going to be a lot
of traffic. Whereas in the suburbs and country roads, however, detectors are common. Which
may detect when cars arrive at an intersection or when too many cars are stacked up at an
intersection to control the lights. These detectors may be composed of many technologies like
lasers to rubber hoses filled with air, or even an inductive loop (most common) which detects
changes in the inductance at the road surface to know if there is a car waiting.
Project Discussions
Software Components
Keil uVision
NI Mutism/Proteus
Visual Studio/ Turbo C
PROGISP for burning the code into microcontroller
Embedded C Program (Source Code)
7|Page
Software Requirements Descriptions
Keil uVision - Compiling, Converts hex file from C Source code. It is a development tool
for the 8051 Microcontroller Architecture support every level of software developer from
the professional applications engineer to the student just learning about embedded
software development.
Multism/Proteus these are simulation Software's that simulate the hardware
PROGISP is used for burning the source code into microcontroller
Embedded C is one of the most popular and most commonly used Programming
Languages in the development of Embedded Systems due to its efficiency, less
development time and portability.
o Embedded Software or Program allow Hardware to monitor external events
(Inputs) and control external devices (Outputs) accordingly. During this process,
the program for an Embedded System may have to directly manipulate the internal
architecture of the Embedded Hardware (usually the processor) such as Timers,
Serial Communications Interface, Interrupt Handling, and I/O Ports etc.
o Earlier Embedded Systems were developed mainly using Assembly Language. Even
though Assembly Language is closest to the actual machine code instructions, the
lack of portability and high amount of resources spent on developing the code,
made the Assembly Language difficult to work with.
Hardware Components
8|Page
Hardware Components Description
Breadboard
It’s a circuit board that is used to make temporary circuits for the purpose of testing and
prototyping circuits.
It provides physical support for mounting the electronic components and also the electrical
connections between them., They can be reused again and again for the purpose of testing.
Breadboards are solderless and they are made of two kinds of strips i.e. terminal and bus strips.
Terminal strips help in holding the electronic elements while the bus strip is used to power
electric power to all the electronic components. Breadboard are advantageous in that the
positions of the wires can be changed if they are placed in a wrong order.
In our project, we will be using breadboards as opposed to PCBs because they are suitable for
small projects which involve a limited number of components (through-hole components) and
connections.
LEDS
An LED or a Light Emitting Diode is semiconductor device that emits light due to
Electroluminescence effect. An LED is basically a PN Junction Diode, which emits light when
forward biased.
Few advantages of LEDs over incandescent and compact fluorescent lamps(CFL) light sources
are:
o Low Power Consumption
o Small Size
o Fast Switching
o Physically Robust
o Long Lasting
Instead of traffic lights, we will =use LEDs (RED, GREEN, YELLOW). In normal traffic system
the LEDs need to glow on time basis. But in our case, if the traffic density is high on any
particular path, then glows green LED of that particular path and glows the red LEDs for the
other remaining paths.
Diodes
Diode is a non-linear semiconductor device that allows flow of current in one direction. A
Diode is a two – terminal device and the two terminals are Anode and Cathode respectively.
9|Page
Transistors
A Transistor is a 3 terminal device that can either a current controlled device or a voltage
controlled device. Transistors are further classified in to Bipolar Junction Transistors (BJT)
and Field Effect Transistors (FET).
o A Bipolar Junction Transistor or BJT uses both the charge carriers i.e. electrons and
holes and is often used as a current amplifier. Based on the construction, BJTs are
further divided in to NPN and PNP Transistors.
o Field Effect Transistor or FET uses only a single charge carrier. Junction FET (JFET)
and Metal Oxide Semiconductor FET (MOSFET) are the two types of FETs.
Power Sources
Batteries
Battery is a device that converts chemical energy in to electrical energy and provides power
to devices like mobile phones, laptops, flashlights, etc. In electronics, we often use batteries
to power our circuits, either to make the circuit portable or just to test the functionality of
the circuit.
Batteries come in different sizes and voltage. Batteries are also classified as Primary and
Secondary. You can use Primary Batteries until they are drained out and discard them later.
In case of Secondary Batteries, you can use them even after they are drained out by
recharging them.
DC Power Supply
Also known as Bench Power Supply. Electronic components majorly work on DC Power
Supply and hence having a reliable source of DC Power Supply is very important.
Passive Components
Passive Components cannot control the flow of current through them i.e. they cannot introduce
energy in to the circuit but can increase or decrease voltage and current, for example Resistors.
Resistors
They are the basic of all electronic components. It is a passive electronic component that
introduces electrical resistance in to the circuit. Using resistors, we can reduce the
current, divide voltages, setup biasing of transistors (or other active elements), etc.
Resistors cad be divided into Fixed Resistors and Variable Resistors. Fixed Resistors, as the
name suggests, have a fixed resistance and its resistance doesn’t change due to external
parameters.
10 | P a g e
Variable Resistors, on the other hand, have a variable resistance that can either be
changed manually like in case or Trimmers and Potentiometers or which controlled by
external factors like Light Dependent Resistor (LDR) or Thermistor.
Ohm’s Law defines the behaviour of a resistor which states that the current through a
conductor is directly proportional to the voltage across the conductor. The proportionality
constant is called as Resistance.
The mathematical representation of Ohm’s Law is I = V/R.
The principle behind the working of this project lies in the functioning of IR Sensor. We are
going to use a reflective type IR Sensor in this project. Thus when Powered, the transmitted IR
rays hit the object and reflect back to the IR receiver.
11 | P a g e
MCU
1 P1B0T2 VCC 40
2 P1B1T2EX P0B0AD0 39
3 P1B2 P0B1AD1 38
4 P1B3 P0B2AD2 37
5 P1B4 P0B3AD3 36
6 P1B5MOSI P0B4AD4 35
7 P1B6MISO P0B5AD5 34
8 P1B7SCK P0B6AD6 33
9 RST P0B7AD7 32
10 P3B0RXD EAVPP 31
11 P3B1TXD ALEPROG 30
12 P3B2INT0 PSEN 29
13 P3B3INT1 P2B7A15 28
14 P3B4T0 P2B6A14 27
15 P3B5T1 P2B5A13 26
16 P3B6WR P2B4A12 25
17 P3B7RD P2B3A11 24
18 XTAL2 P2B2A10 23
19 XTAL1 P2B1A9 22
20 GND P2B0A8 21
8051
Project Design
The 8051 Microcontroller Design
8051 is an 8-bit Microcontroller i.e. the data bus (both internal and external is 8-bit wide.
It is a CISC based microcontroller, with Harvard Architecture
Features of 8051
8 – Bit ALU: ALU or Arithmetic Logic Unit is the heart of a microcontroller. It performs
arithmetic and bitwise operation on binary numbers. The ALU in 8051 is an 8 – Bit ALU
i.e. it can perform operations on 8 – bit data.
8 – Bit Accumulator: The Accumulator is an important register associated with the ALU.
The accumulator in 8051 is an 8 – bit register.
RAM: 8051 Microcontroller has 128 Bytes of RAM which includes SFRs and Input / Output
Port Registers.
ROM: 8051 has 4 KB of on-chip ROM (Program Memory).
I/O Ports: 8051 has four 8 – bit Input / Output Ports which are bit addressable and
bidirectional.
Timers / Counters: 8051 has two 16 – bit Timers / Counters.
Serial Port: 8051 supports full duplex UART Communication.
External Memory: 8051Microcontroller can access two 16 – bit address line at once: one
each for RAM and ROM. The total external memory that an 8051 Microcontroller can
access for RAM and ROM is 64KB (216 for each type).
Packaging - Dual in-line or DIP. We will be using a 40 – pin PDIP or Plastic DIP IC.
No of Pins - 32 I/O Pins (Input / Output Pins) – Arranged as 4 Ports: P0, P1, P2 and P3.
8- bit Stack Pointer (SP) and Processor Status Word (PSW).
16 – bit Program Counter (PC) and Data Pointer (DPTR).
Timers - Two 16 – bit Timers / Counters – T0 and T1.
Control Registers – SCON, PCON, TCON, TMOD, IP and IE.
Serial Data Transmitter and Receiver for Full – Duplex Operation – SBUF.
12 | P a g e
8051 Microcontroller Architecture in a block diagram style.
Pins 1 – 8 (PORT 1): Pins 1 to 8 are the PORT 1 Pins of 8051. PORT 1 Pins consists of 8 – bit
bidirectional Input / Output Port with internal pull – up resistors. In older 8051
Microcontrollers, PORT 1 doesn’t serve any additional purpose but just 8 – bit I/O PORT.
In some of the newer 8051 Microcontrollers, few PORT 1 Pins have dual functions. P1.0 and P1.1
act as Timer 2 and Timer 2 Trigger Input respectively.
P1.5, P1.6 and P1.7 act as In-System Programming Pins i.e. MOSI, MISO and SCK respectively.
Pin 9 (RST): Pin 9 is the Reset Input Pin. It is an active HIGH Pin i.e. if the RST Pin is HIGH
for a minimum of two machine cycles, the microcontroller will be reset. During this time, the
oscillator must be running.
Pins 10 – 17 (PORT 3): Pins 10 to 17 form the PORT 3 pins of the 8051 Microcontroller. PORT 3
also acts as a bidirectional Input / Output PORT with internal pull-ups. Additionally, all the
PORT 3 Pins have special functions. The following table gives the details of the additional
functions of PORT 3 Pins.
13 | P a g e
P3.4 T0 Timer 0
P3.5 T1 Timer 1
P3.6 WR External Memory
Write
P3.7 RD External Memory
Read
Pins 18 & 19: Pins 18 and 19 i.e. XTAL 2 and XTAL 1 are the pins for connecting external
oscillator. Generally, a Quartz Crystal Oscillator is connected here.
Pin 20 (GND): Pin 20 is the Ground Pin of the 8051 Microcontroller. It represents 0V and is
connected to the negative terminal (0V) of the Power Supply.
Pins 21 – 28 (PORT 2): These are the PORT 2 Pins of the 8051 Microcontroller. PORT 2 is also
a Bidirectional Port i.e. all the PORT 2 pins act as Input or Output. Additionally, when
external memory is interfaced, PORT 2 pins act as the higher order address byte. PORT 2 Pins
have internal pull-ups.
Pin 29 (PSEN): Pin 29 is the Program Store Enable Pin (PSEN). Using this pins, external
Program Memory can be read.
Pin 30 (ALE/PROG): Pin 30 is the Address Latch Enable Pin. Using this Pins, external address
can be separated from data (as they are multiplexed by 8051).
During Flash Programming, this pin acts as program pulse input (PROG).
Pin 31 (EA/VPP): Pin 31 is the External Access Enable Pin i.e. allows external Program
Memory. Code from external program memory can be fetched only if this pin is LOW. For
normal operations, this pin is pulled HIGH.
During Flash Programming, this Pin receives 12V Programming Enable Voltage (VPP).
Pins 32 – 39 (PORT 0): Pins 32 to 39 are PORT 0 Pins. They are also bidirectional Input /
Output Pins but without any internal pull-ups. Hence, we need external pull-ups in order to
use PORT 0 pins as I/O PORT.
In addition to acting as I/O PORT, PORT 0 also acts as lower order address/data bus when
external memory is accessed.
Pin 40 (VCC): Pin 40 is the power supply pin to which the supply voltage is given (+5V).
14 | P a g e
Block Diagram of The 8051
Program Memory
The instructions of the CPU are stored in the Program Memory. It is usually implemented as Read
Only Memory or ROM, where the Program written in to it will be retained even when the power
is down or the system is reset.
Modern Program Memory Modules are generally made up of EEPROM (Electrically Erasable
Programmable Read – only Memory), which is a type of non – volatile memory (the data can be
erased and reprogrammed using special programming signals)
When the microcontroller is powered on or manually reset, the processor executes a set of
instructions from a pre-defined memory location (address) in the Program Memory.
Data Memory
Data Memory in a Microcontroller is responsible for storing values of variables, temporary data,
intermediate results and other data for proper operation of the program.
15 | P a g e
Data Memory is often called as RAM (Random Access Memory), which is a type of volatile
memory. It is generally organized as registers and includes both Special Function Registers (SFRs)
and user accessible memory locations.
U1
1 P1B0T2 VCC 40
2 P1B1T2EX P0B0AD0 39
3 P1B2 P0B1AD1 38
C 4 P1B3 P0B2AD2 37
Switch 5
6
P1B4 P0B3AD3 36
35
P1B5MOSI P0B4AD4
7 P1B6MISO P0B5AD5 34
8 P1B7SCK P0B6AD6 33
9 RST P0B7AD7 32 R2
10 P3B0RXD EAVPP 31
11 P3B1TXD ALEPROG 30
C1 12 P3B2INT0 PSEN 29
13 P3B3INT1 P2B7A15 28
R1 14
15
P3B4T0 P2B6A14 27
26
P3B5T1 P2B5A13
16 P3B6WR P2B4A12 25
17 P3B7RD P2B3A11 24
18 XTAL2 P2B2A10 23
19 XTAL1 P2B1A9 22
X 20 GND P2B0A8 21
C2 8051
This basic circuit of 8051 microcontrollers is the minimal interface required for it to work.
The basic circuit includes a Reset Circuit, the oscillator circuit and power supply.
First is the power supply. Pins 40 and 20 (VCC and GND) of the 8051 Microcontroller are
connected to +5V and GND respectively.
16 | P a g e
Next is the Reset Circuit. A logic HIGH (+5V) on Reset Pin for a minimum of two machine
cycles (24 clock cycles) will reset the 8051 Microcontroller. The reset circuit of the 8051
Microcontroller consists of a capacitor, a resistor and a push button and this type of reset
circuit provides a Manual Reset Option. If you remove the push button, then the reset
circuit becomes a Power-On Reset Circuit.
The next part of the basic circuit of the 8051 Microcontroller is the Oscillator Circuit or
the Clock Circuit. A Quartz Crystal Oscillator is connected across XTAL1 and XTAL2 pins
i.e. Pins 19 and 18. The capacitors C1 and C2 can be selected in the range of 20pF to 40pF.
8051 Microcontroller Pin Description, PORTS 1, 2 and 3, all have internal pull – ups and
hence can be directly used as Bidirectional I/O Ports. But, we need to add external Pull –
ups for PORT 0 Pins in order to use it as an I/O Port.
18 XTAL 1
X1
8051 DIP
C2
19 XTAL 2
Although 8051 has an on-chip oscillator, it needs an external crystal that decides the operating
frequency.
A crystal oscillator is an electronic oscillator circuit which is used for the mechanical resonance of
a vibrating crystal of piezoelectric material. It will create an electrical signal with a given
frequency which is commonly used to keep track of time.
The crystal is connected to pins 18 and 19 with stabilizing capacitors. We will be using a 12 MHz
(11.059MHz) crystal oscillator to synchronize the 8051’s operation.
Same value capacitors called stabilizing capacitors of the ranges 20pF to 40pF are connected to
the crystal to generate the clock signal of the desired frequency (parallel resonance).
The oscillator circuit also provides an accurate and stable periodic clock signal to a
microcontroller. The frequency of this clock signal can range from a few kilohertz to tens of
megahertz and determines how quickly the microcontroller executes its instructions, hence
determines the response time and the length of a machine cycle (Number of clock cycles it takes
to execute an instruction).
8051 uses the crystal for precisely that to synchronize its operation, since the 8051 operates using
what are called "machine cycles."
The oscillator circuit is the ‘heartbeat’ of the system and is crucial to correct operation. For
example, if the oscillator fails, the system will not function at all; if the oscillator runs irregularly,
any timing calculations performed by the system will be inaccurate.
17 | P a g e
The Machine Cycles
CPU executing an instruction takes a certain number of clock cycles. These are referred as to as
machine cycles. A single machine cycle is the minimum amount of time in which a single 8051
instructions can be executed. although many instructions take multiple cycles.
The length of machine cycle depends on the frequency of the crystal oscillator connected to 8051
In original 8051, one machine cycle lasts 12 oscillator periods
Two factors can affect the accuracy of the delay in a machine cycle:
Crystal frequency
The duration of the clock period of the machine cycle is a function of this crystal frequency
8051 design
The original machine cycle duration was set at 12 clocks
Advances in both IC technology and CPU design in recent years have made the 1-clock
machine cycle a common feature
Therefore, this would give us a reasonable response time for our microcontroller. NB: Machine
Cycles refers number of clock cycles a CPU takes to execute instructions.
AT89C51 Atmel 12
P89C54X2 Philips 6
DS89C420/30/40/50 Dallas 1
Semi
Finding the period of the machine cycle (MC) for various versions of 8051, if XTAL=11.0592 MHz.
(a) AT89C51
11.0592MHz/12 = 921.6kHz;
MC is 1/921.6kHz = 1.085μs =1085ns
18 | P a g e
(b) P89C54X2
11.0592MHz/6 = 1.8432MHz;
MC is 1/1.8432MHz = 0.5425μs =542ns
(c) DS5000
11.0592MHz/4 = 2.7648MHz;
MC is 1/2.7648MHz = 0.36μs =360ns
(d)DS89C4x0
11.0592MHz/1 = 11.0592MHz;
MC is 1/11.0592MHz = 0.0904μs =90ns
To calculate the time any instruction would take to be executed, find the number of cycles, C. The
time to exec that instruction is the found by multiplying C by 12 and dividing by the crystal
frequency.
𝐶 ∗ 12𝑑
𝑇𝑖𝑛𝑠𝑡 =
𝐶𝑟𝑦𝑠𝑡𝑎𝑙 𝐹𝑟𝑒𝑞𝑢𝑒𝑛𝑐𝑦
For example, if the crystal frequency is 16 MHz, then the time to execute an ADD A, R1 one-cycle
is 0.75µ𝑆.
A 12MHz crystal yields the convenient time of 1mS per cycle.
An 11.0592 MHz crystal yields a crystal frequency of 921.6kHz
19 | P a g e
Why Choose a Low Oscillator Frequency?
1. Since many applications do not require the level of performance a modern 8051 can
provide.
2. Clock frequency is directly proportional to the power supply current. Hence we ought to
reduce the power requirements by using a low frequency. This can be useful in battery-
powered applications.
3. Since we will be accessing low speed peripherals, we have to use a low clock speed in order
to conform to their requirements.
4. Electromagnetic interference generated by a circuit increases with the clock frequency
After a reset, the program counter is loaded with 0000H but the content of on-chip RAM
is not affected.
20 | P a g e
Table showing the Components Values of 8051 after reset.
A real reset circuit is not necessary in order for an 8051 to function in a circuit, but it helps
restore the microcontroller to its original or default state in case of an error(fault). Without
the use of a reset circuitry, the microcontroller may go into a tristate of which it may go into
abnormal operation.
The reset pin (pin 9) is an Active HIGH (normally low) input, and a RESET is an Active
HIGH input signal.
It is used to clear the controls register, that is:
When RESET is activated, all the ports are configured as inputs, ready to be used as
input ports. When the first 0 is written to a port, it becomes an output. To reconfigure
it as an input, a 1 must be sent to a port.
To ensure a valid input of Reset, the high pulse must be high for a minimum of two machine
cycles before it is allowed to go low, which depends on the capacitor value and the rate at
which it charges. (Machine Cycle is the minimum amount of frequency a single instruction
requires in execution). Given by:
𝑅
𝑇 = 𝐶 to find the time taken by a capacitor to fully charge
21 | P a g e
Upon Reset, all the interrupts are disabled even if they are activated. The interrupts must be
enabled using software in order for the microcontroller to respond to those interrupts.
A reset is the ultimate interrupt because the program may not block the action of the
voltage on the RST pin. Hence its non-maskable, since no combination of bits in any register
can stop, or mask the rest action.
Internal RAM is not changed by reset: however, the states of the internal RAM when power
Is first applied to the 8051 are random. Register back 0 is selected upon reset as all bits in
PSW are 0.
The resistor in the reset circuit is a pulldown resistor, it pulls the signal to a low state unless
its driven high, to prevent floating conditions.
The value of the pull-down resistor depends on two factors, that is the power dissipation
and the pin voltage when the switch is open.
The capacitor serves two functions:
It acts a simple switch de-bounce mechanism and ensuring the reset pin is pulled high
for an appropriate period of time to properly initiate a reset.
Once the switch is open, the capacitor begins to charge at a rate based on the RC
factor, when it reaches a level equivalent to the low logic threshold, the device
transitions fro, reset to normal operations
22 | P a g e
LEDs Interfacing
For the traffic lights, we will be using a LEDs, with the following typical ratings:
Each LED will be connected to a single port pin via a current limiting resistor of whose value
is calculated below:
(𝑉𝑠 − 𝑉𝑓)
𝑅=
𝑖
Therefore, Substituting,
5𝑉 − 1.83𝑉
= 158.5Ω
0.02𝐴
The frequency range of infrared is higher than microwave and lesser than visible light. The
basic concept of an Infrared Sensor which is used as Obstacle detector is to transmit an
infrared signal, this infrared signal bounces from the surface of an object and the signal is
received at the infrared receiver.
There are five basic elements used in a typical infrared detection system:
o an infrared source
o a transmission medium
o optical component
o infrared detectors or receivers and
23 | P a g e
o signal processing
Infrared lasers and Infrared LED’s of specific wavelength can be used as infrared sources.
The three main types of media used for infrared transmission are vacuum, atmosphere and
optical fibers.
Optical components are used to focus the infrared radiation or to limit the spectral response.
Optical lenses made of Quartz, Germanium and Silicon are used to focus the infrared
radiation.
Infrared receivers can be photodiodes, phototransistors etc. some important specifications of
infrared receivers are photosensitivity, detectivity and noise equivalent power.
Signal processing is done by amplifiers as the output of infrared detector is very small.
Types of IR Sensors
24 | P a g e
Infrared Transmitter Design
The 555 timer is designed to operate in A-stable mode (In this mode, the 555 IC will work as a
free running oscillator and generates an approximate 38 KHz square wave.). It generates a
continuous pulse and of frequency 38kHz, therefore for our design, the information or the
light signals are pulse width modulated and are contained in the 38 KHz frequency.
IR LED emits infrared light, meaning it emits light in the range of Infrared frequency which
we cannot see with bare eyes. (700nm – 1mm)
The output of the 555 IC is connected to an IR LED through a button. When we push the
switch, the connection between IR LED and the output of the 555 Timer is closed and the IR
LED emits the light at a frequency of 38 KHz.
IR LED is a special type of LED that emits Infrared rays of the Electromagnetic Spectrum. The
wavelength of Infrared Rays is greater than that of Visible light and hence they are invisible to
human eye.
25 | P a g e
Infrared receivers are also called as infrared sensors as they detect the radiation from an IR
transmitter.
TSOP 1738 in particular supports a carrier frequency of 38 KHz and the output of this IR
Receiver can be directly connected to a microcontroller or a microprocessor.
TSOP 1738 has three pins namely GND, VS and OUT. Whereby:
Vcc to the power supply 3-5V DC;
Gnd to the ground reference;
Out for the digital output signal of the sensor.
TSOP sensor has an inbuilt control circuit for amplifying the coded pulses from the IR
transmitter
The Resistor R and Capacitor C are only used to suppress the power supply disturbances.
When this modulated infrared light (its modulated in order to prevent interference and false
triggering) is placed in line of sight to TSOP 1738, it detects the signal and demodulates it.
The output of TSOP 1738 is usually HIGH and when it detects IR Signals, the output becomes
LOW.
The output is connected to a PNP transistor(BC558), which basically acts as switch since the
output is connected to a PNP transistor (BC558), when the IR Receiver detects infrared signal,
the transistor is switched ON and the LED connected to it is turned ON.
The output of the PNP transistor is the one we will connect to the microcontroller pin and
there is no need for any extra interface. Therefore, it can be powered using a 5V power supply
and its active low output can be directly connected to a microcontroller or microprocessor.
26 | P a g e
Principles of Operation of the IR.
The circuit is divided into IR transmitter and IR receiver circuits. The infrared rays emitted by
the IR Transmitter i.e. IR LED must be detected by the IR Receiver i.e. TSOP 1738. Since the
IR Receiver used in this project is TSOP 1738, we need to modulate the IR Signals at nearly 38
KHz.
In the transmitter part, the 555 Timer is designed to operate in A Stable Mode. In this mode,
the 555 IC will work as a free running oscillator and hence, it generates a continuous pulse
(square wave) and the frequency of the pulse is 38 KHz. The output of the 555 IC is connected
to an IR LED through a button. When we push the tactile switch, the connection between IR
LED and the output of the 555 Timer is closed and the IR LED emits the light at a frequency
of 38 KHz.
When this modulated infrared light is placed in line of sight to TSOP 1738, it detects the
signal and demodulates it. The output of TSOP 1738 is usually HIGH and when it detects IR
Signals, the output becomes LOW. Since the output is connected to a PNP transistor (BC558),
when the IR Receiver detects infrared signal, the transistor is switched ON and the LED
connected to it is turned ON.
When the IR transmitter emits radiation, it reaches the object and some of the radiation
reflects back to the IR receiver. Based on the intensity of the reception by the IR receiver, the
output of the sensor is defined.
The positioning of the IR LED and the IR Receiver is an important factor; When the IR LED is
held directly in front of the IR receiver, this setup is called Direct Incidence. In this case,
almost the entire radiation from the IR LED will fall on the IR receiver. Hence there is a line
of sight communication between the infrared transmitter and the receiver. If an object falls in
this line, it obstructs the radiation from reaching the receiver either by reflecting the
radiation or absorbing the radiation.
Objects Interactions
Infrared detectors can operate during both day and night, and can be mounted in both side
and overhead configurations. Its disadvantage is that infrared detectors can be sensitive to
element weather conditions and ambient light. Common materials that absorb IR include
window glass, plastics, metals and wood. Others include gold, manganese, copper, CO2,
ozone and oxygen – although these may be in small percentage. A car’s paint also absorbs IR
radiation on long exposure. Darker colors absorb the visible wavelengths in sunlight, not IR
rays. Therefore, the color of the material is unimportant in the ability of a material to absorb
infrared light
27 | P a g e
receiver, the emitted radiation must reflect back to the photodiode after hitting any object.
The surface of the object can be divided into two types:
reflective surface
non-reflective surface.
If the surface of the object is reflective in nature i.e. it is white or other light color, most of the
radiation incident on it will get reflected back and reaches the photodiode. Depending on the
intensity of the radiation reflected back, current flows in the photodiode.
If the surface of the object is non-reflective in nature i.e. it is black or other dark color, it
absorbs almost all the radiation incident on it. As there is no reflected radiation, there is no
radiation incident on the photodiode and the resistance of the photodiode remains higher
allowing no current to flow. This situation is similar to there being no object at all.
The pictorial representation of the above scenarios is shown below.
The positioning and enclosing of the IR transmitter and Receiver is very important. Both the
transmitter and the receiver must be placed at a certain angle, so that the detection of an
object happens properly. This angle is the directivity of the sensor which is +/- 45 degrees.
In order to avoid reflections from surrounding objects other than the object, both the IR
transmitter and the IR receiver must be enclosed properly. Generally, the enclosure is made
of plastic and is painted with black color.
The IR transmitter sends an infrared signal that, in case of a reflecting surface (e.g. white
color), bounces off in some directions including that of the IR receiver that captures the
signal detecting the object.
When the surface is absorbent (e.g. black color) the IR signal isn’t reflected and the object
cannot be detected by the sensor. This result would occur even if the object is absent.
Our IR sensors will be placed under a protecting cover made of glass or plastic. The glass will
be painted, or the plastic tinted with ink to hide the sensor. The protecting cover must
transmit IR light while at the same time being largely opaque to the visible light. IR inks are
specifically formulated to block much of the visible light while passing IR light.
28 | P a g e
When light passes through a material, light is absorbed, reflected, scattered or transmitted.
As stated, the IR light should be transmitted while the visible light is blocked. Visible light
absorption is the preferred way to block light since the side effects are minimal; however,
visible light absorption is difficult to control while passing IR light.
Reflection is also an acceptable way to block light but is often closely related to scattering.
Scattered light is the most problematic causing a small amount of the light to leak directly
from the IR LED to the sensor.
Black ink typically absorbs light while white ink reflects/scatters light. In a very thin ink layer,
some light will be transmitted, some absorbed, and some light reflected. With the black ink,
the light not transmitted is absorbed. With the white ink, the light not transmitted is
reflected.
The term “black” ink refers to any ink, film, or other method used to conceal the electronics.
Black ink typically does not transmit any light. The term “dark” ink refers to translucent ink,
glass with tinting, film, or any other method used to partially hide the sensor. Dark ink allows
light to transmit to the sensor.
Distance Determination
29 | P a g e
The maximum possible transmission distance of an IR system depends on various parameters,
but is mainly conditional on the radiant intensity of the emitter (Ie) and sensitivity of the
receiver (Eemin)
Calculating transmission ranges in the simplest case assumes a quadratic relationship
between the distance d and the irradiance of the receiver Ee. Given emitter intensity Ie, the
maximum distance is calculated as:
When the responsivity of the receiver module and the intensity of the transmitter are known,
the transmission range can either be calculated using this expression.
Alternatively, graph can be used to determine the distance. The typical distance shown in the
curve was calculated using a threshold irradiance of 0.12 mW/m2. This is equivalent to the
typical value specified for the TSOP48 or TSOP22 series. The maximum threshold sensitivity
is specified at 0.25 mW/m2 for these devices, which is used for calculating the worst case
transmission distance.
In practice, the relationship between irradiance and transmission distance does not exactly
follow a quadratic curve. In most cases, the actual distance is longer than calculated by the
expression. This means that the example calculated here can be used as a worst case in free
air and in reality better transmission ranges are attained.
30 | P a g e
Sensor Interfacing
VCC
The 8051 considers any voltage between 2 and 5V at its port pin as HIGH and any voltage
between 0 to 0.8V as LOW. Since the output of the sensor module has only two stages (HIGH
(3.3V) and LOW (0V)), it can be directly interfaced to the 8051 microcontroller. As shown
above.
The sensor outputs logic 1(+5V) when Infrared below a threshold is falling on to it, and a logic
0 (0V) when it receives Infrared above a threshold.
It does not respond to any stray IR; it only responds to IR falling on it at a pulse rate of 38kHz.
To increase the range of the IR, one can increase the current or power at the IR transmitter.
Factors That may affect the range of the Infrared ray transmission are
1. Presence of other sources of interference e.g. fluorescent lights.
2. Whether we are transmitting data or just doing object detection.
3. Whether indoors or outdoors.
4. Radiant intensity of the emitter.
5. Sensitivity of the receiver/
6. Disturbance conditions, such as rain, high humidity.
31 | P a g e
The Circuit System Diagram
VCC VCC
5.0V
U1
1 P1B0T2 VCC 40
2 P1B1T2EX P0B0AD0 39
3 P1B2 P0B1AD1 38
C 4 P1B3 P0B2AD2 37
Switch 5
6
P1B4 P0B3AD3 36
35
P1B5MOSI P0B4AD4
7 P1B6MISO P0B5AD5 34
8 P1B7SCK P0B6AD6 33
9 RST P0B7AD7 32 R2
10 P3B0RXD EAVPP 31
11 P3B1TXD ALEPROG 30
C1 12
13
P3B2INT0 PSEN 29
28
P3B3INT1 P2B7A15
R1 14
15
P3B4T0 P2B6A14 27
26
P3B5T1 P2B5A13
16 P3B6WR P2B4A12 25
17 P3B7RD P2B3A11 24
18 XTAL2 P2B2A10 23
19 XTAL1 P2B1A9 22
X 20 GND P2B0A8 21
C2 8051
Sensor 1
Sensor 2
Sensor 3
32 | P a g e
Sensor and Lights Placements
If you receive logic 0 from any of these sensors, we have to give the green signal to that particular
path and give red signal to all other paths. Here continuously we have to monitor the IR sensors
to check for the traffic.
The system also has a timer, in order to prevent a particular lane from being ON for too long, if
the density of that lane is very high, it’s basically a time out, this helps to prevent ‘starvation’
whereby a given lane will be ACTIVE continuously thereby denying access to other lanes.
Hence our system is a multistate input/timed system in which transition between the states (&
behavior in each state) will depend both on the passage of time and system inputs.
For example, our system will only move to state A and B if a particular input is received within X
seconds of a system output being generated.
Green light allows traffic to proceed in the direction denoted, if it’s safe to do so and there is room
on the other side of the intersection
33 | P a g e
The amber (yellow) light warns that the signal is about to change to red. A phase where red and
yellow are displayed together indicates that the signal is about to change to green.
Red prohibits traffic from proceeding in the given direction, and a flashing red indicates a stop
sign
8051 has two timers/counters, timer 0 and timer 1 which are 16 bits wide.
34 | P a g e
Flowchart Showing the System Operation
No conflict
Start Detected
Error
Initialize the Ports and Initialize a timer interrupt Detected Error mode (Orange
Sensor Ports for regular system Light Flashes On and
diagnosis(troubleshoot) OFF)
Delay
TD is Active
Delay 1
Delay
Sensor 1 YES TA is ACTIVE 0
Once S1 state
is High? The rest are OFF.
NO 1
Delay
YES TB is ACTIVE 0
Sensor 2 Once S2 State
is High? The rest are OFF.
NO 1
Delay
TC is ACTIVE
NO Sensor 3 YES Once S3 State 0
is High? The rest are OFF.
35 | P a g e
How Interrupts work in 8051 MCU
Upon the activation of an interrupt:
1. Microcontroller finishes the instructions its executing and saves the address of the next
instruction(PC) on the stack.
2. It also saves the current status of all interrupts internally (i.e. not in the stack)
3. It jumps to a fixed location in memory called the interrupt vector table, that holds the address of
the Interrupt Service Routine(ISR).
4. The microcontroller gets the address of the ISR form the interrupt vector table and jumps into it.
a. It starts to execute the Interrupt Service Subroutine until it reaches the last instruction
of the subroutine which is RETI (return from interrupt)/
5. Upon the execution of the RETI instruction, the MCU returns to the place where it was
interrupted.
a. First it gets the PC address from the stack by popping the top 2 bytes of the stack into
the PC.
b. Then it starts to execute from that address.
To achieve a fail-safe engineering, whereby in the event of a specific type of failure it inherently
responds in a way that will cause minimal harm to the equipment, the environment or people, we
have incorporated the following into our design:
Hardware traps
Efficient codes, capable of diagnosing the system or troubleshooting for errors.
Prevention, Detection and Correction of interlocks (undesired states) which may cause
system failure.
The goal of failsafe design is to make a control system as tolerant as possible to likely wiring or
component failure. The most common type of wiring and component failure is an ‘open-circuit’ or
broken connection. Therefore, a failsafe system should be designed to default to its safest mode of
operation in case of an open circuit.
36 | P a g e
Pedestrian Traffic Control
Each road lane would have a separate light for pedestrians, the pedestrians can only cross that
particular lane whenever the traffic is not flowing (light is red) based on the sensors which control
the traffic.
In our design, we have decided to use an LED indictor to control the pedestrians, that is, when
the light is ON, pedestrians are restricted from crossing the road, otherwise they are permitted.
Applications
The density based traffic light can be used in normal roads, highways, express ways etc.
They can be used to monitor car traffic as well as pedestrian traffic, hence makes traffic
safer.
Conclusion
By introducing the concept of infrared technology on traffic lights in roads and transports, we can
make our roads much safer, efficient and faster with great efficiencies with reduced traffic
congestions and accidents. We do hope that such a system can be set up at public transport
places like railways, bus station, and airport and also at roadside for traffic control and in
emergency situations, because it is cost efficient system and very easy to handle.
References
From the website http://www.electronicshub.org where we researched on:
http://www.electronicshub.org/density-based-traffic-signal-system-using-
microcontroller/
http://www.electronicshub.org/different-types-sensors/
http://www.electronicshub.org/led-light-emitting-diode/
http://www.electronicshub.org/basic-electronic-components/
Books:
Warwick A. Smith, C Programming for Embedded Microcontrollers
Sedra and Smith, Microelectronic Circuits, fourth edition, Oxford University Press, 1998
R.S. Sedha, 2002. A Text Book of Applied Electronics, S. Chand and Company Ltd., New
Delhi
Michael J. Pont, Embedded C
Others:
Embedded Systems/ 8051 Microcontroller Available at:
http://en.wikibooks.org/wiki/Embedded_Systems/8051Microcontroller
37 | P a g e
Programming and Customizing the AVR Microcontroller by Dhananjay Gadre
Keil website: http://www.keil.com/c51/., C51 Documentation/ Tutorials and Examples
The Features of ATmega8: https://handhua.wordpress.com/2011/04/27/the-features-of-
atmega8/>
Wikipedia https://en.wikipedia.org/wiki/Atmel_AVR
38 | P a g e