09_MyatMinMaung

advertisement
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
SIM UNIVERSITY
SCHOOL OF SCIENCE AND TECHNOLOGY
APPLICATION OF MICROCONTROLLER IN
TRAFFIC LIGHT CONTROL
STUDENT
: MYAT MIN MAUNG (Y0402019)
SUPERVISOR
: MR CHONG SIEW PING
PROJECT CODE : JAN09/BEHE/54
A project report submitted to SIM University
in partial fulfillment of the requirements for the degree of
Bachelor of Engineering (Electronics)
NOV 2009
0
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Acknowledgements
I would like to take this opportunity to express my heart-felt gratitude to my
mentor as well as project supervisor, Mr. Chong Siew Ping, for his professional and
excellent support and guidance during my project development. His in-depth
experience in microcontroller technology, tireless encouragement and commitment
has paved my way to success in developing this exciting and demanding project. He
has been the one who endures the most of my setbacks whenever I lose the plot and
energized me to carry on until the last day.
Secondly, I would like to give my appreciation to those who make this
UniSIM-Singapore Polytechnic collaboration possible in offering these exciting and
comprehensive FYP projects. I feel privileged and proud to be one of the students to
carry out these projects as it not only improves my knowledge in software
development aspect but also offers me the opportunity to flourish my skills in
hardware development and circuit design.
I am also grateful to my colleagues for their priceless ideas and knowledge
given to me at certain area I do not excel at. My final note of thanks goes to my
parents, sister, brother and my wife for their unparallel love and support during my
study of this course.
1
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Abstract
Microcontrollers play an important role in the success of today’s consumer
and industry related products. Due to the cheaper unit cost, low voltage operation,
multipurpose features and higher demand in embedded system, almost every
application nowadays is based on microcontroller system. The other factor that
accelerates the influence of this technology is that these chips can be available for
various terminations types such as DIP, SMD and Through Hole which conveniently
fit to different applications and purposes. Furthermore, it can be integrated with any
other devices for communication and control purposes.
The basic operation of this project is that there are two modules of traffic light
controllers operating at the junction where North-South road intersects East-West
road. The traffic controller itself is maintenance-free with fixed timing for intervals
such as Green, Amber, Red, Turn right and Pedestrian Passing stages. But, there
are two exceptional conditions for the traffic controllers to act according to the
urgency of the traffic flow. One condition is when the pedestrian pressed the button
requesting for the road passage and the other is the request sent by the emergency
vehicles for priority passage of the junction.
In this project, PIC18F2520 acts as the central brain for all the activities to be
carried out. It will take all the inputs from push buttons and receiver’s inputs and
execute the appropriate actions to fulfill the requirement. The development board,
PICKit 2 is used as a communication platform between PC and microcontroller board.
Microcontroller board was assembled and soldered from the scratch to have the
understanding and skill of hardware design. The blessing of choosing PIC 18F2520
is that all the necessary development software such as MPLAB IDE and MPLAB C18
are widely available for free. User manuals, product data sheets and sample codes
are also useful in the learning of early stages.
As for the traffic light modules, only two controller modules were constructed
in the sense that individual module will operate in the directions of respective
South-North and East-West. This decision is to save time for further implementation
and modification purposes.
As for the last part of the project, Holtek infrared encoder and decoder pair is
used to communicate between traffic light controller and emergency vehicle to give
priority passage to the vehicle. Once the signal is received, the traffic controller will
prolong the green signal until it receives another signal to proceed to the traffic
sequence as usual. This condition is right only when the traffic light state is under
Green light for the respective road. If the desired road that needs priority access is
under Red light or other conditions, it will shorten the timings of other road to have
faster Green light access.
2
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
List of Figures for PART1

Figure 1.1 Ideal Intersection and Traffic Light Controller for this project

Figure 1.2 Standard processes of programming and downloading to Traffic
Light Module

Figure 2.1 Circuit diagram of Traffic Light Controller

Figure 2.2 Various steps of traffic/pedestrian movements of Traffic Light
Sequence

Figure 2.3 Schematic diagram of Traffic Light Controller using Board of
Education

Figure 2.4 PIC18F2520 Controller Module (Front and Back)

Figure 3.1 Project Gantt Chart

Figure 3.2 Days and Tasks allocation of the whole project as a Pie Chart

Figure 4.1 Schematic of Traffic Light Controller for North-South Traffic

Figure 4.2 Illustration of how EVPS works for Fire Engine

Figure 4.3 Schematic of Infrared transmitter Circuit

Figure 4.4 Transmission of data in Latching mode

Figure 4.5 Schematic of Infrared Receiver Circuit

Figure 4.6 Graph from the datasheet of Holtek HT12D encoder

Figure 5.1 Flowchart of standard Traffic Light Controller

Figure 5.2 Flowchart of shortening the timing of Turn Right sequence when
the pedestrian on the opposite road requests passage access

Figure 5.3 Illustrations of Red Truncation and Green Extension Methods

Figure 5.4 Flowchart of emergency sequence when the vehicle is on opposite
road

Figure 5.5 Flowchart of emergency sequence for prolonging the Green light
Timing

Figure 6.1 Typical circuit diagram of astable 555 timer
3
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)

Figure 7.1 Vehicle requesting for priority access to prolong Green light (Check
in)

Figure 7.2 Vehicle requesting to disable priority access (Check out)

Figure 7.3 Recommended design of checking in and out using either IR
transmitter or RFID chip
List of Figures for PART2

Figure A.1 Driver Board of PIC18F2520 Microcontroller with Headers

Figure A.2 Pin assignments and descriptions of PIC18F2520 microcontroller

Figure A.3 Schematic Diagram of Microcontroller Driver Board

Figure A.4 Single Traffic Light Controller

Figure B.1 Infrared Transmitter using Holtek HT12A

Figure B.2 Infrared Receiver using Holtek HT12D
4
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
List of Tables

Table 3.1 Application of Microcontroller in Traffic Light Control (Planned)

Table 3.2 Application of Microcontroller in Traffic Light Control (Actual)

Table 4.1 Figure Components List of Traffic Light Controller Module (only one
module)

Table 4.2 Port assignments for both directions of the Traffic

Table 4.3 Components list of Infrared Transmitter

