Dynamic Traffic Light Control Using Microcontroller: Industrial and Control Engineering

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 49

DYNAMIC TRAFFIC LIGHT CONTROL

USING MICROCONTROLLER
Submitted to Arba Minch University, Institute of Technology, Electrical and
Computer Engineering Department in partial fulfilment of the requirements
For
The award of degree of
B.Sc.
In

Industrial and control engineering


By

Amrellah Tewfik
Asseged Eshetu
Bereket Berhanu
Fuad Jemal
Muhammed Jemal

UNDER THE GUIDANCE OF

M.r Asrat Gedefa (Msc.)

Electrical and Computer Engineering Department

Arba Minch Institute of Technology

Arba Minch University

Arba Minch, Ethiopia

June 2014.
CERTIFICATE

This is to certify that the present work titled “…………………….” submitted by


………………………..in partial fulfilment of the requirements for the award of degree
of B.S.C, is a record of his original work carried out by him. He has worked under
my supervision and has fulfilled the requirement for the submission of this report.
The results presented in this work have not been submitted in part or full to any
other university for award of degree.

Date: June 23, 2014

Signature of Main Advisor:

Name of the Main Advisor:

i
Acknowledgement

It is a matter of great pleasure & privilege for us to present this report of minor project on “Traffic
light controller using PIC 16F877A”. Through this project report we would like to thank numerous
people whose consistent support and guidance has been the standing pillar in architecture of this
project.
We would like to thank our instructor Mr. H/Mareyam and Mr.Balak Krishnan for exposing us to
the world of Embedded Systems.
We would also like to thank our coordinators and add Advisores Mr. Asrat Gedefa and Dr.
Sunder Rajan for their enduring support and guidance throughout the project. We are very grateful
to the whole faculty for their support and guidance.
We are also thankful to Mr.Brhanu Oumer, overall project coordinator and Mr.Natnael Chutta,
Head of Department (Electrical and Computer engineering) Last but not the least, we are grateful to
the almighty for enabling us to present this project report as the outcome of our learning in this very
form.
Date June 23, 2014

Name ID e-mail Phone


Amrellah Tewfik RET/1516/02 amir.tewfik@yahoo.com +251910201905
Asseged Eshetu RET/775/02 eshetuassegid@gmail.com +251937334727
Bereket Berhanu RET/ 849/02 bereketberhanu@gmail.com +251919691709
Fahad Jemal RET/ 103/02 Fuad33jemal@gmail.com +251914130552
Muhammed Jemal RET/1394/02 mohjemal7@gmail.com +251913813832

ii
Abstract

Vehicular traffic at intersecting streets is typically controlled by traffic control lights. The function
of traffic lights requires sophisticated control and coordination to ensure that traffic moves as
smoothly and safely as possible. In recent days electro-mechanical controllers are replaced by
electronic circuits. The accuracy & fault tolerant drive towards electronic circuits. This project is
developed to meet the requirements of a 4-way solid state traffic lane by using a traffic light
controller with microcontroller as the main controlling element, and led ’s as the indication of light.
Our device provides an effective way to reduce the amount of waiting time of each commuter in
every lane of the 4-way road before he can pass the junction without risking the chance of accidents
during lane changes. A micro controller is interfaced to LEDs provide for centralized control of the
traffic signals. Microcontroller is programmed in such a way to provide their timing and phasing in
a fair manner to each lane. Two seven segment displays are used to display the count timings of
each light of opposite lanes. This project can be enhanced in such a way as to automatically control
the signals depending on the number of vehicles on the roads using sensors like IR detector/receiver
module extended with automatically. The circuit besides being reliable and compact is also cost
effective.

iii
Table of Contents
Acknowledgement ............................................................................................................................................. ii
Abstract ................................................................................................................................................................ iii
List of figure ........................................................................................................................................................ vi
List of table .......................................................................................................................................................... vi
Abbreviation ...................................................................................................................................................... vii
Chapter 1.......................................................................................................................................................................... 1
Introduction............................................................................................................................................................... 1
1.1 Problem statement ........................................................................................................................................ 2
1.2 Project Background ....................................................................................................................................... 2
1.2.1 Objective of the project ........................................................................................................................ 2
1.2.2 Scope of project ...................................................................................................................................3
1.2.3 Brief description ..................................................................................................................................3
1.2.4 Connection diagram.......................................................................................................................... 6
1.2.5 Flow chart .............................................................................................................................................7
Chapter Two ................................................................................................................................................................. 8
2. Literature review ................................................................................................................................................ 8
2.1 The traffic light system ................................................................................................................................ 8
2.2 Traffic light objectives .............................................................................................................................. 8
2.3 Advantages of traffic light ........................................................................................................................ 8
2.4 Traffic light history .................................................................................................................................... 8
2.5 PIC Microcontrollers ................................................................................................................................ 9
2.5.1 Overview and Features .................................................................................................................... 9
2.5.2 ARCHITECTURE of PIC 16F877A ..............................................................................................11
2.5.3 Pin Diagram ........................................................................................................................................ 12
2.5.4 PIC Features ....................................................................................................................................... 12
Chapter 3 ....................................................................................................................................................................... 16
3. Design Hardware and Software Development ......................................................................................... 16
3.1 HARDWARE COMPONENTS USED .................................................................................................. 16
3.1.1 VOLTAGE REGULATOR (IC 7805) .............................................................................................. 16

