You are on page 1of 42

Semester project Design and simulation of traffic light control using microcontroller

CHAPTER ONE
INTRODUCTION
1.1 Background
The idea of traffic light microcontroller circuit and programming of the PIC is an adaptation
from conventional traffic light controller system. All the concept and idea from the reference are
combined to get the idea of automatically traffic light controller using PIC. The sensor are used
each side road to detect the number of vehicle. The witting time of green light and red light is
decided by microcontroller based on the number of vehicles detected by sensors. A traffic light is
a device that is designed to control the flow of traffic by using three colours of lights. These
lights are mainly green, yellow, and red.
Traffic congestion is a severe problem in many modern cities around the world. Traffic
congestion has been causing many critical problems and challenges in the major and most
populated cities. To travel to different places within the city is becoming more difficult for the
travellers in traffic. Due to these congestion problems, people lose time, miss opportunities, and
get frustrated. Traffic congestion directly impacts the companies. Due to traffic congestions there
is a loss in productivity from workers, trade opportunities are lost, delivery gets delayed, and
thereby the costs goes on increasing.
To solve these congestion problems, we have to build new facilities & infrastructure but at the
same time make it smart. The only disadvantage of making new roads on facilities is that it
makes the surroundings more congested. So for that reason we need to change the system rather
than making new infrastructure twice. Therefore many countries are working to manage their
existing transportation systems to improve mobility, safety and traffic flows in order to reduce
the demand of vehicle use.
The project uses simple Electronic components such as LED as Traffic Light indicator and a
Microcontroller for auto change of signal after a pre-specified time interval.
Microcontroller PIC16F877A is the brain of the project which initiates the traffic signal at a
junction. The LEDs are automatically on and off by making the corresponding port pin of the
micro controller high. A seven segment display also connected to display the timing of each
signal. At a particular instant only one green light holds and other lights hold at red. During
transition from green to red, the present group yellow led and succeeding group yellow led glows
and then succeeding group led changes to green. This process continues as a cycle.

Haramaya university institute of technology, HRUiT Page 1


Semester project Design and simulation of traffic light control using microcontroller

In our research we focus on optimization of traffic light controller in a city using IR sensor
and developed visual monitoring using microcontroller PIC16F877A.roadwork and accidents
further influence complexity and performance. In this paper, we propose two approaches, the
first approach to take data/input from object or vehicle with using IR sensor and in the second
approach to process the input data by Microcontroller and finally display it on the traffic light
signal to control the Closed Loop System.
1.2 Brief description
The project uses simple electronic components such as LED as Traffic Light indicator, a seven
segment display, Infra-red (IR) sensor and a Microcontroller for auto change of signal after a
pre-specified time interval. Figure shows the drawing of the 4-way junction, where each way
has its traffic light and counter.

Figure1.1- General 4-Way Traffic


 Microcontroller PIC 16F877A is the brain of the project which initiates the traffic signal
at a junction. LEDs used are red, yellow and green
Red LED indicates “stop driving”
Yellow LED indicates “start stopping”
Green LED indicates “Drive”.
The sequence of altering the LEDs according to their colour is as shown in the figure below:
green-yellow-red-green. Twelve LEDs are used; three to each traffic light.

Haramaya university institute of technology, HRUiT Page 2


Semester project Design and simulation of traffic light control using microcontroller

Fig 1.2 Sequence of LED


The LED’s are automatically on and off by making the corresponding port pin of the micro
controller high. Furthermore associated is the right turn green lights which are on for the first 10
seconds of the total green light time.

Figure1.3 cycle for the traffic light


7-segment LED displays are used to show the current count value. Since all of the traffic lights
are working simultaneously, each one is to display a different digit than the other. When a traffic
light is tuned green, its corresponding 7-segment displays start counting down from a specific
value and decrements until zero is reached. After this the counter starts by a new count value at
the moment the yellow light turns on. When the red light turns on after the yellow took its time,
the count continues to decrement until reaching zero. This means that the same 7-segments, on
each traffic light, are used to display the count when cars are allowed and not allowed to pass. In
terms of counting, the yellow and red are considered one set while the green is another set. The
circuit board designed supports in-circuit serial programming (ICSP) for the PIC. This support
eases the way to the designer to program the microcontroller without the need to plug the
microcontroller in and out repeatedly.
The following flow represents the sequence of operation done by the signal.
 Each sensor transmits the status periodically to the controller.
 Controller receives the signals and computes the following: - Check all counters how
many vehicles are there then give command signal for each traffic light sequence ally.

Haramaya university institute of technology, HRUiT Page 3


Semester project Design and simulation of traffic light control using microcontroller

Figure1.4 Circuit Block Diagram

Figure 1.5 Working Principle

1.3 Statement of a problem


In the conventional traffic light controller, the duration allocated for each junction is at a constant
cycle time, which is clearly not the optimal solution. Using this system, traffic light cycle time is
fixed without care the traffic flow at the time. For example, when the traffic flow at the main
road is in low condition and the traffic flow at the side road is in high condition, the traffic cycle
still in the fixed time. The green light at the main road usually is set in a long period but the side
road usually is set in a short period. It makes the side road being congested and sometimes the
vehicles stuck at the centres of the intersection. The conventional traffic light controller system

Haramaya university institute of technology, HRUiT Page 4


Semester project Design and simulation of traffic light control using microcontroller

uses the programmable logic controller (PLC). The problem of PLC is the cost of the controller
set is expensive. It’s make the traffic light at one intersection become expensive. Besides, the
PLC system needs other component for example, CPU, and I/O card, to support the system. PLC
also needs the 24VDC to operate and it makes the electricity cost become expensive.
1.4 Objective
1.4.1 General objective
The general objective of this project is to design traffic light controller using microcontroller to
control the flow of traffic at the intersection.
1.4.2 Specific Objective
 To know how micro controller unit is implemented to design traffic light
controller with other elements.
 To design how traffic light control is operated.
 To design how seven segments displayed is implemented for traffic light