Table 4.4 Components list of Infrared Receiver
5
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Table of Contents
Pages
Acknowledgements …………………………………………………………………… 1
Abstract …………………………………………………………………………………
2
List of Figures ………………………………………………………………………….
3
List of Tables …………………………………………………………………………..
5
PART 1
Chapter 1 : Introduction ………………………………………………………………
8
Overview of the Project ……………………………………………………………....
8
Project Objective ………………………………………………………………………
10
Project Scope ………………………………………………………………………….
10
Chapter 2 : Literature Review ………………………………………………………..
11
Review of Traffic Light Controller and Its Development …………………..
The Advantage of Choosing Microchip PIC18F2520 and C Language …
11
17
Chapter 3 : Project Plan ……………………………………………………………...
18
Chapter 4 : Design of Traffic Light Controller ……………………………………...
22
2.1
2.2
Construction of Driver Boards for Two Traffic Light Modules and ……….
Components Involved
Emergency Vehicle Priority System (EVPS) ……………………………….
Basic Operation of the Emergency Vehicle Priority System ……………...
Hardware Design of Transmitter Module ……………………………………
Hardware Design of Receiver Module ………………………………………
22
Chapter 5 : Implementation of Software and Programming ………………………
31
Overview of Microchip MPLAB IDE and MPLAB C18 Compiler …………
Implementation of Algorithm and Considerations Involved for …………...
Multiple Traffic Light Situations
5.2.1 Normal traffic condition state …………………………………………
5.2.2 Pedestrian crossing input state……………………………………….
5.2.3 Emergency vehicle priority request state…………………………….
31
32
4.1
4.2
4.3
4.4
4.5
5.1
5.2
24
26
27
29
33
35
36
6
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Chapter 6 : Experimental Results and Modifications ……………………………… 38
6.1
6.2
Performance of Initial Circuit Design of Traffic Light Controller ………….. 38
and EVPS
Performance of Final Circuit Design of Traffic Light Controller …………... 39
and EVPS
Chapter 7 : Conclusion, Recommendation and Additional Modifications ……….. 40
for Further Improvement
7.1
7.2
7.3
Conclusion ………………………………………………………………………
Recommendation ………………………………………………………………
Additional Modifications for Further Improvement ………………………….
7.3.1 Current Traffic Light Controller Design ………………………………
7.3.2 Recommended Traffic Light Controller Design ……………………..
40
41
42
44
45
PART 2
Critical Review and Reflections ……………………………………………………… 45
Bibliography ……………………………………………………………………………. 47
APPENDICES
Appendix A : Driver Board for PIC18F2520 Microcontroller and …………………
Components Involved
49
Appendix B : Driver Board for Traffic Light Module and Components …………..
Involved
52
Appendix C : Algorithm for the Traffic Light Control of Different Situations …….
54
Glossary ………………………………………………………………………………..
61
7
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
PART 1
Chapter 1 : Introduction
1.1
Overview of The Project
This project is carried out with the aim to explore the capabilities of
PIC18F2520 in the development of academic level traffic light control. The traffic light
controller is assumed to be stationed at the traditional road junction at which
East-West intersects North-South traffic. Moreover, this project excludes the
consideration of left turn with the assumption that there will be a small side road with
zebra crossing will be provided for the traffic. There will be three types of traffic
conditions. The first condition is the normal traffic flow with the fixed timer for all
stages. The second condition is the case where the pedestrians’ input is received so
that the traffic sequence will be given priority to pedestrian crossing. The third and
last condition is exceptional case where the emergency vehicle requests the traffic
controller to give priority so that the waiting time will be shortened which can save
lives. In this case, all other conditions such as normal and pedestrian conditions will
be overridden by this condition. The following figures show the ideal traffic junction
where this experiment is expected to be performed and the traffic signals involved.
Figure 1.1 Ideal Intersection and Traffic Light Controller for this project
Although there are so many projects of traffic light in the past, the purpose of
the project, the methodology, the components used, the microcontrollers, the
development tools and the programming languages vary in individuals. Microchip’s
microcontroller PIC18F2520 is used in this project for a few reasons.
First and foremost, Microchip provides Design development tools such as
MPLAB IDE and MPLAB C18 which enables the chip understood the C language for
free. For MPLAB C18, some features of the optimum capability might be disabled
after a few months but still good enough for academic projects. Furthermore, flash
memory is used which means reprogramming can be done numerous times without
having to buy many microcontrollers. And the PICKit2 programmer is compact in size
and easy to use. Although the hardware components in this project are widely
available and can directly connect to the microcontroller, additional ICs such as 7
segment driver IC(7447) and Up/Down counter (74LS193) are used. This is the effort
8
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
to save the pins available for further additional applications although there are more
than enough available pins of 25 IO pins. Only 19 out of 25 available IO pins are
used for microcontroller module including Vdd, Gnd and Master Rst pins. Those 6
pins left are catered for the development of emergency vehicle priority system. The
following diagram illustrates the general concept of programming and downloading
the programs into Microchip’s PIC18F2520 in MPLAB IDE environment.
MPLAB IDE
Creating project files,
linking necessary files
and assigning project
environment variables,
building Program
MPLAB C18
Declaration of libraries
and header files,
writing executable
program using C
language
Corresponding driver
circuit for the system
(Traffic light module)
PICkit 2
To import, export, write
and read executable
hex file to PIC18F2520
PIC18F2520
PIC microcontroller
module
Figure 1.2 Standard processes of programming and downloading to Traffic
Light Module
Since there are four directions at the junction, practically there should be four
traffic controllers stationed at each point. But, as we notice that the controllers facing
each other are operating exactly the same. Therefore, we only simulate two
controllers, one for East-West traffic and the other for North-South traffic. By doing
so, the cost will be reduced to half and also cut down work load in programming and
building hardware yet still can realize the same working model.
For the Emergency priority system, the push button is used for early stages to
get the programming algorithm right. Once the concept is right, communication
channels such as RF and infrared are considered. The decision making factors and
the chosen ICs for communication channel will be discussed in later sections.
9
Application of Microcontroller in
Traffic Light Control
1.2
Maung Myat Min Maung(Y0402019)
Project Objective

The main objective of this project is to implement the traffic light controller at
the junction with the use of PIC18F2520 microcontroller and C programming.

Additional goal is to experiment whether it is feasible to install emergency
vehicle priority system for urgent vehicles such as fire engine and ambulance
in conjunction with the traffic light controller.

The last aim is to get experience in hardware and software related project
development, troubleshooting and decision skills when things go wrong, good
project management skills and presentation skills.
1.3
Project Scope

Installation of PICkit 2 , MPLAB IDE and MPLAB C18 C Compiler software

Construction, testing and troubleshooting of PIC18F2520 controller module
(PCB and necessary components for the PIC microcontroller module are
provided by tutor)

Construction, testing and troubleshooting of two traffic light controller modules

Programming the algorithm of the traffic light controller in normal and
pedestrians’ inputs condition.

Construction, testing and troubleshooting of transmitter and receiver circuits
for the emergency priority system

Programming and integration of transmitter and receiver circuits with the
traffic light controller.
10
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Chapter 2 : Literature Review
2.1
Review of Traffic Light Controller and Its Development
Traffic light controller is a good foundation of academic topic in understanding
the engineering concepts such as algorithms, design and implementation. Algorithm
is essential in directing the sequence of the devices such as LEDs, Buzzers and
7-segment counters. In the case of design, there are a few options to be chosen
from such as sequential and combinational logic design with the help of state
diagrams, using Programmable Logic Device (PLD) with external circuits or using
microcontrollers.
Regardless of the above available technologies, microcontrollers are widely
used in conjunction with other devices to develop academic and industrial projects.
For example, in this project, RF or infrared communication devices can be used as
inputs to microcontroller and necessary actions can be carried out in accordance
with the programmer’s instructions. This same goal might not be easily realized in
other techniques such as logic design, PLD and so on. And the implementation steps
might involve complex consideration such as state diagrams, flowcharts and truth
tables which will result in designing complicated circuitry. For example, for timing
based projects, component such as 555 timer will be necessary. Even for previous
versions of microcontrollers, external add-ons such as crystal oscillators and ceramic
resonators are needed. Yet, nowadays, internal oscillators are already installed in
microcontrollers saving cost and space.
During the literature review, different kinds of techniques, devices and
microcontrollers were studied. In this report, only three types of techniques will be
focused and discussed as follows:
2.1.1 ) Traffic Light Controller using Gal 22x10 Output Decoder
2.1.2 ) Variable Traffic Light Controller using STK-500
2.1.3 ) Design and Development of Sensor Based Traffic Light System using
Parallax Board of Education
11
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
2.1.4 ) Traffic Light Controller using Gal 22x10 Output Decoder
Figure 2.1 Circuit diagram of Traffic Light Controller
The above circuit is designed by Singapore Polytechnic FYP team with the
use of PLD (Programmable Logic Device) and some sequential and combinational
logic circuits. This circuit operates exactly as the actual traffic light sequence in
Singapore except the exclusion of count down 7-segment LED display.
In this circuit, the 555-timer is the most critical part of all the other parts as the
whole sequence of the traffic light is driven by this oscillator. The output of this clock
is fed into the CP1 of 7493 Frequency divider which will on the other hand yield the
1
output signal at Q d (most significant bit) with the frequency of
that of the input
8
clock signal.
This output clock signal is connected to the CPu of 74193 counter which can
be used either as down-counter or up-counter. In this case, the IC pins are
connected in such a way that it will count from 0 to 11 and will reset all of its outputs
to 0000 state once it exceeds the count of 11. This can be done by first feeding the
clock output of 7493 into the clock source of up-counter, 74193 IC. And the two
pins,Q2 and Q3 of this IC is connected together with 2-input NAND to the PL to load
the default value 0000 for the outputs whenever both outputs of Q 2 and Q3 have 1s.
Finally, all of the 4 outputs of 74193 are directly connected into the inputs of
GAL22v10 Output Decoder. Afterwards, the decoder is programmed in such a way
that it will produce the specific output depending on the output 4 bits or count of the
74193 counter. The illustrations of the action performed relating to the count of the
12
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
74193 counter can be observed from the figure and can be understood that the
accuracy and reliability of the counter is very critical to the performance of this traffic
light controller. The following figures show the standard operation of the traffic light
controller in different count number.
Figure 2.2 Various steps of traffic/pedestrian movements Traffic Light
Sequence
This project plays an integral part in developing my own Traffic Light
Controller as it has basic concepts such as the involvement of counter, oscillator and
PLD. So, the Traffic Light Controller can be easily developed with the use of
microcontroller by simply replacing PLD with Microchip’s PIC18F2520 and scripting
necessary programming to give instructions to the microcontroller to perform as
desired. And even more advanced features such as displaying counting downwards
of 7-segment LED and allowing communication with the technology such as infrared
and RF can be easily integrated with additional circuits.
13
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
2.1.5 ) Variable Traffic Light Controller using STK-500
This project is still accessible through Cornell University FYP microcontroller
projects list. This project operates almost like my project except the fact that it uses
different development kit and the purpose of traffic condition detection. This project
uses STK-500 kit and composes of three traffic conditions which are as follows.
(a) Normal Traffic Light condition
(b) Pedestrians’ inputs condition
(c) Hall effect sensor input condition
In this project, there is no necessity of driver boards as it doesn’t consist of
additional components except LEDs as traffic signal indicators and pedestrian lights.
So, all the components can be directly connected to the development board and can
be programmed directly. For the sensor input, it uses the Hall Effect sensors which
detect the presence of the metal (assumed cars in this case) and adjust the flow of
the traffic.
This project really helps me in getting to understand the fundamental concept
of traffic light controller and its programming concept. It also has the feature of
overriding the state depending on the congestion of the traffic. That’s why this
project’s name is given variable traffic light controller as its timers for the interval will
be automatically adjusted according to the need of the traffic. It will give longer
interval or faster access to the more congested traffic than to the lesser congested
one. It will allow the traffic to flow accordingly and will reduce the chances of having
traffic jam or unnecessary long waiting time at the intersection.
14
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
2.1.6 ) Design and Development of Sensor Based Traffic Light System using
Parallax Board of Education
Figure 2.3 Schematic diagram of traffic light controller using Board of
Education
This project was developed by a few students from International Islamic
University Malaysia, Faculty of Engineering in 2006 and the journal can be found in
American Journal of Applied Sciences. It consists of Basic Stamp 2 as
microcontroller and is plugged into the Board of Education which is connected to the
computer for programming codes and downloading programs.
As shown in the above figure, the corresponding LEDs will react according to
the outputs of the microcontroller. This traffic light controller also differs from mine as
it only consists of three states which are Green, Amber and Red. And it is also noted
that Red and Green light are joined together with inverters so that this two conditions
will operate in different conditions simultaneously. But, the similarity between this
15
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
project and the one from Cornell University is that both system use sensors to adjust
the timing of the respective interval to give priority to the more congested traffic to
avoid traffic congestion. The only difference is that this system uses infrared object
detectors instead of Hall Effect sensors to detect the length of the traffic. And the
distance between the position of the sensor and the traffic light controller plays a part
as it uses the formula to calculate the timing to illuminate the green light. The formula
for the calculation of timing for the Green light according to the journal is as follows:

1 d a
Time    a  zD12 
3  v1 v s

Where
d
=
distance between one sensor to another in meter
v1
=
the average speed of the first car moving from stationary at the
moment the signal turned green in (m/s)
aa
=
the average acceleration of a car from stationary position to the
next car position in (m/s2)
vs
=
the average speed of a car moving from standstill after traffic
light turns green in (m/s)
z
=
0 when there is no sensor triggered and 1 if there is at least one
sensor triggered
D12
=
total time delay which can be calculated using the following
equation
D12  t1 nt  1  t 2
Where
t1
nt
t2
=
=
=
the value of the first time delay in (s)
the number of sensors triggered
the second time delay for each lane in (s)
This traffic light system involves three infrared object detection sensors for
each lane which will be used to detect the presence of vehicles. Depending on the
number of sensors triggered, it will be used in the above formulae to calculate the
illumination timing of Green light for respective traffic. After the illumination of Green
light, Amber will follow and so as the Red in the end of the sequence. Next, it will go
to the next lane condition.
16
Application of Microcontroller in
Traffic Light Control
2.2
Maung Myat Min Maung(Y0402019)
The Advantage of Choosing Microchip’s PIC18F2520 and C Language
Microchip’s PIC18F2520 which belongs to PIC18 series is one of the well
known microcontrollers for academic and industry based applications and projects.
And not like its earlier models which have to depend on third party compilers for the
compilation using C, it is fully supported by Microchip’s very own compiler, MPLAB
C18 compiler. There are plenty in terms of advantages in using this microcontroller
but the followings list some important facts in making this decision.

PIC18F2520 is neither an obsolete nor future product as it is still in
production.

It has flash memory which can be reprogrammed many times and has the
EEPROM program and data memory of 32,000 bytes and 256 bytes.

It also supports the RAM memory of up to 1536 bytes for variables used for
programs.

It consists of a total of 28 pins of which 25 pins are IO pins that are suitable
for medium size projects.

Saving cost for project development as it has its own internal oscillator which
means using the external oscillator for clocking the PIC is no more necessary.

The power supply voltage ranges from 2V to 5.5V which is well suitable
DC-Based project development.