iv
3.1.2 SEVEN SEGMENT DISPLAY ....................................................................................................... 17
3.1.3 RESISTOR ......................................................................................................................................... 19
3.1.4 CAPACITOR .................................................................................................................................... 19
3.1.5 BERG CONNECTOR ..................................................................................................................... 19
3.1.6 OSCILLATOR ................................................................................................................................... 19
3.1.7 LED ....................................................................................................................................................... 19
3.1.8 Infra-Red (IR) Sensors ................................................................................................................... 20
3.1.9 DECODER (74LS47) ....................................................................................................................... 21
3.1.10 TRANSISTOR .................................................................................................................................. 23
3.1.11 PICKIT 2 USB PROGRAMMER ................................................................................................ 23
3.2 Software design ......................................................................................................................................... 24
3.2.1 Software development tools ......................................................................................................... 24
3.2.2 Software used.................................................................................................................................... 25
3.2.3 Design and Implementation ......................................................................................................... 29
3.2.4 Calculation ........................................................................................................................................ 30
3.2.5 Connection circuit diagram for proteus..................................................................................... 31
3.3 Coding ......................................................................................................................................................... 32
Chapter Four ............................................................................................................................................................... 34
4. RESULTS AND DISCUSSIONS .................................................................................................................. 34
4.1 Results ......................................................................................................................................................... 34
4.2 Discussions ................................................................................................................................................. 34
Chapter 5 ...................................................................................................................................................................... 35
5. Conclusion and future scope ........................................................................................................................ 35
5.1 Conclusion ..................................................................................................................................................... 35
5.2 Future Scope .............................................................................................................................................. 35

v
List of figure

Figure1.1- General 4-Way Traffic ...........................................................................................................................3


Figure1.2 cycle for the traffic light ......................................................................................................................... 4
Figure1.3 Circuit Block Diagram ........................................................................................................................... 5
Figure1.4- Connection diagram .............................................................................................................................. 6
Figure1.5- Flow chart .................................................................................................................................................7
Figure ‎2.1- Architecture of PIC16F877A microconteroller............................................................................11
Figure ‎2.2-pin description of PIC16F877A ........................................................................................................ 12
Figure ‎3.1-IC 7805 Features ................................................................................................................................... 16
Figure ‎3.2- Seven Segment Display ....................................................................................................................... 18
Figure ‎3.3- Resistor .................................................................................................................................................... 19
Figure ‎3.4 -Capacitor ................................................................................................................................................ 19
Figure ‎3.5 Oscillator ........................................................................................................................................................ 19
Figure ‎3.6 - Light Emitting Diode......................................................................................................................... 20
Figure ‎3.7-IR sensor .................................................................................................................................................. 21
Figure ‎3.8 74LS47 decoder ...................................................................................................................................... 21
Figure ‎3.9- Decoder (74LS47) (a) connection diagram (b) pin description ............................................ 22
Figure ‎3.10- Logic Diagram and Output of 74LS47 ....................................................................................... 22
Figure ‎3.11- Transistor ............................................................................................................................................ 23
Figure ‎3.12-PICit 2 pin diagram........................................................................................................................... 23
Figure ‎3.13-Micro C Pro Window ........................................................................................................................ 26
Figure ‎3.14-Proteus 8 starting window............................................................................................................... 27
Figure ‎3.15-Proteus blank area............................................................................................................................. 28
Figure ‎3.16-proteus device selection ................................................................................................................... 28
Figure ‎3.17- Traffic light control using microcontroller design................................................................... 31

List of table

Table 1- Hex Codes To Display Various Digits ................................................................................................. 18


Table 2 components ................................................................................................................................................... 38
Table 3 key features ................................................................................................................................................... 39
Table 4microcontroller pins........................................................................................................................................ 39
Table 5 pin description............................................................................................................................................ 40
Table 6 pin description ..............................................................................................................................................41

vi
Abbreviation

CPU Central Processing Unit

DC Direct Current

EEPROM Electrically Erasable Programmable Read only Memory

GPS Global Positioning Satellite System

ICSP In Circuit Serial Programming

IR Infrared Sensor

LED Light Emitting Diode

PIC Peripheral Interface Controller

PLC Programmable Logic Controller

RAM Random Access Memory