controller.
 To design timing of the signal clock.
1.5 Significance of the study
 To build a circuit to facilitate the movement of traffic in a 4-way lane system
 To reduce the waiting time
 Study the problem of Conventional traffic system
 Develop the programmed of traffic light microcontroller using PIC basic pro
 Implement the circuit on design on circuit board or system on a model of a traffic light.
 Solve the conventional traffic light congesting problem
 Reduce traffic light controller cost
1.6 Scope and limitation of the project
The scopes of project study are:-
 Designing the traffic light controller circuit and programming of the PIC 16F designing
 Construct a model of four way junction of a traffic light model
 Solving the congestion at the side roads
 Sensors are implemented in the side road to detect how many vehicles are their
 Combine the software part and the hardware part to simulate a traffic light system
Limitation of the project are:-

Haramaya university institute of technology, HRUiT Page 5


Semester project Design and simulation of traffic light control using microcontroller

1.7 Methodology
We have used different methodologies in order to achieve the objectives of this project. The
methodology used in this system is the fundamental and decisive part to design traffic light
system. This involves in under taking comprehensive study from the information gathered and
reference materials. The methodology in this system basically consists of data collections and
Analysis methods.
• Data collection:-it is an important aspect of any type of project. First we obtain the
necessary information and data about the existing traffic light from traffic police at
KETENA Street then we make the information to go with what we are learnt. Even
though our project can applicable in everywhere at the street intersection we focused
on one of the place found in HARAR town which is one of the places with dense
vehicles KETENA. At the place as we have discussed with some police traffic, car
owner and commuter, they confirm that as there are many problems that caused due to
traffic cognition like; loss of life, becoming injury, destruction of resource and also
spending unnecessary time on the road that must be applicable for other considerable
job.
• Analysis method:-The new designed traffic light system is analysed by using
Proteus and micro C software, in such manner, Proteus is for circuit analysis and
micro C is for programming the circuit in C language.
 And also this project is supported by:

1. Theoretical analysis
2. Advisor suggestion
3. Materials like:-
voltage regulator(IC 7805)
microcontroller unit
Decoder (74LS47)
Crystal oscillator
Berg connector
Resistor
infra-Red (IR) sensors
Capacitor
Power supply
LED’s etc.
Transistor
4. Proteus simulation

Haramaya university institute of technology, HRUiT Page 6


Semester project Design and simulation of traffic light control using microcontroller

5. Seven segment display


6. Questionnaires for the intended person
1.8 Overview of the project
This project contains five chapters in it, they estates how traffic light controller is implemented
and why it so important. Let’s see each chapter the first chapter’s deals about introduction of the
project which is give some ideas why the project is needed and the significance of traffic
light control. The second chapter talks about literature review of the paper, estates brief
explanation of the components of hard ware part of the project and try to compare the previous
work with this project. The third chapter deals about the design part and the fourth chapter states
about how it implementation with schematic diagram. The fifth chapter talks about result
and analysis in both table and pseudo code. The six chapter talks about conclusion and
recommendation.
1.9 Flow chart

Fig 1.6 flow chart

Haramaya university institute of technology, HRUiT Page 7


Semester project Design and simulation of traffic light control using microcontroller

CHAPTER TWO
1. LITERATURE REVIEW
This chapter will discuss literature review of this project. The content of literature review is one
of the important steps to gather information about the project. Literature review will explore the
basic history and evolution of traffic light system, microcontroller review especially PIC
16F877A and PIC programming that is used in this project.
2.1 The traffic light system
Traffic light system consists of two parts. First part is traffic light the second part is controller
unit. Traffic light is used to control traffic flow at the busy intersection.
2.1.1 Traffic light objectives
 Save and efficient traffic flow
 Assign right of way to maximize delay and reduce conflict.
2.1.2 Advantages of traffic light
 Provide orderly movement of traffic
 Minimize conflicting movement.
 Increase traffic handling capacity
 Mean of interrupting heavy traffic.
 Coordinated for continuous movement.
 Provide driver confidence by assigning the right ways.
2.1.3Traffic light history
Ever since Roman times, society has tried to control traffic. Even the fabled Roman road system
created a conflict between pedestrian and equine travellers. However, a practical solution was
not developed until the mid-nineteenth century, when J. P. Knight, a railway signalling engineer,
created the first traffic signal, which was installed near Westminster Abbey in London, England
in 1868. Unfortunately, the device exploded, killing a police officer, and its use was discontinued
after being in operation for only a short time. The modern traffic light was invented in America.
New York had a three colour system in 1918 that was operated manually from a tower in the
middle of the street. Other cities soon adopted the idea of having someone on the scene to control
the lights. Garrett Morgan, inventor of the gas mask, also developed traffic signalling devices.
Having witnessed an accident between a car and a carriage, Morgan felt compelled to devise a

Haramaya university institute of technology, HRUiT Page 8


Semester project Design and simulation of traffic light control using microcontroller

system to prevent such collisions at street intersections. In 1923 he patented an electric traffic
light system using a pole with a cross section on which the words STOP and GO were
illuminated. These basic designs were soon improved. In 1926 the first automatic signals were
installed in London; they depended on a timer to activate them. In the 1930s vehicle activated
lights were created in which cars rolled over half-buried rubber tubes. Air in the tubes was
displaced by the weight of the car rolling over them, and the increased pressure operated an
electric contact, activating the lights. But these tubes wore out quickly. A better idea was the
inductive-loop device: a loop of wire was imbedded in the road itself and connected to a box
controlling the lights; a current of electricity passed through the loop, and when the steel body of
a car passed overhead, it produced a signal that activated the light. Today, traffic is automatically
routed onto limited access highways courtesy of a computer activated guidance system that
determines traffic volume on the highway. Global positioning satellite systems (GPS) are
installed in many cars. These systems connect with a satellite and inform drivers where they are
and possible routes to their destination. Such systems will eventually enable a drive to determine
the best route to a destination given prevailing traffic conditions.
2.2 PIC Microcontrollers
The term PIC stands for Peripheral Interface Controller .It is the brain child of Microchip
Technology, USA. Originally this was developed as a supporting device for PDP computers to
control its peripheral devices, and therefore named as PIC, Peripheral Interface Controller. They
have coined this name to identify their single chip micro controllers. These 8-bit micro
controllers have become very important now a day in industrial automation and embedded
applications etc.
2.2.1 Overview and Features
 The PIC 16F8XX Microcontrollers are basically RISC microcontrollers with very small