Microchip provides free student version MPLAB C18 compiler which allows to
use popular programming C.
Figure 2.4 PIC18F2520 Controller Module (Front and Back)
17
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Chapter 3 : Project Plan
The main objective of this project is to implement the traffic light controller
functionality in accordance with the Singapore traffic light sequence using
PIC18F2520. The additional task is to combine the traffic light controller with the
transmitter from assumed emergency vehicles. As I already had knowledge in C
programming and microcontroller though different brand and model, the expected
goals were met in advance to the schedule. So, additional tasks were carried out in
exploring the available and suitable devices and techniques to communicate with the
traffic controller. The planned and modified tables of project plan, Gantt Chart are
shown below.
Application of Microcontroller in Traffic Light Control(Planned)
Task to be performed
Start Date
End Date
Duration(days)
1. Project goal discussion, proposal
01/01/2009
01/24/2009
24
and approval
2. Installation of MPLAB IDE,
MPLAB C18 and PICkit 2
01/25/2009
02/03/2009
9
software
3. Assembling, testing and
troubleshooting PIC controller
02/04/2009
03/02/2009
26
module
4. Literature review
02/04/2009
02/28/2009
24
5. Preparation, writing and
02/13/2009
02/27/2009
14
Submission of initial report
6. Review Project plan
02/28/2009
03/15/2009
15
7. Programming and testing of
03/16/2009
05/12/2009
57
individual components
8. Designing the driver circuit for
05/13/2009
06/15/2009
33
traffic light module
9. Programming and designing of
06/16/2009
08/15/2009
29
final design and algorithm
10. Fabrication of final design and
08/16/2009
09/17/2009
32
testing
11. Concluding the prototype, final
09/18/2009
10/02/2009
14
and oral report issues
12. Finalization and submission of
10/03/2009
11/15/2009
43
final report
13. Poster and oral presentation
11/16/2009
11/30/2009
14
Table 3.1 Application of Microcontroller in Traffic Light Control (Planned)
18
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Application of Microcontroller in Traffic Light Control(Actual)
Task to be performed
Start Date
End Date
Duration(days)
1. Project goal discussion, proposal
01/01/2009
01/24/2009
24
and approval
2. Installation of MPLAB IDE,
MPLAB C18 and PICkit 2
01/25/2009
02/03/2009
9
software
3. Assembling, testing and
troubleshooting PIC controller
02/04/2009
03/02/2009
26
module
4. Literature review
02/04/2009
02/28/2009
24
5. Preparation, writing and
02/13/2009
02/27/2009
14
Submission of initial report
6. Review Project plan
02/28/2009
03/15/2009
15
7. Programming and testing of
03/16/2009
05/12/2009
57
individual components
8. Designing the driver circuit for
05/13/2009
06/15/2009
33
traffic light module
9. Programming, designing and
06/16/2009
08/15/2009
29
wiring of final design and algorithm
10. Literature review on Infrared
08/16/2009
08/31/2009
15
sensors, IR encoders and decoders
11. Testing and Prototyping of IR
09/01/2009
09/30/2009
30
transmitter and receiver
12. Concluding the prototype, final
10/01/2009
10/14/2009
14
and oral report issues
13. Finalization and submission of
10/15/2009
11/09/2009
25
final report
14. Poster and oral presentation
11/16/2009
11/28/2009
12
Table 3.2 Application of Microcontroller in Traffic Light Control (Actual)
19
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Figure 3.1 Project Gantt Chart
20
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Tasks vs Days Allocated
1. Project goal discussion, proposal and
approval
2. Installation of MPLAB IDE, MPLAB C18
and PICkit 2 softwares
3. Assembling, testing and troubleshooting
PIC controller module
14, 4%
25, 8%
14, 4%
30, 9%
4. Literature review
24, 7%
9, 3%
26, 8%
24, 7%
5. Preparation, writing and Submission of
initial report
6. Review Project plan
7. Programming and testing of individual
components
8. Designing the driver circuit for traffic
light module
15, 5%
14, 4%
15, 5%
29, 9%
33, 10%
9. Programming, designing and wirirng of
final design and algorithm
10. Literature review on Infrered sensors,
IR encoders and decoders
11. Testing and Prototyping of IR
transmitter and receiver
57, 17%
12. Concluding the prototype, final and oral
report issues
13. Finalization and submission of final
report
14. Poster and oral presentation
Figure 3.2 Days and Tasks allocation of the whole project as a Pie Chart
21
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Chapter 4 : Design of Traffic Light Controller
4.1
Construction of Driver Boards for Two Traffic Light Modules and
Components Involved
Figure 4.1 Schematic of Traffic Light Controller for North-South Traffic
From the figure, we understand that all the ports from RA0 to RA7 are the
output ports of the PIC18F2520. So, this whole circuit acts according to the
instruction from the microcontroller. If the ports are enough, there is no necessity in
building the external circuits to drive the 7-segment LED. But, for the sake of saving
a few pins for the emergency vehicle priority system, 7-segment decoder driver
(7447) and count down counter(74193) are used.
For the calculation of current limiting resistor values, ohm’s law was used. If
we assume with the standard procedure to calculate the values of resistor, the
current normally assumed to be 20mA for the LED with forward voltage of 1.7 V for
5V  1.7V   165 . Yet, the LED light is dimmer
LED Red. So, the value of resistor is
20mA
with this value and the supply voltage is not exactly 5V as expected in theory.
Therefore, 100 Ω is used to replace the ideal 165 Ω resistor without damaging the
LED. The calculated value of forward current is around 30mA which is still
acceptable for the LED as the max current allowed is 30mA in theory.
The connection of RA5 is quite different from the rest as it drives three
devices such as LED, Buzzer and clock input of 74LS193. In this case, it is
programmed in the microcontroller such a way that output signal of RA5 produces
22
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
like a clock signal. This can be done by using delays and loops to form a desired
clock waveform. And the power supply pin of 74LS193 is connected to RA7 so that
this IC can be controlled according to the sequence necessary.
The data pins of 74LS193 are pre-configured which is at digit 9 that is the
counter will load digit 9 once the IC is supplied with 5V and counts it downwards up
to digit 0. Once the counter reaches digit 0, the pin-11, TC will output low state which
will drive the 7-segment to be blank. Port RA6 is the input of pedestrian input for
North to South traffic.
For the common anode 7-segment LED Display, the incoming current is
limited with 220 Ω so that only around 15mA of current will share for all the active
LED diodes with parallel voltage of around 1.7V. Although there is reverse biased
voltage at the cathode side which has around 5V, practically it can’t damage the LED
as it can resist maximum reverse-biased voltage of 5V. The components and
devices involved in the above circuit diagram are listed in the following table.
S/N
1
2
3
4
5
6
7
Component Type
Quantity
LED( 2 x Red, 3 x Green, 1 x Amber )
6
Resistor ( 7 x 100Ω, 1 x 220Ω, 10kΩ )
9
1 x Buzzer
1
1 x Push Button ( Normally Open)
1
1 x 74LS193 Counter
1
1 x 7447 Decoder
1
1 x 7 Segment LED Display
1
Total
20
Table 4.1 Figure Components List of Traffic Light Controller Module(only one
module)
PORT A - EAST to WEST
PORT C - NORTH to SOUTH
Direction
Direction
RA0 – RED LED
RC0 – RED LED
RA1 – AMBER LED
RC1 – AMBER LED
RA2 – GREEN LED
RC2 – GREEN LED
RA3 – TURN RIGHT LED
RC3 – TURN RIGHT LED
RA4 – RED MAN LED
RC4 – RED MAN LED
RA5 – GREEN MAN, BUZZER,
RC5 – GREEN MAN, BUZZER,
CLOCK PULSE
CLOCK PULSE
RA6 – PEDESTRIAN INPUT
RC6 – PEDESTRIAN INPUT
RA7 – VOLTAGE SUPPLY FOR
RC7 – VOLTAGE SUPPLY FOR
74LS193
74LS193
RB5 – SENSOR INPUT FROM
RB7 – SENSOR INPUT FROM
INFRARED RECEIVER
INFRARED RECEIVER
Table 4.2 Port assignments for both directions of the Traffic
23
Application of Microcontroller in
Traffic Light Control
4.2
Maung Myat Min Maung(Y0402019)
Emergency Vehicle Priority System (EVPS)
Figure 4.2 Illustration of how EVPS works for Fire Engine
In this experiment, several ways of communication techniques such as RF
and infrared were considered for the implementation of this system. Devices such as
Amber wireless products, AM Hybrid Transmitter and Receiver, Motorola Infrared
Encoder and Decoder pairs and Holtek Encoder and Decoder pairs were suitable for
the project. Yet, after consideration of important factors such as cost and time
constraint, infrared communication was chosen for the implementation. After this
process, literature review and case studies were done to select the encoder and
decoder pairs which would be suitable for this project. Both Motorola and Holtek IR
ICs are popular ones with their functionality and easy-to-use features. Unluckily, the
preferred models of Motorola MC145026 and MC145027 were not available in
Singapore anymore. So, the only available item was Holtek Encoder and Decoder
pair and widely available in the current market. And it has various models suitable for
both RF and Infrared communications. Furthermore, lesser external components are
required to construct application circuits. For example, for this project, TSAL6400 IR
emitter and TSOP 34838 IR receiver are used which are operating at 38kHz carrier
frequency. Fortunately, Holtek HT12A provides 38 kHz output carrier frequency
which is convenient for both transmission and reception. That is the reason Holtek
HT12A and HT12D are the best choice for the current and future implementation.
The following tables show the components involved in the construction of IR
transmitter and receiver circuits.
24
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
S/N
1
2
3
4
5
6
7
8
9
Component Type
Quantity
Holtek HT12A Infrared Transmitter
1
TSAL6400 Infrared Emitter
1
Ceramic Resonator (455kHz)
1
8050 NPN Silicon Planer Transistor
1
MC7805 5V Voltage Regulator
1
DIP Switch, 8 positions
1
Push Button On/Off
3
3 x Resistors(10MΩ, 10kΩ, 100Ω)
3
Capacitors(2 x 100pF, 1 x 0.33uF, 1 x 0.1uF)
4
Total
16
Table 4.3 Components list of Infrared Transmitter
S/N
1
2
3
4
5
6
7
8
9
10
11
Component Type
Quantity
Holtek HT12D Infrared Receiver
1
TSOP34838 Infrared Receiver (38kHz)
1
MPS2907A PNP Transistor
2
DPDT PCB Relay(G2VN)
2
1N4148 (Diode)
2
8050 NPN Silicon Planer Transistor
1
MC7805 5V Voltage Regulator
1
DIP Switch, 8 positions
1
Resistors(57kΩ, 10kΩ, 5kΩ, 2x330Ω, 220Ω, 100Ω)
7
Capacitors(1 x 0.33uF, 1 x 0.1uF)
2
LED(2 x Green, 1 x Red)
3
Total
23
Table 4.4 Components list of Infrared Receiver
25
Application of Microcontroller in
Traffic Light Control
4.3
Maung Myat Min Maung(Y0402019)
Basic Operation of the Emergency Vehicle Priority System
Basically, there are three push-button switches in transmitter module, one for
North-South traffic, one for East-West traffic and one as a reset switch.
For example, if the button assigned for the North-South is pressed, HT12A
encoder will scan the status of all pins (A0 to D11) and send the information
containing 12 bits through TSAL6400 IR transmitter. The chip will repeat the same
sequence as long as the button is pressed and stops its last cycle only after the
button is released. The information is also encoded with the use of 38kHz built in
carrier frequency.
The TSOP34838 Receiver will remove the carrier frequency and recover the
address and data bits. Then, with the use of 8050 NPN transistor, it will feed the
information into data input (Din, pin-14) of HT12D decoder. The decoder will
compare the status of its own address pins with the information it receives. Once the
information is matched, it will activate the respective relay and feed 5V supply to the
port RB5. The same principle is applied to operation of the East-West traffic priority
system.
For the reset button, there is no actual hardware system attached to the
output pin of the decoder. So, it will just update the status of respective pin resetting
the others.
26
Application of Microcontroller in
Traffic Light Control
4.4
Maung Myat Min Maung(Y0402019)
Hardware Design of Transmitter Module
Figure 4.3 Schematic of Infrared transmitter Circuit
In the above circuit, MC7805 act as a voltage regulator which produces the
regulated output voltage of 5 V that supplies voltages to HT12A and TSAL6400
Emitter directly. Ceramic resonator of 455kHz is used as a clock for the encoder. For
this infrared transmitter circuit, design is mostly based on the application circuit
associated with the datasheet except for the transmission mode (Latch/Momentary)
and the switch configuration for addressing and data pins. The 8050 NPN transistor
is implemented as a switch which will turn on once it is supplied with very small micro
current from its base terminal.
For HT12A, pin1 to 8(A0 to A7) act as addressing pins and pin 10 to 13(D8 to
D11) as Data pins. In latching mode (pin-14 left open), whenever any of pin 10 to 12
is pressed, the transmission will be enabled and the addressing data and four data
bit status (D8 to D11) will be transmitted continuously until the respective push
button is released. This task will be done by HT12A which will introduce a small
amount of current through Pin 17(Dout) to base terminal of 8050 switching on and off
TSAL IR Emitter accordingly. This information will be transmitted with the built in
38kHz carrier frequency of HT12A that is suitable for TSOP34838 receiver. In the
above configuration of D8 to D10, D8 is used as priority signal for North to South
traffic and D9 for East to West. Push button for D10 is installed with the purpose to
reset the status of other pins. The following diagram from datasheet explains how
the transmission works in latching mode.
27
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Figure 4.4 Transmission of data in Latching mode
28
Application of Microcontroller in
Traffic Light Control
4.5
Maung Myat Min Maung(Y0402019)
Hardware Design of Receiver Module
RB7
1N4148
1N4148
Figure 4.5 Schematic of Infrared Receiver Circuit
As mentioned in earlier session, MC7805 is a voltage regulator of 5V power
supply. TSOP34838 is an infrared receiver which will receive the transmitted signal
and recover the encoded data by removing it from 38kHz carrier frequency. So, this
IR receiver is strictly working only with the 38 kHz carrier frequency. Just like in the
transmitter, output pin of TSOP receiver is connected to the base terminal of 8050
NPN transistor switching on and off according to the recovered data. This data will
act as input data for the pin-14 of HT12D Decoder chip. This chip will compare the
received addressing data with its own pre-configured pins(A0 to A7). Once it is
matched, it will make VT (valid transmission) , pin-17, high lighting up the LED. At
the same time, it will make respective data pin (any of D8 to D11) low according to
the recovered data bit. In this HT12D decoder, output state of data pins is active low
and power on status is active low for all pins. That is the reason PNP transistors are
used to activate relays as base of respective transistor needs to be grounded to
switch it on.
Most of the resistors used in this circuit are calculated in such a way to limit
the current flowing through the devices except for the 57k Ω resistor. This value was
approximated from the graph and formula provided by the datasheet. Although the
readout from the graph should be around 51k Ω, 57k Ω is used and the circuit still
works as per normal.
29
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Figure 4.6 Graph from the datasheet of Holtek HT12D encoder
As we understand from the datasheet of HT12A encoder that the encoder’s
oscillator frequency is 455 kHz. By using the formula given above, the recommended
oscillator frequency of decoder will be 455 kHz / 3 which is around 151.667 kHz. So,
plotting the graph line of supply voltage 5V with frequency of 151.667 kHz will yield
the resistance value of 51k Ω in approximation.
30
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Chapter 5 : Implementation of Software and Programming
5.1
Overview of Microchip MPLAB IDE and MPLAB C18 Compiler
For this project, development kit PICkit 2 with accompanied programmer
software is used to download the codes to the PIC18F2520 microcontroller. The
beauty of this MPLAB IDE is that it has its own integrated programmer for PICkit 2
without having to install the software. Although MPALB only supports assembly
language, it can be easily associated with the MPLAB C compiler which can be
downloaded from Microchip website.
Most of the traffic light projects done in the past as academic projects are
mostly in assembly language which is far more complicated and demand more
understanding of programming algorithm compared to C programming. Even in
implementation with C language, there are slight different in library and programming
format depending on the compilers used. But, microchip’s compiler, MPLAB C18
compiler, provides not only simplified C platform and resources but also available for
free with full features for certain period. Even in the period where some features are
restricted for free student version, it is still good enough for academic development
of projects.
31
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
5.2
Implementation of Algorithm and Considerations Involved for Multiple
Traffic Light Situations
The algorithm of traffic light controller is just like the one in the real world
except for the emergency vehicle priority system which is an evaluation of this
project. There are altogether three states which are catered for certain traffic
conditions. They are listed as follows:
5.2.1 Normal traffic condition state
5.2.2 Pedestrian crossing input state
5.2.3 Emergency vehicle priority request state
32
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
5.2.1 Normal traffic condition state
In normal traffic condition, the traffic sequence will operate independently with
pre-assigned fixed interval as programmed just like in the real life controller. In this
project, North-South traffic controller will start operating with Green light for the
incoming and outgoing traffic with Green man light for the pedestrian crossing. After
a while, the 7-segment display will start counting down from digit 9 with blinking
Green man until digit 0. At the same time, the opposite traffic will be under red light
for both traffic and pedestrian crossing. Once the counting down counter reaches
digit 0, the 7-segment display will black out and the pedestrian crossing will be under
Red man. The traffic will be under amber for a while and then become red.
Afterwards, the right turn arrow will be activated and the East-West traffic controller
will operate in the same manner.
Start
Initialization of Ports, variables, North-South and
East-West Traffic Light Controllers
A
N-S
Green access
direction
E-W is under Red
light for both vehicle
and pedestrians
E-W
N-S is under Red
light for both vehicle
and pedestrians
Display Green
light for vehicle
& pedestrian
crossing
Delay for a few, and scan pedestrian
and emergency input
Emergency priority
request received?
Yes
C
No
Display 7-segment display
starting from digit 9 and counting
down until digit 0 blinking the
Green man at the same time
33
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Delay for a few, and scan pedestrian
and emergency input
Emergency priority
request received?
F
Yes
E
Yes
B
No
Display Amber
light for the traffic
& Red light for
pedestrian
crossing
Delay for a few, and scan pedestrian
and emergency input
Display Red light
for both the traffic
& pedestrian
crossing
Pedestrian crossing
request received?
No
Display Turn right
LED for a while
and blink 5 times
before turning of
D
Changed traffic direction accordingly
(E-W to N-S/N-S to E-W)
A
Figure 5.1 Flowchart of standard Traffic Light Controller
34
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
5.2.2 Pedestrian crossing input state
This state is activated when either one of the two buttons assigned to
individual traffic controller is pressed. The steps involved in the sensing of the
pedestrian’s input are programmed in conjunction with the normal traffic condition
sequence. During the normal traffic sequence in certain steps, the reading of the
status of push button will be carried out. And another important fact in this algorithm
is that it will only sense the pedestrian’s input status of the other traffic yet not the
current traffic. For example, if the current traffic is under Green Light for North-South,
People will be crossing the road across East-West zebra crossing and the detection
for the status of that crossing is not necessary. So, at that situation, the scanning of
the status of pedestrian’s request for North-South will only be performed. Meanwhile,
it is not ideal to shorten the timing of Amber or Red light to give instant access to the
pedestrian crossing as it is not so critical as emergency vehicle. Therefore, once this
state is activated, the program will only shorten the duration of the right turn timing to
give faster access to the next sequence which is pedestrian crossing sequence.
B
Counter starts with
value 1
Blink Turn Right
LED once
Counter <=5
Yes
No
D
Figure 5.2 Flowchart of shortening the timing of Turn Right sequence when the
pedestrian on the opposite road requests passage access
35
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
5.2.3 Emergency vehicle priority request state
In this state, the algorithm is designed in such a way that once the request is
received, the traffic light controller will give instant access to the vehicle for passage
in the respective traffic if certain conditions are met. But it is not practical to suddenly
change from Green to Red light in one direction and give instant access of Green
light to the other. So, there is a condition for the vehicle to have instant access or
faster passage in a condition that the respective traffic must be under Green light
condition when the vehicle is on that road at the visible distance. The two options
available for faster passage is either by shortening the Red light or prolonging the
Green light duration. You can see the illustrations of this theory in the next page step
by step.
Red Light Timing Reduction
Green Light Timing Extension
Figure 5.3 Illustrations of Red Truncation and Green Extension Methods
In this project, the latter (green extension method) is used as it is more
practical and easier to implement. The principle of this state is simple with the fact
that so long as the receiver at the traffic light controller receive the request, it will
keep green access for the incoming vehicle until it receives another signal to
continue normal traffic operation. Furthermore, to be more visible of the difference
for the emergency system for this project, shorter delays are added for pedestrian
crossing and turn right timings of in process traffic controller once the request is
received from the other road. The flow charts below will demonstrate the functions of
these two conditions.
36
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
C
Set emergency state
delay to all the
respective stages of
the traffic sequence
until it changes to
other traffic direction
Return
Figure 5.4 Flowchart of emergency sequence when the vehicle is on
opposite road
E
Prolong the timing of
Green light for the
current Traffic Light
Controller for certain
period
Yes
Still receive the
emergency request
signal?
No
Prolong the timing of
Green light for the
current Traffic Light
Controller for certain
period
F
Figure 5.5 Flowchart of emergency sequence for prolonging the Green light
Timing
37
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Chapter 6 : Experimental Results and Modifications
6.1
Performance of Initial Circuit Design of Traffic Light Control and EVPS
In the earlier stages of the design, all the output components and devices
such as LEDs, buzzers and 7-segment LED were directly connected and
programmed. Each module of traffic light controller needs 3 x 6 LEDs, 1 x buzzer, 7
x LEDs of 7-segment and 1 x pedestrian input. So, total of 12 pins were needed for
individual controller and 24 pins for the whole traffic light project excluding the
Emergency Vehicle Priority System (EVPS). Furthermore, more complex
programming was necessary for this type of design. For example, just to make the
7-segment LED counts downwards automatically, reasonable amount of
programming procedure and sequence was required. After successfully simulating
the 7-segment LED display with direct connections and individual programming, it
was not desirable to use this design as it required too many ports.
Additional components such as 74LS193 and 7447 ICs were introduced in an
attempt to save further ports and reduce complexity in programming. And for the
clock input, 555 timer with astable mode was used to drive the count down process.
The most challenging part of the usage of this 555 timer was to synchronize with the
microcontroller clock pulse. For example, when the pedestrian crossing light is
blinking, the counter should count down single step every time the crossing light
blinks. In this case, we also have to bear in mind that the crossing light is driven by
the microcontroller while the 7-segment down-counter is driven by the oscillator. The
duty cycle is controlled by the 2 resistors.
Although the external oscillator was used as clock pulse source, this
technique was not desirable as there was slight deviation in duty cycle of the 555
timer output clock compared to microcontroller’s output. The performance of the 555
timer was also limited due to the tolerance of the components such as resistors and
capacitors.
Figure 6.1 Typical circuit diagram of astable 555 timer
38
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
For the EVPS of the initial design, it took quite long time to get the correct
transmitted data. This was due to the fact that during the earlier stages of the design
of the IR communication, the carrier frequencies of the transmitter and receiver were
overlooked. That is the reason why the transmission was not successful and the
original information cannot be recovered.
6.2
Performance of Final Circuit Design of Traffic Light Control and EVPS
Due to the inconsistent output of 555 timer, it was decided to use the clock
input directly from the microcontroller by using dedicated pin. Although it was
necessary to use subroutine as a delay to have the desired output square wave, the
process of programming was not that complicated for this part. Moreover, after
further consideration of the design, only one port was assigned as source for Green
man, Buzzer and 74LS193. This integration yields better performance in terms of
timing synchronization and saves many ports. After the final design, there were only
8 ports needed for each module compared to the initial 12 ports and resulted in
keeping extra ports for emergency vehicle priority system.
For the EVPS system in the final circuit design, the additional considerations
such as external components and oscillators were reduced by using Holtek encoder
and decoder pair which had built in carrier frequency suitable for infrared
transmission. And this frequency can be produced by using appropriate resistor
value which can be calculated with the data sheet provided. The main important fact
of using this pair is that the IR receiver must be operating in the same frequency
range as the transmitter which is 38kHz. Although the performance of this circuit is
quite good for an academic project, further improvement is necessary to apply in real
life activities to increase reliability and consistency.
The further improvement necessary for this design and real life practical
considerations are fully described in the recommendation part to further enhance this
design. Kindly refer to the appendices for the final design of microcontroller, traffic
light controller, IR transmitter and IR receiver modules.
39
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Chapter 7 : Conclusion, Recommendation and Additional
Modifications for Further Improvement
7.1
Conclusion
This academic traffic light controller consists of standard traffic light operation
with emergency vehicle priority system. Although it is academic based, it is intelligent
enough to operate in accordance with the user and infrared inputs. There are three
states namely normal state, pedestrian crossing state and emergency vehicle priority
state. In normal condition, the traffic sequence will be carried out in accordance with
the pre-assigned intervals for all traffic sequences. Once the pedestrians’ input is
activated, the traffic sequence will give priority to the pedestrian crossing by reducing
time interval in other traffic sequence.
For emergency vehicle priority state, infrared communication is used to
activate this state. The transmitter will send out signal from the assumed vehicle to
the receiver at the traffic light controller. Once the receiver gets the signal, it will keep
the state at green so as to let the vehicle pass through the traffic light controller and
waits until it receives another signal to resume its normal operation.
Although this project is academic based, it can be realized in the real world by
using long distance communication devices to further enhance the performance of
the system. More complicated algorithms can be applied to focus on more detailed
decisions in giving priority and increasing the capability of the traffic light controller.
In this application, infrared red communication is ideal for academic project in terms
of cost and performance but not practical as infrared is very sensitive to sun light and
this will degrade the performance.
Yet, this project is considered quite successful in the sense that it is functional
in all operations and all the objectives of the project is achieved as earlier planned in
the Gantt chart. There was no necessity to modify or amend the project plan or use
different devices. All the tasks were carried out as planned and the devices used
were purely based on the suitability with supervisor’s approval.
40
Application of Microcontroller in
Traffic Light Control
7.2
Maung Myat Min Maung(Y0402019)
Recommendation
In this project, there are a few areas that can be improved not for the Traffic
Light Controller but for the EVPS system by including additional components and
high-end devices. The followings can be done to further enhance the performance
and capability of the controller.
(1)
To get better controlled over all the I/O devices, it is better to have dedicated
ports for each function which means either using microcontroller with more ports or
using multiple microcontrollers which is expensive but effective.
(2)
To have secured and long range communication, infrared transmitter and
receiver can be replaced with RF transmitter and receiver which have encryption and
can communicate up to 100m.
(3)
If possible, it is better to use the detection technique of sound frequency as
the emergency vehicles normally turn the siren on whenever they are in urgency and
it is more practical that there is no need to on extra button for priority access. But
more advanced technique of algorithm and design is necessary as there are a lot of
things to be considered such as direction consideration, checking in and checking
out consideration and cost effectiveness as it might be expensive.
(4)
One of the efficient and up-to-date technologies to integrate Traffic Light
Controller and EVPS is using RFID technology just like in the ERP System. Although
this idea might already be realized and implemented, it will surely be quite effective
and practical. All the emergency vehicles are needed to install RFID module and the
detection modules have to be located before and after the station. Yet, my worry is
that it might not be cost effective and expensive for academic projects except there
is available sponsor from companies to implement.
41
Application of Microcontroller in
Traffic Light Control
7.3
Maung Myat Min Maung(Y0402019)
Additional Modifications for Further Improvement
As the main objective of this project was to learn the use of PIC18F2520 with
PICKit2 and MPLAB IDE for the application of microcontroller, it was quite time
consuming at the start of the project as everything had to be studied from
programming towards circuit design and software used. And by the time, after the
Traffic Light Controller was completed, there was only around two and a half months
left for me do literature review on available encoder and decoder pairs for the
communication system for the EVPS system. This time amount also shares the time
for FYP report writing and preparation for poster presentation. So, I was only able to
complete one set of a remote control with receiver of two relays that provide two
outputs for North-South and East-West roads. In this scenario, it is like the traffic
light is controlled by a remote control with the assumption that the transmitter is
installed at the vehicle and the driver needs to request the traffic light controller by
pressing transmit button. Therefore, it is better to have the system which has the
capability to detect the presence of the emergency vehicle and allows priority service
and automatically disable the service once the vehicle leaves the station. The current
and recommended design of Traffic Light Controller is illustrated as follows.
42
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
7.3.1 Current Traffic Light Controller Design
IR receiver to be installed at Traffic Light Post
Request for priority access
Figure 7.1 Vehicle requesting for priority access to prolong Green light (Check
in)
IR receiver to be installed at Traffic Light Post
Request to disable priority access
Figure 7.2 Vehicle requesting to disable priority access (Check out)
43
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
7.3.2 Recommended Traffic Light Controller Design
Figure 7.3 Recommended design of checking in and out using either IR transmitter or RFID chip
44
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
PART 2
Critical Review and Reflections
Although I have gone through many projects in my academic study in
Polytechnic and semester-based Micro-mouse project of SIM University, I have
never been in this feeling of accomplishment in the development of this Traffic Light
Controller.
I was given the opportunity to learn microcontroller in Micro-mouse group
project but the chances of programming and involvement were limited as it was
group-based and team work was necessary. For this FYP project, it is totally different
as it is an individual project everything from scratch to the final product is totally
dependent upon my own decision.
As the first stage, I had to learn C programming in MPALB C18 and tried to be
familiar with the MPLAB IDE environment. It was quite a slow start as lots of things
had to be gone through without knowing which part to be focused on. Even in the
earlier stages of software installation, most of the work didn’t go smooth as planned
as the accompanied software didn’t work well with the Windows Vista of my PC. So,
a few down loadings of up-to-date software and firmware from Microchip website
were needed and re-installations had to be carried out several times just to run test
program provided by the Supervisor.
Once the software installation and verification were successful, literature
review and component level programming were carried out. Component level
programming means writing small programs to integrate with individual component
such as LED, Buzzer, 7-segment LED display and switches. This task is compulsory
as it is the building block to carry on developing bigger and more intelligent projects.
Literature review was carried out by means of surfing internet, going through library
resources and IEEE journals. This activity gave me the idea of how most academic
traffic light controller worked and were designed. After component level programming
and integration were successful, I performed more advanced tasks by combining two
or more components to operate as desired. In my opinion, my way of researching is
time consuming in the earlier stages but fruitful in the later stages. This task speeds
up the process of creating the individual Traffic Light Controller Module. Before the
final design, all the circuits were tested on the bread board so as to save time in cost
and ease in modification and repair process. Only after the final design worked well
with the microcontroller, the circuit was assembled on the strip board and soldered
permanently.
In the beginning, the objective of this project is to appreciate the application of
microcontroller for Traffic Light Controller, the aim of the project was met earlier than
scheduled and additional task was carried which is the Emergency Vehicle Priority
System. Also for this system, literature review was performed to select proper
technique of communication and devices. Although RF communication would be an
ideal choice for real life in long distance communication, infrared communication was
selected due to its low cost and easy implementation for academic projects. Even in
infrared communication, there are quite a number of transmitters and receivers
popular for remote controlled applications. Motorola ICs( MC14457,MC14458,
MC145026, MC145027) encoder and decoder pairs were considered and reviewed
for the application. Yet, due to the lack of resources and poor availability on the
Singapore market, Holtek encoder and decoder pair (HT12A and HT12D) was used
for this infrared communication. The main factor of this decision was owing to its
45
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
lesser external components required and the other factor was that it would be
compatible with future modifications such as integrating with the RF communication
modules.
Although this project was completed successfully, it could be developed even
more advanced and intelligent by applying more complex algorithm and using higher
capable devices. For example, infrared transmitter and receiver modules can be
replaced with RF modules to interact longer distances without having to concern
about the disturbance of sun light. Algorithms can be programmed not only to
prolong the green light but also for the turning right vehicles and so on.
By undertaking this project, I have tremendously increased my knowledge in
the implementation and application of microcontrollers using C programming. I am
also confident in designing dc circuit design for the integration with microcontrollers
and other devices. Furthermore, I also learn to work in schedule and understand the
importance of project management skills. Even though undergoing this project for
one whole academic year is challenging and tiring, it also teaches me to be
independent and gives me the satisfaction of achievement that I have never
experience in my life before.
46
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Bibliography
1. Programmable Logic Device Traffic Light Project
http://joshuagalloway.com/2210ProjectII.pdf
2007
2. Micro controller programming: Making a set of traffic lights
http://www.instructables.com/id/Micro-controller-programming%3a-Making-a-s
et-of-traf/
2007
3. Traffic light controller project using AT89C2051 based on 8051
http://www.8051projects.net/downloads172.html
2007
4. FPGA-Based Advanced Real Traffic Light Controller System Design
El-Medany, W.M.; Hussain, M.R.;
Intelligent Data Acquisition and Advanced Computing Systems: Technology
and Applications, 2007. IDAACS 2007. 4th IEEE Workshop on
6-8 Sept. 2007 Page(s):100 - 105
Digital Object Identifier 10.1109/IDAACS.2007.4488383
5. Design and Development of Sensor Based Traffic Light System
http://www.scipub.org/fulltext/ajas/ajas331745-1749.pdf
American Journal of Applied Sciences 3 (3): 1745-1749, 2006
ISSN 1546-9239
© 2006 Science Publications
6. PIC project resources
http://computing.unn.ac.uk/staff/CGWH1/projects/ProjectResources2005.html
2005
7. PIC resources
http://pic-resource.com/index.html
2005
8. Optimal traffic light control for a single intersection (1998) [3 citations — 2 self]
by Bart De Schutter, Bart De Schutter, Bart De Moor, Bart De Moor
European Journal of Control
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.53.8227
9. Intelligent Traffic Lights Control By Fuzzy Logic
Kok Khiang Tan, 1Marzuki Khalid and Rubiyah Yusof
Malaysian Journal of Computer Science (ISSN 0127-9084)
http://mjcs.fsktm.um.edu.my/document.aspx?FileName=13.pdf
1996
47
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
10. Microchip Product Support
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeI
d=64
11. Traffic Signal Timing
http://ops.fhwa.dot.gov/publications/fhwahop08024/chapter9.htm
12. Mobile Infrared Transmitter(MIRT)
http://www.themirt.com/
13. Wikipedia
http://www.wikipedia.org/
14. Variable Traffic Light Controller
http://instruct1.cit.cornell.edu/courses/ee476/FinalProjects/s2003/rs234sy22
8/476/report.html
15. Simple 4-channel remote
http://electronics-diy.com/electronic_schematic.php?id=174
16. http://www.hobbyprojects.com/I/Infrared_Circuits.html
48
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
APPENDICES
Appendix A : Driver Board for PIC18F2520 Microcontroller and Traffic Light
Controller
Figure A.1 Driver Board of PIC18F2520 Microcontroller with Headers
Figure A.2 Pin assignments and descriptions of PIC18F2520 microcontroller
49
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Figure A.3 Schematic Diagram of Microcontroller Driver Board
50
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Figure A.4 Single Traffic Light Controller
51
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Appendix B : Driver Boards for Infrared Transmitter and Receiver
Figure B.1 Infrared Transmitter using Holtek HT12A
52
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Figure B.2 Infrared Receiver using Holtek HT12D
53
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Appendix C : C Program for the Traffic Light Control of Different Situations
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////
Designed and scripted by Maung Myat Min Maung, Y0402019, for
Final Year Project of BE(Electronics)
SIM University
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <p18f2520.h>
#include <delays.h>
#define East_West PORTAbits.RA6
#define North_South PORTCbits.RC6
#define ir_input_EW PORTBbits.RB5
#define ir_input_NS PORTBbits.RB7
#pragma config OSC = INTIO67
// description of what libraries and header files to be used
// assignment of port for pedestrian's input of East-West
//traffic
// assignment of port for pedestrian's input of North-South
//traffic
// assignment of port for emergeny vehicle's input of
//East-West traffic
// assignment of port for emergeny vehicle's input of
//North-South traffic
// use internal oscillator
int COUNT;
// variables should be declared outside main
int North_South_press, East_West_press;
int ir_input_EW_count, ir_input_NS_count,g; // declarations of variables for two pedestrian's inputs
// and two emergency inputs for counting purposes
void initialize(void)
{
PORTA = 0;
PORTB = 1;
PORTC = 0;
// Initialization function of all 3 ports
}
void normal_delay(void)
{
unsigned int a;
for(a = 0;a<30000;a++)
;
}
// normal delay for standard traffic condition
void pedestrian_input_delay(void)
// shorter delay for right turn arrow if pedestrian pressed push
//button
{
unsigned int b;
for(b = 0;b<10000;b++)
;
}
void emergency_state_delay(void)
// shorter delay for certain stages if traffic light receives
//emergency access request
{
unsigned int c;
for(c = 0;c<10000;c++)
;
}
54
Application of Microcontroller in
Traffic Light Control
void long_delay(void)
Maung Myat Min Maung(Y0402019)
// prolonged time for Emergency vehicle before updating the
//status of emergency port
{
unsigned int d;
for(d = 0;d<50000;d++)
;
}
void emergency_sequence_EW(void)
// function of prolonging the green access for emergency
//vehicle and detection of signal request
{
do
{
PORTA = 0x14;
long_delay();
ir_input_EW_count = 0;
if(ir_input_EW)ir_input_EW_count++; // once there is the presence of infrared signal,
//the count will be
}while(ir_input_EW_count !=0);
ir_input_EW_count = 0;
// increased by 1 and this loop will continue until count is 0
}
void emergency_sequence_NS(void)
// function of prolonging the green access for emergency
//vehicle and detection of signal request
{
do
{
PORTC = 0x14;
long_delay();
ir_input_NS_count = 0;
if(ir_input_NS)ir_input_NS_count++; // once there is the presence of infrared signal,
the count will be
}while(ir_input_NS_count !=0); // increased by 1 and this loop will continue until count is 0
}
void short_delay(void)
{
unsigned int c;
for(c = 0;c<5000;c++)
;
}
void main (void)
{
TRISA = 0x40;
TRISB = 0xFF;
TRISC = 0x40;
initialize();
while (1)
// the main program starts here
// port 6 is input and the rest are outputs
// port 4 and 5 are input ports and the rest are output ports
// port 6 is input and the rest are outputs
// loop forever
{
North_South_press = 0; // Resetting the counters of all inputs which includes push
East_West_press = 0; // buttons and sensors
ir_input_EW_count = 0;
ir_input_NS_count = 0;
55
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
/////////////////////////////////////////////////////////////////////////////////////////
///
East to West traffic sequence
///
/////////////////////////////////////////////////////////////////////////////////////////
PORTC = 0x11;
PORTA = 0x24;
normal_delay();
for (COUNT = 1; COUNT <= 8; COUNT++) // Counter for 7-segment LED display and
//Green Man
{
PORTA = 0x84;
PORTC = 0x11;
// blinking green man with green light for traffic
// red light for both red man and the traffic
if(North_South)North_South_press++; // detection of North-South push button
if(ir_input_NS)ir_input_NS_count++; // detection of North-South infrared sensor
if(ir_input_NS_count>0) // if emergency vehicle signal of North-South is received,
{
// it will execute shorter delay for counter
emergency_state_delay();
}
else
{
normal_delay();
// use normal delay if no emergency signal is
//received
}
if(North_South)North_South_press++;
PORTA = 0xE4;
PORTC = 0x11;
if(ir_input_NS_count>0)
{
emergency_state_delay();
}
else
{
normal_delay();
}
}
if(North_South)North_South_press++;
if(ir_input_EW)ir_input_EW_count++;
if(ir_input_NS)ir_input_NS_count++;
if(ir_input_EW_count>0)
{
emergency_sequence_EW();
}
PORTC = 0x11;
PORTA = 0x12;
if(North_South)North_South_press++;
56
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
if(ir_input_EW)ir_input_EW_count++;
if(ir_input_NS)ir_input_NS_count++;
if(ir_input_NS_count>0)
{
emergency_state_delay();
}
else
{
normal_delay();
}
if(North_South)North_South_press++;
if(ir_input_NS)ir_input_NS_count++;
if(North_South_press<=0)
{
PORTA = 0x19;
if(ir_input_NS_count>0)
{
emergency_state_delay();
}
else
{
long_delay();
}
}
for (COUNT = 1; COUNT <= 5; COUNT++) // will blink 5 times for turn right arrow
{
PORTC = 0x11;
// during this process, it will use normal delay
PORTA = 0x19;
// if there is no emergency signal and will use
if(ir_input_NS_count>0)
// short delay if the signal is detected
{
emergency_state_delay();
}
else if(North_South_press>0)
{
pedestrian_input_delay();
}
else
{
normal_delay();
}
PORTC = 0x11;
PORTA = 0x11;
if(ir_input_NS_count>0)
{
emergency_state_delay();
}
else if(North_South_press>0)
{
pedestrian_input_delay();
}
else
57
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
{
normal_delay();
}
}
////////////////////////////////////////////////////////////////////////////////////////
///
North to South traffic sequence
///
////////////////////////////////////////////////////////////////////////////////////////
PORTA = 0x11;
PORTC = 0x24;
// In this case, PORTA will be static and
if(ir_input_EW)ir_input_EW_count++; // only PORTC will change depending on
//sequence
normal_delay();
for (COUNT = 1; COUNT <= 8; COUNT++)
// Counting down sequence for North-South
//traffic
{
PORTC = 0x84;
PORTA = 0x11;
if(East_West)East_West_press++;
if(ir_input_EW)ir_input_EW_count++;
if(ir_input_NS)ir_input_NS_count++;
if(ir_input_EW_count>0)
{
emergency_state_delay();
}
else
{
normal_delay();
}
if(East_West)East_West_press++;
PORTC = 0xE4;
PORTA = 0x11;
if(ir_input_EW_count>0)
{
emergency_state_delay();
}
else
{
normal_delay();
}
}
if(ir_input_NS_count>0)
{
emergency_sequence_NS();
58
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
}
PORTA = 0x11;
PORTC = 0x12;
if(ir_input_EW_count>0)
{
emergency_state_delay();
}
else
{
normal_delay();
}
if(East_West)East_West_press++;
if(ir_input_EW)ir_input_EW_count++;
if(East_West_press<=0)
{
PORTC = 0x19;
if(ir_input_EW_count>0)
{
emergency_state_delay();
}
else
{
long_delay();
}
}
for (COUNT = 1; COUNT <= 5; COUNT++) // right arrow sequence for North-South traffic
{
PORTA = 0x11;
PORTC = 0x19;
if(ir_input_EW_count>0)
{
emergency_state_delay();
}
else if(East_West_press>0)
{
pedestrian_input_delay();
}
else
{
normal_delay();
}
PORTA = 0x11;
PORTC = 0x11;
if(ir_input_EW_count>0)
{
emergency_state_delay();
}
else if(East_West_press>0)
{
59
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
pedestrian_input_delay();
}
else
{
normal_delay();
}
}
}
}
60
Application of Microcontroller in
Traffic Light Control
Maung Myat Min Maung(Y0402019)
Glossary
Algorithm
Algorithm is an effective and systematic method in solving problems.
Astable mode
This mode is used in oscillator to generate free running continuous pulses.
Basic stamp 2
Basic stamp is a microcontroller which includes tiny Basic interpreter built into
ROM and usually programmed in conjunction with easy-to-use Basic
programming.
Capacitor
Capacitor is a dielectric electronic material or device and it has the property to
charge dc voltage and pass ac voltage.
Carrier frequency
Carrier frequency is the un-modulated wave which is the nominal frequency or
center frequency of the carrier wave.
Compiler
A compiler is the software or program which yields the assembly or executable
codes that machine or devices can understand and react.
Decoder
A decoder is the device that retrieves the encoded data to get the original
information.
Diode
EEPROM
A diode is a two terminal electronic device having P-N junction. An ideal diode
acts like a closed switch when it is forward biased and open switch when
reversed biased.
EEPROM is an Electrically Erasable and Programmable Read-Only Memory. It is
a non-volatile memory which is normally used in electronic devices such as
computers.
Encoder
An encoder is a device that converts original data to more secured and private
information.
EVPS
EVPS stands for Emergency Vehicle Priority System that give priority access to
those vehicles which are in need of urgency.
Gantt chart
Gantt chart is some type of bar chart in which important schedule and datelines
are plotted to be focused on.
Hall effect sensor
Hall effect sensor acts like a transducer which produces the voltage output with
response to changed in magnetic field. This sensor is mostly used in position and
speed sensing.
Microcontroller
Microcontroller acts like a small computer for electronic devices. Modern
microcontroller can be reprogrammed many times to control and execute
complicated tasks and functions in order to get desired goals.
MPLAB IDE
This is the environment where programmer writes and design codes and
programs to build intelligent microcontroller based systems.
Receiver
Relay
Receiver is a component or device that receives the transmitted signal.
A relay is a electronic device or switch that can be turned on or off by supplying
certain current or voltage to its supply terminals. And other terminals can be used
as switches. There are different types of relays such as single pole single
throw(SPST), single pole double throw(SPDT), double poles double
throws(DPDT) and so on.
61
Application of Microcontroller in
Traffic Light Control
Resonator
RFID
Schematic
SMD
Maung Myat Min Maung(Y0402019)
Resonator is a device that produces resonance frequencies.
RFID means Radio Frequency Identification which is widely used in wireless
identification such as ERP and automatic gate system for HDB carpark.
It is a electrical, mechanical or electronic drawing.
SMD means surface-mount devices that are normally mounted onto the PCB
boards. It is better option for mass production compared to through-hole
technology.
State diagram
A state diagram is the graphical presentation of the behavior of a system.
Strip board
This board is made of parallel strips of copper cladding in which holes are
distanced by 0.1 inch and widely used for prototyping.
Transistor
Transistor is a three terminal electronic device which is normally used as an
amplifier or as an electronic switch.
Transmitter
Transmitter is a device that transmits or propagates different types of signals with
the use of antenna or by other means of transmission.
Voltage regulator
This device maintains the output voltage at specific range which is compatible for
certain circuits and applications. It usually compares its output voltage with
internal reference voltage to regulate the output voltage. Depending on the
voltage required and applications desired, suitable output range of voltage
regulators are used.
62
Download