ROM Read Only Memory

vii
Chapter 1

Introduction

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.

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

Arba minch university institute of technology, AMiT 1


Dynamic traffic light control using microcontroller 2014

approach to process the input data by Microcontroller and finally display it on the traffic light
signal to control the Closed Loop System.

1.1 Problem statement


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
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.2 Project 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.

1.2.1 Objective of the project

The main objectives of this project are:-

 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

Arba minch university institute of technology, AMiT 2


Dynamic traffic light control using microcontroller 2014

1.2.2 Scope of 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

1.2.3 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

Arba minch university institute of technology, AMiT 3


Dynamic traffic light control using microcontroller 2014

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. 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.2 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
Arba minch university institute of technology, AMiT 4
Dynamic traffic light control using microcontroller 2014

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.

Figure1.3 Circuit Block Diagram

Arba minch university institute of technology, AMiT 5


Dynamic traffic light control using microcontroller 2014

1.2.4 Connection diagram

Figure1.4- Connection diagram

Arba minch university institute of technology, AMiT 6


Dynamic traffic light control using microcontroller 2014

1.2.5 Flow chart

Figure1.5- Flow chart

Arba minch university institute of technology, AMiT 7


Chapter Two
2. 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.2 Traffic light objectives


 Save and efficient traffic flow
 Assign right of way to maximize delay and reduce conflict.

2.3 Advantages of traffic light


i. Provide orderly movement of traffic
ii. Minimize conflicting movement.
iii. Increase traffic handling capacity
iv. Mean of interrupting heavy traffic.
v. Coordinated for continuous movement.
vi. Provide driver confidence by assigning the right ways.

2.4 Traffic 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

Arba minch university institute of technology, AMiT 8


Dynamic traffic light control using microcontroller 2014

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
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.5 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.5.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.

Arba minch university institute of technology, AMiT 9


Dynamic traffic light control using microcontroller 2014

 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.
 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.

Arba minch university institute of technology, AMiT 10


Dynamic traffic light control using microcontroller 2014

2.5.2 ARCHITECTURE of PIC 16F877A

Figure ‎2.1- Architecture of PIC16F877A microconteroller

Arba minch university institute of technology, AMiT 11


Dynamic traffic light control using microcontroller 2014

2.5.3 Pin Diagram

Figure ‎2.2-pin description of PIC16F877A

2.5.4 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. FIGURE-8 PROGRAM MEMORY
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.

Arba minch university institute of technology, AMiT 12


Dynamic traffic light control using microcontroller 2014

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.
 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.

Arba minch university institute of technology, AMiT 13


Dynamic traffic light control using microcontroller 2014

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). Indirect Addressing Mode In the indirect
addressing mode the 8-bit register file address is first written into a Special Function
Register (SFR) which acts as a pointer to any address location in the register file. A
subsequent direct access of INDF will actually access the register file using the
content of FSR as a pointer to the desired location of the operand.

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

Byte Oriented Instructions In a byte oriented Instructions f represents a file register and d
represents destination register. The destination specifies where the result of operation is to be
placed. If D= 0 the result is placed in W register (Accumulator) and if d = 1, the result is placed
in the file register specified in the instruction. ADDWF f, d: Add W and f CLRF f: Clear f
MOVWF f, d: Move f NOP: No operation SUBWF f, d: Subtract W from f Bit Oriented
Instruction In bit oriented instructions, b represents a bit field designator which selects the
number of the bit affected by the operation and f represents the number of the file in which the
bit is located. BCF f, b: Bit clear f BSF f, b: Bit set f BTFSC f, b: Bit test f, skip if set
Literal and Control Instructions In literal and control instructions K represents an 8 or 11 bit
constant or literal value. ADDLW k: Add literal and W ANDLW k: AND literal with W CALL
k: Call subroutine MOVLW k: Move literal to W

Arba minch university institute of technology, AMiT 14


Dynamic traffic light control using microcontroller 2014

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.

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

Arba minch university institute of technology, AMiT 15


Chapter 3
3. 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 COMPONENTS USED

3.1.1 VOLTAGE REGULATOR (IC 7805)

Figure ‎3.1-IC 7805 Features

 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.

Arba minch university institute of technology, AMiT 16


Dynamic traffic light control using microcontroller 2014

 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.
 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 SEGMENT DISPLAY

 Four common anode 7-segment displays are used in this 4-way traffic light control
system. Figure 3.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.

Arba minch university institute of technology, AMiT 17


Dynamic traffic light control using microcontroller 2014

Figure ‎3.2- Seven Segment Display

Table 1- Hex Codes To Display Various Digits

Arba minch university institute of technology, AMiT 18


Dynamic traffic light control using microcontroller 2014

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.

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.

Arba minch university institute of technology, AMiT 19


Dynamic traffic light control using microcontroller 2014