instruction set of only 35 instructions and a two-stage pipeline concept fetch and
execution of instructions. As a result, all instructions execute in a single cycle except for
program branches.
 PIC 16F877A is a 40-pin 8-Bit CMOS FLASH Microcontroller. The core architecture is
high-performance RISC CPU. Since it follows the RISC architecture, all single cycle
instructions take only one instruction cycle except for program branches which take two
cycles.

Haramaya university institute of technology, HRUiT Page 9


Semester project Design and simulation of traffic light control using microcontroller

 16F877A comes with 3 operating speeds with 4, 8, or 20 MHz clock input. Since each
instruction cycle takes four operating clock cycles, each instruction takes 0.2 μs when
20MHz oscillator is used.
 It has two types of internal memories .One is program memory and the other is data
memory. Program memory is provided by 8K words (or 8K*14 bits) of FLASH Memory,
and data memory has two sources. One type of data memory is a 368-byte RAM (random
access memory) and the other is256-byte EEPROM (Electrically erasable programmable
ROM).
 The core features include interrupt up to 14 sources,
 power saving SLEEP mode,
 A single 5V supply and In-Circuit Serial Programming (ICSP) capability.
2.2.2 Architecture of PIC 16F877A

Figure 1.1- Architecture of PIC16F877A microconteroller

Haramaya university institute of technology, HRUiT Page 10


Semester project Design and simulation of traffic light control using microcontroller

2.2.3 PIC Features


Memory Organization
The memory module of the PIC controller has three memory blocks.
a) Program Memory: The PIC 16F8XX has 4k x14 program memory space (0000H-0FFFH).It
has a 13 bit Program counter(PC) to access any address (213=4k). This PIC family uses 13-bit
program counter allowing the controllers to an 8k-program memory without changing the CPU
structure.
b) Data memory: The data memory of PIC 16F8XX is partitioned into multiple banks which
contain the general purpose registers and the Special function Registers. (SFRs).The bits RP1
and RP0 bits of the status register are used to select these banks. Each bank extends up to 7FH
(128 Bytes).The lower bytes of the each bank are reserved for the Special Function Registers.
Above the SFRs are general purpose registers implemented as static RAM.
Register File Structure
In PIC Microcontrollers the Register File consists of two parts namely
a) General Purpose Register File
b) Special Purpose Register
Parallel I/O Ports
Most of the PIC16cx/7x family controllers have 33 I/O lines and five I/O ports They are PORT
A, PORT B, PORT C , PORT D and PORT E.

What is the purpose of PORT’ S


 PORT A: Port A is a 6-bit wide bi-directional port. Its data direction register is TRISA
setting TRISA bit to 1 will make the corresponding PORTA Pin an input. Clearing a
TRIS a bit will make the corresponding pin as an output.
 PORT B: Port B is an 8-bit wide, bi-directional port. Four of the PORT B pins RB7 –
RB4 have an interrupt-on- change feature. Only the pins configured as inputs can cause
this interrupt to occur.
 PORT C: Port C is an 8-bit wide, bidirectional port. Bits of the TRISC Register
determine the function of its pins. Similar to other ports, a logic one 1 in the TRISC
Register configures the appropriate port pin as an input.

Haramaya university institute of technology, HRUiT Page 11


Semester project Design and simulation of traffic light control using microcontroller

 PORT D: Port D is an 8-bit wide bi-directional port. In addition to I/O port, Port D also
works as 8-bit parallel slave port or microprocessor port. When control bit PSPMODE
(TRISE: 4) is set.
 PORT E: It is a 3-bit bi-directional port. Port E bits are multiplexed with analog inputs of
ADC and they serve as control signals (RD, WR and CS) for parallel slave port mode of
operation.
Addressing Modes
The PIC microcontrollers support only TWO addressing modes .They are,
(i) Direct Addressing Mode
(ii) Indirect Addressing mode Direct Addressing Mode In direct addressing mode 7 bits
(0-6) of the instruction identify the register file address and the 8th bit of the register
file address register bank select bit (RP0).
Instruction Set
The instruction set of PIC is divided into three basic categories. They are:
(a) Byte oriented Instructions
(b) Bit oriented Instructions
(c) Literal and Control Instructions
Classification of Instructions
(i) Arithmetic Operations
(ii) Logical Instructions
(iii) Increment/Decrement Instructions
(iv) (iv) Data Transfer instructions
(v) Clear Instructions
(vi) Rotate Instructions
(vii) Branch Instructions
PIC I/O Programming (Programming the Ports)
The PIC 16F family of microcontrollers has a total of 33 pins arranged into 5 ports. Port A, Port
B, Port C, Port D and Port E. In order to use them as I/O ports, they must be properly
programmed. In addition to acting as I/O ports, they also have certain additional functions like
ADC, Timers, Interrupts and serial communication pins etc.

Haramaya university institute of technology, HRUiT Page 12


Semester project Design and simulation of traffic light control using microcontroller

Limitations
The PIC architectures have these limitations:
o One accumulation
o Register-bank switching is required to access the entire RAM of many devices
o Operations and registers are not orthogonal; some instructions can address RAM
and/or immediate constants, while others can only use the accumulator Stack
limitations:
o The hardware call stack is not addressable, so pre-emptive task, switching cannot
be implemented.
o Software-implemented stacks are not efficient, so it is difficult to generate re-
entrant code and support local variables

Haramaya university institute of technology, HRUiT Page 13


Semester project Design and simulation of traffic light control using microcontroller

CHAPTER THREE
DESIGN HARDWARE AND SOFTWARE DEVELOPMENT
In this chapter we will discuss about all the design and implementation of the traffic light control
using microcontroller.
Numerous hardware development tools are available for the PIC16 microcontrollers. Some of
these products are manufactured by Microchip Inc., and some by third-party companies. The
most ones are:
 Development boards
 Device programmers
 In-circuit debuggers
 In-circuit emulators
 Breadboards
3.1 Hardware component
3.1.1Voltage regulator (IC 7805)

Figure 3.1-IC 7805 Features


It maintains a constant voltage level independent of load condition or variation in the amplitude
of the AC supply .An example of regulator is LM78xx series. It is the three terminal devices with
input (1), ground (2), and output (3) as its terminals. The voltage required for micro controller is
5V. Hence LM7805 voltage regulator is used.
 IC 7805 is a 5V Voltage Regulator that restricts the voltage output to 5V and draws
5V regulated power supply.
 It comes with provision to add heat sink. The maximum value for input to the
voltage regulator is 35V.
 It can provide a constant steady voltage flow of 5V for higher voltage input till the
threshold limit of 35V.
 If the voltage is near to 7.5V then it does not produce any heat and hence no need
for heat sink. If the voltage input is more, then excess electricity is liberated as heat
from 7805.
Haramaya university institute of technology, HRUiT Page 14
Semester project Design and simulation of traffic light control using microcontroller

 It regulates a steady output of 5V if the input voltage is in rage of 7.2V to 35V.


Hence to avoid power loss try to maintain the input to 7.2V.
3.1.2 Seven Display Segment
 Four common anode 7-segment displays are used in this 4-way traffic light control
system. Figure 4.2 shows a segment LED display and its pin description.
 It is a 10-pin display device. The pins are: a, b, c, d, e, f, g, DP (dot) and com. The pins
labelled as “com” are internally connected to each other.
 The digits displayed in every 7-segment range from 0 to 9. Since the required numbers to
display are more than 9, two 7-segment LED displays (left and right) were used for every
traffic light and this is why 4 displays were used in this project (a pair for each opposite
lanes). The data pins (a, b, c, d, e, f and g) for the left and right displays in every strip
board are connected to each other because they are multiplexed.
 Multiplexing is made by using a 3 to 8 decoder.
The IC (74LS47) is used to select which 7 segment to show the digit. This chip has 4 input
pins labelled A, B and C and 8 output pins labelled. The input pins are connected to the
microcontroller for it to select which 7 segment to light up.

Figure 3.2- Seven Segment Display

Haramaya university institute of technology, HRUiT Page 15


Semester project Design and simulation of traffic light control using microcontroller

Table 1- Hex Codes To Display Various Digits

3.1.3 Resistor
A resistor is a passive two-terminal electrical component that implements electrical resistance as
a circuit element. In this circuit 330 ohm and 10 k ohm resisters are used.

Figure 3.3 Resistor


3.1.4 Capacitor
A capacitor (originally known as a condenser) is a passive two-terminal electrical component
used to store energy electrostatically in an electric field. This circuit uses a 2 μF capacitor.

Figure 3.4 Capacitor


3.1.5 Berg connector
A Berg connector is a brand of electrical connector used in computer hardware.

Haramaya university institute of technology, HRUiT Page 16


Semester project Design and simulation of traffic light control using microcontroller

3.1.6 Oscillator
An electronic oscillator is an electronic circuit that produces a repetitive, oscillating electronic
signal, often a sine wave or a square wave. Oscillators convert direct current (DC) from a power
supply to an alternating current signal. This circuit uses a 2 MHz oscillator.

Figure 3.5 Oscillator


3.1.7 LED
Light emitting diodes (LEDs) are semiconductor light sources. The light emitted from LEDs
varies from visible to infrared and ultraviolet regions. They operate on low voltage and power.
LEDs are one of the most common electronic components and are mostly used as indicators in
circuits. They are also used for luminance and optoelectronic applications. Three colours of LED
are used in this project.

Figure 3.3 - Light Emitting Diode


Principle:
When a light-emitting diode is forward biased electrons are able to recombine with electron
holes within the device, releasing energy in the form of photons. This effect is called
electroluminescence. Electroluminescence (EL) is an optical and electrical phenomenon in which
a material emits light in response to the passage of an electric current or to a strong electric field.
The wavelength of the light emitted, and thus its colour depends on the band gap energy of the
materials forming the p-n junction. The materials used for the LED have a direct band gap with
energies corresponding to near-infrared, visible or near-ultraviolet light.

Haramaya university institute of technology, HRUiT Page 17


Semester project Design and simulation of traffic light control using microcontroller

Figure 3.7 Operation of LED

3.1.8 PIC 16F877A Microcontroller

Figure 3.8 PIC16F877A microcontroller


The microcontroller unit (MCU) is now big, or rather small, in electronics. It is one of the most
significant developments in the continuing miniaturization of electronic hardware.
There is no escape from microcontrollers, so it is pretty useful to know how they work. The
computer or digital controller has three main elements: input and output devices, which
communicate with the outside world; a processor, to make calculations and handle data
operations; and memory, to store programs and data.
Unlike the conventional microprocessor system (such as a PC), which has separate chips on a
printed circuit board, the microcontroller contains all these elements in one chip. The MCU is

Haramaya university institute of technology, HRUiT Page 18


Semester project Design and simulation of traffic light control using microcontroller