Figure ‎3.6 - Light Emitting Diode

They are:

3.1.8 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.

Arba minch university institute of technology, AMiT 20


Dynamic traffic light control using microcontroller 2014

Figure ‎3.7-IR sensor

3.1.9 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 Figure 3.8 74LS47 decoder
cascadable zero-suppression functions.

Arba minch university institute of technology, AMiT 21


Dynamic traffic light control using microcontroller 2014

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

Figure ‎3.10- Logic Diagram and Output of 74LS47

Arba minch university institute of technology, AMiT 22


Dynamic traffic light control using microcontroller 2014

3.1.10 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.

Figure ‎3.11- Transistor

3.1.11 PICKIT 2 USB PROGRAMMER

Figure ‎3.12-PICit 2 pin diagram

Arba minch university institute of technology, AMiT 23


Dynamic traffic light control using microcontroller 2014

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.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

Arba minch university institute of technology, AMiT 24


Dynamic traffic light control using microcontroller 2014

programs, usually run on personal computers that allow the programmer (or system developer) to
create, modify, and test applications programs.
Some common software development tools are:
 Text editors
 Assemblers/compilers
 Simulators
 High-level language simulators
 Integrated development environments (IDEs)

3.2.2 Software used

1. 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.

Arba minch university institute of technology, AMiT 25


Dynamic traffic light control using microcontroller 2014

Figure ‎3.13-Micro C Pro Window


2. 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.

Arba minch university institute of technology, AMiT 26


Dynamic traffic light control using microcontroller 2014

 System Benefits Integrated package with common user interface and fully context
sensitive help.

Figure ‎3.14-Proteus 8 starting window

Arba minch university institute of technology, AMiT 27


Dynamic traffic light control using microcontroller 2014

Figure ‎3.15-Proteus blank area

Figure ‎3.16-proteus device selection

Arba minch university institute of technology, AMiT 28


Dynamic traffic light control using microcontroller 2014

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.2.3 Design and Implementation

As we have seen in the above chapters, 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 (). 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 PORTB pins are interrupted. So it has to connect to the
sensor.
 PORTC 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.
 PORTD and the first pins of PORTA 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.

Arba minch university institute of technology, AMiT 29


Dynamic traffic light control using microcontroller 2014

3.2.4 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 Arba Minch 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.
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 Arba Minch town is so short.
Depending on the road you can vary the distance of the sensor from the traffic light.

Arba minch university institute of technology, AMiT 30


Dynamic traffic light control using microcontroller 2014

3.2.5 Connection circuit diagram for proteus

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

Figure ‎3.17- Traffic light control using microcontroller design

Arba minch university institute of technology, AMiT 31


Dynamic traffic light control using microcontroller 2014

3.3 Coding
Finally the proteus design has needed the source code. So, the final code is shown below.

Arba minch university institute of technology, AMiT 32


Dynamic traffic light control using microcontroller 2014

Arba minch university institute of technology, AMiT 33


Chapter Four
4. 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.

Arba minch university institute of technology, AMiT 34


Chapter 5
5. Conclusion and future scope

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 Future Scope


This project can be enhanced in such a way as to automatically control the signals depending on
the number of vehicles 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. 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

Arba minch university institute of technology, AMiT 35


Dynamic traffic light control using microcontroller 2014

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.

Arba minch university institute of technology, AMiT 36


Dynamic traffic light control using microcontroller 2014

REFRENCES
For Books

John B.Peatman- PIC Microcontroller design, 1st edition: Pearsons Education; 1997

Muhammad Ali Mazidi- PIC Microcontroller and Embedded systems, 3rd edition: Pearsons
Education; 2007

Iovine John- PIC Microcontroller Project Book, 2nd Edition, Singapore: McGraw Hill 121-123;
2000. Nd

Lawrence A. Duarte- The Microcontroller Beginner’s Handbook, 2 Edition, United States of


America: Prompt Publication. 3-5; 1998.

For Report and User’s Manual

MPLAB IDE, Simulator, Editor User’s Guide


http://www.mi0crochip.com
http://robotaaly.blogspot.in/2013/02/traffic-light-control-system.html
hhtp://www.slideshare.net/deepu671/demo-traffic-light-in-pic16f87

Arba minch university institute of technology, AMiT 37


Dynamic traffic light control using microcontroller 2014

Appendix 1

Table 2 components

Arba minch university institute of technology, AMiT 38


Dynamic traffic light control using microcontroller 2014

Appendix 2

Table 3 key features

Table 4microcontroller pins

Arba minch university institute of technology, AMiT 39


Dynamic traffic light control using microcontroller 2014

Table 5 pin description

Arba minch university institute of technology, AMiT 40


Dynamic traffic light control using microcontroller 2014

Table 6 pin description

Arba minch university institute of technology, AMiT 41

You might also like