essentially a computer on a chip; however, it still needs input and output devices, such as a
keypad and display, to form a working system.
The range of microcontrollers now available developed because the features of the MCU used in
any particular circuit must be as closely matched as possible to the actual needs of the
application. Some of the main features to consider are
• Number of inputs and outputs.
• Program memory size.
• Data RAM size.
• Non-volatile data memory.
• Maximum clock speed.
• Range of interfaces.
• Cost and availability.
The PIC16F877A is useful as a reference device because it has a minimal instruction set but a
full range of peripheral features. PIC16F877 is a 40-pin 8-Bit CMOS FLASH Microcontroller
from Microchip. PIC16F877A comes with 3 operating speeds with 4, 8, or 20 MHz clock input.
It has two types of internal memories: program memory and data memory. Program memory is
provided by 8K words (or 8K*14 bits) of FLASH Memory, and data memory has two sources.
One type of data memory is a 368-byte RAM (random access memory) and the other is256-byte
EEPROM (Electrically erasable programmable ROM).
The core feature includes interrupt capability up to 14 sources, power saving SLEEP mode, and
single 5V In-Circuit Serial Programming (ICSP) capability. The sink/source current, which
indicates a driving power from I/O port, is high with 25mA. Power consumption is less than
2mA in 5V operating condition.
Basic digital input and output (I/O) in the microcontroller uses a bidirectional port pin. The
default pin configuration is generally digital input, as this is the safest option if some error has
been made in the external connections. To set the pin as output, the corresponding data direction
bit must be cleared in the port data direction register (e.g., TRISD).
For input, the current driver output is disabled by loading the data direction bit with a 1, which
switches off the tristate gate. Data are read into the input data latch from the outside world when
its control line is pulsed by the CPU in the course of a port register read instruction. The data are
then copied to the CPU working register for processing. When the port is set up for output, a 0 is

Haramaya university institute of technology, HRUiT Page 19


Semester project Design and simulation of traffic light control using microcontroller

loaded into the data direction bit, enabling the current output. The output data are loaded into the
data latch from the CPU. A data 1 at the output allows the current driver to source up to 25 mA
at 5 V. A data 0 allows the pin to sink a similar current at 0 V.
3.1.9 Infra-Red (IR) Sensors
Basically the quantities to be measured are Non-Electrical quantities such as temperature,
pressure, displacement, humidity, fluid flow, speed etc., but these quantities cannot measure
directly. Here we had been used the Infra-Red sensor. It is used to count the vehicles. If the
vehicle cut the signal between the transmitter and receiver, the sensor send signal to the
microcontroller.

Figure 3.9-IR sensor


3.1.10 Decoder (74LS47)
The DM74LS47 accepts four lines of BCD (8421) input data, generates their complements
internally and decodes the data with seven AND/OR gates having open-collector outputs to drive
indicator segments directly. Each segment output is guaranteed to sink 24 mA in the ON (LOW)
state and withstand 15V in the OFF (HIGH) state with a maximum leakage current of 250 mA.
Auxiliary inputs provided blanking, lamp test and cascadable zero-suppression functions.

Figure 3.10 74LS47 Decoder

Haramaya university institute of technology, HRUiT Page 20


Semester project Design and simulation of traffic light control using microcontroller

Figure 3.11 - Decoder (74LS47) (a) connection diagram (b) pin description

Figure 3.12- Logic Diagram and Output of 74LS47


3.1.11 Transistor
A transistor is an electronic control device, where an electrical signal input can control another
electrical signal. The very name derives from the fact that this control action was seen as an input
current flowing into one resistor (base-emitter) causing a larger current in another resistor
(collector-emitter). The early named for this device was the transfer-resistor and hence
transistor.
In digital circuits, transistors are always used as a switch. Like a common light switch, the ideal
digital transistor is, at any one instant, either "off" with zero current flowing through it, or "on"
with nearly zero voltage across it. There are occasional transitions between the two states, but in
this book we ignore the details of what happens during the transition.

Haramaya university institute of technology, HRUiT Page 21


Semester project Design and simulation of traffic light control using microcontroller

Figure 3.13 - Transistor

3.1.12 PICKIT 2 USB Programmer

Figure 3.14 -PICit 2 pin diagram


Features:
 Separate programmer/debugger unit which plugs into the board carrying the chip to be
programmed.
 The PICkit 2 is open to the public, including its hardware schematic, firmware source
code and application programs.
 Programmer-To-Go: Set up a PICkit 2 to program a device without the need for a PC.
 128K byte memory.
 Easy to use with MIKROC® IDE and other development environments.
 Includes the UART Tool and Logic Tool microcontroller development utilities.
The PICkit 2 Programmer application allows you to program all supported devices listed in the
PICkit 2 Readme file.
3.1.13 Power Supply
Almost all electronic circuits required DC power supply. DC power supply is a circuit which
converts the AC wave form of power lines to direct voltage of constant amplitude. An ideal
regulated power supply is designed to provide a pre- determined DC voltage which is

Haramaya university institute of technology, HRUiT Page 22


Semester project Design and simulation of traffic light control using microcontroller

independent of the current drawn from the source. These circuits are special class of feedback
amplifiers. All the benefits of 'ICs' are thus obtained: excellent performance, small size, ease of
use, low cost, high and reliability. An unregulated power supply has many disadvantages due to
which it is not sufficient for many applications;

• Poor regulation,

• DC output voltage varies with the AC input,

• DC output voltage variation varies with temperature because of semi-conductors used. To


overcome the above disadvantages we depend up on regulated power supply. Regulated
power supplies have internal short circuit protection, thermal shut down and safe
operation of output transistor.

3.2 Software design


In this section we will see about the overall software and design of the traffic light control using
microcontroller.
3.2.1 Software development tools
The tools for developing software and hardware for microcontroller-based systems include
editors, assemblers, compilers, debuggers, simulators, emulators, and device programmers. A
typical development cycle starts with writing the application program using a text editor. The
program is then translated into an executable code with the help of an assembler or compiler. If
the program has several modules, a linker is used to combine them into a single application. Any
syntax errors are detected by the assembler or compiler and must be corrected before the
executable code can be generated. Next, a simulator is used to test the application program
without the target hardware. Simulators are helpful in checking the correctness of an algorithm
or a program with limited or no input-outputs, and most errors can be removed during
simulation. Once the program seems to be working and the programmer is happy with it, the
executable code is loaded to the target microcontroller chip using a device programmer, and the
system logic is tested. Software and hardware tools such as in-circuit debuggers and in-circuit
emulators can analyse the program’s operation and display the variables and registers in real time
with the help of breakpoints set in the program. Software development tools are computer
programs, usually run on personal computers that allow the programmer (or system developer) to
create, modify, and test applications programs.

Haramaya university institute of technology, HRUiT Page 23


Semester project Design and simulation of traffic light control using microcontroller

Some common software development tools are:


 Text editors
 Assemblers/compilers
 Simulators
 High-level language simulators
 Integrated development environments (IDEs)
3.2.2 Software used
Micro C Pro
Micro C is a powerful, feature rich development tool for PIC micros. It is designed to provide the
customer with the easiest possible solution for developing applications for embedded systems,
without compromising performance or control. PIC and C fit together well: PIC is the most
popular 8-bit chip in the world, used in a wide variety of applications, and C, prized for its
efficiency, is the natural choice for developing embedded systems. Micro C provides a
successful match featuring highly advanced IDE, ANSI complaint compiler, broad set of
hardware libraries, comprehensive documentation, and plenty of ready-to-run applications.
Micro C allows us to quickly develop and deploy complex applications:
 Writing C code using highly advanced Code Editor
 It includes design libraries to dramatically speed up the development: data
acquisition, memory, displays, conversions, and communications.
 Monitoring program structures, variables and functions in the code explorer.
Generates commented, human readable assembly, and standard HEX compatible
with all programmers.
 Inspecting program flow and debugging executable logic with the integrated
debugger. Similar Getting detailed reports and graphs on code statistics, assembly
listings, calling tree.

Haramaya university institute of technology, HRUiT Page 24


Semester project Design and simulation of traffic light control using microcontroller

Figure 3.15 -Micro C Pro Window


Proteus 8 EDA
Proteus v8 is software for microprocessor simulation, schematic capture, and printed circuit
board (PCB) design. It is developed by Lab enter Electronics.
System components:
 ISIS Schematic Capture - a tool for entering designs.
 PROSPICE Mixed mode SPICE simulation - industry standard SPICE3F5 simulator
combined with a digital simulator.
 ARES PCB Layout - PCB design system with automatic component placer, rip up and
retry auto-router and interactive design rule checking.
 VSM - Virtual System Modelling lets co-simulate embedded software for popular
micro-controllers alongside hardware design.
 System Benefits Integrated package with common user interface and fully context
sensitive help.

Haramaya university institute of technology, HRUiT Page 25


Semester project Design and simulation of traffic light control using microcontroller

Proteus Design Procedure

Figure 3.16 -Proteus 8 starting window

Figure 3.17 -Proteus blank area

Figure 3.18 -Proteus device selection

Haramaya university institute of technology, HRUiT Page 26


Semester project Design and simulation of traffic light control using microcontroller

Other general features include:


 Runs on Windows 2k and XP.
 Automatic wire routing and dot placement/removal.
 Powerful tools for selecting objects and assigning their properties.
 Total support for buses including component pins, inter-sheet terminals, module ports
and wires.
 Bill of Materials and Electrical Rules Check reports.
 Net list outputs to suit all popular PCB layout tools. How to create & simulate design in
Proteus ISIS?
 Firstly prepare a code having required function implementation & prepare its “Hex File”.
 Open Proteus; go to “File” then “New Design” then select template (see fig. 3.15).
3.3 System design and implementation
 Now we are reaching at the implementation (simulation) phase of our project. At this
stage we are going to discuss the all system.
 The overall circuit diagram of the traffic light controller using the microcontroller is
shown below.

Figure 3.19 Overall design

Haramaya university institute of technology, HRUiT Page 27


Semester project Design and simulation of traffic light control using microcontroller

As we have seen in the above topic, the traffic light control using microcontroller needs to design
and implementing properly.
The first thing to design the project is starting the flow chart is shown in figure (1.6). The
concept of the project is clearly seen in the flow chart. Let as discuss about the steps clearly.
 The voltage regulator takes the voltage at a range of 7 to 35 volt. But we have to give
12V as average volt and also the regulator take the ground. It is known that the output
voltage is +5V. Then this volt is applied for all pins that have need the supply voltage,
like decoder, M.C, 7-segment …
 From the microcontroller all of PORTA pins are interrupted. So it has to connect to the
sensor.
 PORTD is connected to the decoders. It is used to show how many seconds green light is
glow. Already the microcontroller counts HEXA decimal. The decoder is converted to
seven segments.
 PORTB and PORTC have connected to the LED through the 330 ohm resistors.
 The LED gets the supply voltage from the transistor. The transistor gets the power to
generate by its base pin from the microcontroller of PORTE. Then it will be generate.
 Pins 13 & 14 of the PIC are connected to the Oscillator circuit and Crystal which
consisting of 8MHz crystal connected to two 22 pFcapacitors. The oscillator circuit has
been used to provide a microcontroller with a clock, so that the microcontroller can
execute a program.
3.3.1 Design Calculation
Since our project is to count the number of vehicles and vary the seconds to glow the green light.
So between the traffic light and the sensor that send the signal data must have some distance. We
can adjust the limit of the number of the vehicles by adjusting the distance.
Before that what is the length of the vehicle?
There are many vehicles that are different by size (length). In Harar town, we can separate the
vehicles depending on their length, in to three parts.
 The minimum length of the vehicles, about 1.5 meters and near to this.
 The middle length of the vehicles, about 3 meters and near to this.
 The maximum length of the vehicle, about 7 meters and near to this.

Haramaya university institute of technology, HRUiT Page 28


Semester project Design and simulation of traffic light control using microcontroller

From the data’s 40% of the vehicles is minimum length. 50% of those are middle, and also 10%
is large.So we can calculate first the average length of the vehicles.

L = 1.5*40% + 3*50% + 7*10%

L = 60/100 +150/100 + 70/100

= 0.6 + 1.5 + 0.7=2.8 meters


Since the average vehicle length is 2.8 m, and the gap between each cascaded vehicle is 0.2m,
then the overall distance in a vehicle is 3meters.
So if we want to cascade ten vehicles, the sensor must put about 30 meters long from the traffic
light. In this project, the distance is 30 meters. Because of the road in the Harar town is so short.
Depending on the road you can vary the distance of the sensor from the traffic light.
3.3.2 Software implementation
 Using pic16f877A microcontroller allows us to quickly develop and deploy complex
application writing C code using highly advanced code editor the development of data
acquisition memory displays conversion communication monitoring program structure,
variable and functions in code explorer. Generates commented human readable assembly
standard HEX compatible with all programs. Inspecting program flow and debugging
executable logic with the integrated debugger getting detailed reports and graphs on code.
Statistics assembly listings calling tree how it use micro pro. Open micro C go to” file”
then” new “ for new project or “open” for old project then write code for the required
application then go to build to compile the file and create the hex file to be loaded into
the microcontroller select the “run” option to starts the debugging process and the
program.

Haramaya university institute of technology, HRUiT Page 29


Semester project Design and simulation of traffic light control using microcontroller

 Connection circuit diagram for Proteus


The usable connection diagram of the traffic light control using microcontroller is shown below

Figure 3.20 – Design and simulation of traffic light control using microcontroller
 Coding
Finally the Proteus design has needed the source code. So, the final code is shown below.
int i,a;
char portbdata,portbpriv;
void sensor(char input)
{
}
void interrupt(void)
{
portbdata=portb;
a=!a;
if(a)
sensor(portbdata);
INTCON.RBIF=0;
}
void main()
Haramaya university institute of technology, HRUiT Page 30
Semester project Design and simulation of traffic light control using microcontroller

{
char i,b,temp;
char
dat[]={0x40,0x39,0x38,0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x30,0x29,0x28,0x27,0x26,0x25,
0x24,0x23,0x22,0x21,0x20,0x19,0x18,0x17,0x16,0x15,0x14,0x13,0x12,0x11,0x10,0x09,0x08,0
x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00};
INTCON.GIE=1;
INTCON.RBIE=1;
INTCON.RBIF=0;
TRISA=0X01;
TRISB=0X00;
TRISC=0X00;
TRISD=0X00;
while(1)
{
a=0x50;
PORTB=0x1c;
PORTD=0x11;
for(i=0;i<=14;i++)
{
PORTD=a;
a=a--;
delay_ms(100);
if(a==0x2F||a==0x1F||a==0x0F||a==0x3F||a==0x4F)
{
a=a-6;
}
}
PORTB=0x14;
PORTC=0x11;
for(i=14;i<=49;i++)

Haramaya university institute of technology, HRUiT Page 31


Semester project Design and simulation of traffic light control using microcontroller

{
PORTD=a;
a=a--;
delay_ms(100);
if(a==0x2F||a==0x1F||a==0x0F||a==0x3F||a==0x4F)
{
a=a-6;
}
}
PORTD=0x00;
PORTB=0x12;
a=0x05;
for(i=0;i<=4;i++)
{
PORTD=a;
a=a--;
delay_ms(100);
if(a==0x2F||a==0x1F||a==0x0F||a==0x3F||a==0x4F)
{
a=a-6;
}
}
a=0x50;
PORTB=0xc1;
PORTC=0x11;
for(i=0;i<=14;i++)
{
PORTD=a;
a=a--;
delay_ms(100);
if(a==0x2F||a==0x1F||a==0x0F||a==0x3F||a==0x4F)

Haramaya university institute of technology, HRUiT Page 32


Semester project Design and simulation of traffic light control using microcontroller

{
a=a-6;
}
}
PORTB=0x41;
PORTC=0x11;
for(i=14;i<=49;i++)
{
PORTD=a;
a=a--;
delay_ms(100);
if(a==0x2F||a==0x1F||a==0x0F||a==0x3F||a==0x4F)
{
a=a-6;
}
}
PORTD=0x00;
PORTB=0x21;
a=0x05;
for(i=0;i<=4;i++)
{
PORTD=a;
a=a--;
delay_ms(100);
if(a==0x2F||a==0x1F||a==0x0F||a==0x3F||a==0x4F)
{
a=a-6;
}
}
a=0x50;
PORTB=0x11;

Haramaya university institute of technology, HRUiT Page 33


Semester project Design and simulation of traffic light control using microcontroller

PORTC=0x1c;
for(i=0;i<=14;i++)
{
PORTD=a;
a=a--;
delay_ms(100);
if(a==0x2F||a==0x1F||a==0x0F||a==0x3F||a==0x4F)
{
a=a-6;
}
}
PORTB=0x11;
PORTC=0x14;
for(i=14;i<=49;i++)
{
PORTD=a;
a=a--;
delay_ms(100);
if(a==0x2F||a==0x1F||a==0x0F||a==0x3F||a==0x4F)
{
a=a-6;
}
}
PORTD=0x00;
PORTC=0x12;
a=0x05;
for(i=0;i<=4;i++)
{
PORTD=a;
a=a--;
delay_ms(100);

Haramaya university institute of technology, HRUiT Page 34


Semester project Design and simulation of traffic light control using microcontroller

if(a==0x2F||a==0x1F||a==0x0F||a==0x3F||a==0x4F)
{
a=a-6;
}
}
a=0x50;
PORTB=0x11;
PORTC=0xc1;
for(i=0;i<=14;i++)
{
PORTD=a;
a=a--;
delay_ms(100);
if(a==0x2F||a==0x1F||a==0x0F||a==0x3F||a==0x4F)
{
a=a-6;
}
}
PORTC=0x41;
PORTB=0x11;
for(i=14;i<=49;i++)
{
PORTD=a;
a=a--;
delay_ms(100);
if(a==0x2F||a==0x1F||a==0x0F||a==0x3F||a==0x4F)
{
a=a-6;
}
}
PORTD=0x00;

Haramaya university institute of technology, HRUiT Page 35


Semester project Design and simulation of traffic light control using microcontroller

PORTC=0x21;
a=0x05;
for(i=0;i<=4;i++)
{
PORTD=a;
a=a--;
delay_ms(100);
if(a==0x2F||a==0x1F||a==0x0F||a==0x3F||a==0x4F)
{
a=a-6;
}
}
}
}

Haramaya university institute of technology, HRUiT Page 36


Semester project Design and simulation of traffic light control using microcontroller

CHAPTER FOUR
2. RESULTS AND DISCUSSIONS
4.1 Results
The results are obtained from a specially made prototype shown in Figure 3.17. And they are
compared to that of standard versions of traffic light operations. Such basic systems usually have
predefined timing values. Here the results show that there is an improvement of approximately in
overall performance as compared to the conventional traffic controller.
Results include the successful operation of the Dynamic traffic light control. The IR sensor with
IR transmitter is placed at a gap. Gap acting as a prototype indicating a road. The system is
placed near to the side road as a standalone device. Whenever any obstacle like vehicle passes
between IR transmitter and IR sensor, microcontroller detects and increase number of vehicle
count in a recording interval for particular traffic light. IR sensors are placed at a distance about
40m so that the delay time of green and red light decision taken by microcontroller based on IR
sensors.
4.2 Discussions
This project can be enhanced in such a way as to automatically control the signals depending on
the traffic density on the roads using sensors like IR detector/receiver module extended with
automatic turn off when no vehicles are running on any side of the road which helps in power
consumption saving. The timing of green and red light at each crossing of road will be decided
by microcontroller based on the number of vehicles.

Haramaya university institute of technology, HRUiT Page 37


Semester project Design and simulation of traffic light control using microcontroller

CHAPTER FIVE
CONCLUSION AND RECOMMENDATION
5.1 Conclusion
In conclusion, this paper has successfully demonstrated an improved traffic controller and also we
have studied the optimization of traffic light controller using IR sensors and microcontroller.
Figure1 shows four ways traffic light model Figure2 shows the basic block diagram of the
system and figure4 shows the complete circuit diagram of microcontroller board. By using this
system configuration we tries to reduce the possibilities of traffic jams or congestion, caused by
traffic lights, to an extent and we have successfully gets the results. The witting time of green
light and red light decided basis of vehicle counts microcontroller based on the number of
vehicles detected by IR sensors.
The improvement of town traffic condition is largely dependent on the modern ways of traffic
management and control. Advanced traffic signal controllers and control system contribute to the
improvement of the traffic problem. The Dynamic traffic light controller is introduced in this
project with powerful functions and hardware interface. This project has two major phases. The
first stage is to design a program, which consists of reading, research, planning and designing a
program. Microcontroller Assembly Language was chosen to write a program code for
simulation only to get a timing diagram. After that, second phase is to continue with the
hardware implementation using the embedded system and the interface light is using LED. It is
observed that the proposed Dynamic Traffic Light Controller is more efficient than the
conventional controller in respect of less waiting time. Moreover, the designed system has
simple architecture, fast response time, user friendliness and scope for further expansion.
5.2 RECOMMENDATIONS
Basically, during at the project of our project there are a lot of things that we would have to
recommend.
 Recommendation for everybody who want to modify this system
Every good engineering design has limitation; the limitation of the developed system could be
improved upon by incorporating a density based traffic light controller into the developed
system. This will add a lot of functionality such as monitoring traffic flow depending on the
presence of the vehicle at each side, that save time and energy that loosed without any purpose

Haramaya university institute of technology, HRUiT Page 38


Semester project Design and simulation of traffic light control using microcontroller

during the journey. For future work, the system can also be linked to a database to keep track of
the traffic information using camera to control innocent vehicle crossing traffic light junction
during red light is glow and sending massage to traffic police by using GSM which is beneficial
for security purposes, pedestrian traffic management and air traffic control.
 Recommendation for the Department
We recommend to the department that, it is better to successfully design any project if there is a
budget that is spends to buy some necessary materials that used for the student to implement
practically.

Haramaya university institute of technology, HRUiT Page 39


Semester project Design and simulation of traffic light control using microcontroller

REEFERANCE
[1.] A. Albagul, M. Hrairi, Wahyudi and M. F. Hidayathullah, “Design and Development of
Sensor Based Traffic Light System”, American Journal of Applied Sciences, Vol. 3, No. 3,
pp. 1745-1749, 2006.
[2.] John B.Peatman, “PIC Microcontroller design”, 1st edition: Pearsons Education; 1997
[3.] Muhammad Ali Mazidi,“ PIC Microcontroller and Embedded systems”, 3rd edition:Pearsons
Education; 2007
[4.] Iovine John- PIC Microcontroller Project Book, 2nd Edition, Singapore: McGraw Hill 121-
123; 2000. Nd
[5.] Lawrence A. Duarte- The Microcontroller Beginner’s Handbook, 2 Edition, United States of
America: Prompt Publication. 3-5; 1998.
[6.] S. Rajeswari, “Design of Sophisticated Traffic Light Control System”, Middle-East
Journal of Scientific Research, Vol. 12, No 19, pp. 1647-1652, 2014.
[7.] PIC16F877A, 8 bit PIC microcontroller, http://www.microchip.com
[8.] http://robotaaly.blogspot.in/2013/02/traffic-light-control-system.html

Haramaya university institute of technology, HRUiT Page 40


Semester project Design and simulation of traffic light control using microcontroller

Appendix 1
Table 2 key features

Table 3microcontroller pins

Haramaya university institute of technology, HRUiT Page 41


Semester project Design and simulation of traffic light control using microcontroller

Table 4

Haramaya university institute of technology, HRUiT Page 42

You might also like