Design and Implementation An 8051 MCU Based Traffic Light Controller
Design and Implementation An 8051 MCU Based Traffic Light Controller
1.1 INTRODUCTION
Traffic lights make vehicle traffic control much easier, and more effective. Human reliability
is very small, compared to that of most automated systems for reasons that can’t be avoided.
It is therefore paramount to have the safest possible means of controlling vehicle traffic,
considering the fact that failure could result to loss of life and more.
There are two main colors in traffic lights. They are the red light and the green light. The
(amber), which could mean have different things depending on the manner in which it comes.
In most countries, the sequence is red (stop), green (go), amber (prepare to stop). In the UK,
New Zealand and Canada, amber officially means 'stop' (unless it would cause an accident to
do so) but in practice, is treated as 'prepare to stop'. In the UK, Hong Kong, Macau, Pakistan,
Germany, Hungary, Czech Republic, Poland, Denmark, Iceland and Israel, among others, the
sequence includes red and amber together before green, which helps draw attention to the
impending change to green, to allow drivers to prepare to move off. (In many of these
jurisdictions, such as the UK, it is customary for drivers to select neutral and/or use the
handbrake at red lights; the additional phase gives the driver time to select first gear or
release the handbrake before the light turns green). The single flashing amber signal is used
In some instances, traffic may turn right after stopping on a red (left in left-driving countries;
right in right-driving countries), providing they give way to the pedestrians and other
vehicles. In some cases which generally disallow this, a sign next to the traffic light indicates
this might forbid it at a particular intersection with a "no turn on red" sign, or might put a
1
green arrow to indicate specifically when a right turn is allowed without having to yield to
pedestrians (this is usually when traffic from the perpendicular street is making a left turn
onto one's street and thus no pedestrians are allowed in the intersection anyway). Some
jurisdictions allow turning on red in the opposite direction (left in right-driving countries;
right in left-driving countries) from a one-way road onto another one-way road; some of
these even allow these turns from a two-way road onto a one-way road. Also differing is
whether a red arrow prohibits turns; some jurisdictions require a "no turn on red" sign in
these cases.
The aim of this project is to design and implement a traffic light controller that utilizes the
8051 Microcontroller to implement the control sequence. It doesn’t have special features like
giving priority to sirens or congested lanes. The project is realized by the use of a flash
This traffic light controller consists of relatively few units out together. This is solely as a
result of the versatile nature of the microcontroller. The units involved in the realization of
A rectified power supply unit, stepping down the voltage from the mains to 12v and
converting it to 5v DC; the voltage level required for the implementation of this
project.
2
The microcontroller unit, which functions as the back bone of the project. It is
The display unit, which is made up of a collection of LEDs (light emitting diodes),
four LEDs representing each light display unit. Five light display units are required
for each display module and one display module is used for each side of the cross
junction.
The principle behind the operation of this traffic light controller is centered on the operation
of the microcontroller. The unique and broad range of application of the microcontroller
makes it suitable for the execution of the traffic light control sequence and assignment of
required states to each display at the appropriate time. The microcontroller sends the required
states (high or low) to the various LEDs at the required time, and it implements a delay for as
long as the present states are required. It then sends the next states expected after the time
required for the present states to be active has elapsed and it again implements the delay
required. The microcontroller does all these through a program that is written into it.
Chapter one gives an introduction to the concept of traffic lights, giving a little idea of the
general expectations of a traffic light control and an overview of the variations of different
3
rules applied to designing the control sequence. It also states the aims of the project and gives
Chapter two is a literature review of the operation principle of the various units and
components used in implementing the traffic light controller. It focuses mainly on the
Chapter three gives details of the design process and the methods by which the project was
implemented. It shows calculations involved in determining the components that were used,
and the factors that were considered. It also contains tables showing the sequence execution.
Chapter four contains the results that were obtained from each unit of the implemented traffic
light controller. It discusses the results, compares them to the expected theoretical results and
attempts to explain the reasons for any difference that may exist between the expected
Chapter five presents the summary of the thesis, suggesting improvements that can be done
and recommending methods or modifications that can reduce or eliminate the limitations this
4
CHAPTER TWO
THEORETICAL BACKGROUND
2.1 INTRODUCTION
In this part of this thesis, an attempt to describe the various blocks and units used implement
the traffic light controller is made. This is to enhance understanding of the operation of the
thesis, considering the fact that the entire traffic light controller is based on the various single
The traffic light controller upon which this thesis is based is based constitutes of three
Microcontroller Unit
Display Unit
Each unit performs a unique role in the implementation of the system. The individual units
work together, and they are linked to one another as described in the block diagram below.
5
POWER SUPPLY
MICROCONTROLLER
DISPLAY
The Power Supply unit is connected directly to the other units of the system. This is simply
because each unit requires electrical signals to operate. The microcontroller is connected to
the display as shown in the figure. It basically sends the information required to be displayed.
The microcontroller here doesn’t power the display, because it makes use of negative logic to
The theory of operation and function of each unit will be discussed in this chapter of the
thesis.
The power supply unit as the name implies is the part of the system that delivers the power
required for the operation of the entire system. A power supply is typical in every system. In
6
most electronics, relatively low voltages are required. This makes it impossible to use the ac
mains coming from a power grid to supply required excitation. As a result, is necessary to
provide a means of stepping down the voltage from the mains and this is conveniently done
by a transformer. In direct current (dc) systems (systems that make use of dc sources) it is
further required that the stepped down voltage is converted into a dc source. This conversion
is done a rectifier. The rectified signal is then filtered to make it as close as it can be to an
As shown in fig. 2.3, a basic Power Supply unit is made up of four main sections, namely:
The Transformer
The Rectifier
The Regulator
The requirements and mode of operation of each of the blocks will be discussed.
7
2.3.1 THE TRANSFORMER
The transformer steps down or steps up ac voltage. In other words, it either increases or
decreases the magnitude of ac voltage. This implies that it does not change the nature of the
signal. A transformer has two windings, the primary and the secondary windings. The
primary winding is the coil that is connected to the source, while the secondary winding
gives the output, which is either greater than the input (for a step up transformer) or less than
the input (for a step down transformer). The factor responsible for the degree of step up or
voltage, is the ratio of the number turns of primary winding to that of the secondary winding.
The transformer is a step down transformer if this ratio is greater than one, and a step up
transformer if otherwise.
In electronic circuits, step down transformers are more common, and the source primarily
used is the ac mains, which is 220/240v in Nigeria. This voltage is stepped down to a level
suitable for the circuit it is to be used in. The expression relating the ratio of the output
𝑁𝑠 𝑉𝑠
=
𝑁𝑝 𝑉𝑝
Vs=output voltage
Vp=input voltage
8
2.3.2 THE RECTIFIER
The rectifier is a circuit made up of four diodes. The function of this section of the Power
connected as shown in the circuit in fig. 2.3.2a. The circuit takes in ac voltage and gives a
rectified dc voltage as shown in fig. 2.3.2b. The rectified signal has ripples which have to be
removed in order to get a desired dc signal. This removal is done by a filter, which is a
Rectifier
9
2.3.3 THE FILTER SECTION
This section corrects the output waveform from the rectifier. It smoothens the signal and
makes it suitable for the circuit. A capacitor or a network of capacitors connected in parallel
can implement this. The selection of the smoothening capacitor depends on a number of
factors.
The regulator brings down the voltage from the capacitor to a certain fixed value. This means
that regardless of the voltage input to the regulator from the filtering section, the output of
the entire Power Supply, which comes from the regulator is at a fixed value.
A display is an output device, used to transmit results from circuit or device in a particular
format. For the purpose of this traffic light controller, the display used is a network of light
emitting diodes. Therefore in this part of the thesis, the light emitting diode commonly
The light emitting diode is similar to the normal power diode, except for the fact that it emits
visible light. LEDs just like regular diodes conduct only when the anode is positively biased
10
with respect to the cathode. It produces light when it is forward biased, and the intensity of
the light depends on the design of the diode and the supply voltage. They are generally low
Several LEDs can be connected together to increase the total intensity of the light they
produce. This finds application in many areas, such as 7 segment displays, moving message
displays and a lot of other lucrative appliances. For the purpose of this project, the LEDs are
connected in parallel to increase the intensity of each display unit. This is quite common,
because of the relative low power consumption of LEDs and the ease of understanding and
The specification of the LEDs used for the cause of this project is as shown below.
Current
11
The design is based on these characteristics. The current powering the LEDs is supplied by
resistors which are connected to the anodes of the LEDs. The value of the resistor determines
Microcontrollers’ producers have been struggling for a long time for attracting more and
more choosy customers. Every couple of days a new chip with a higher operating frequency,
more memory and more high-quality A/D converters comes on the market.
Nevertheless, by analyzing their structure it is concluded that most of them have the same (or
at least very similar) architecture known in the product catalogs as “8051 compatible”. What
The whole story began in the far 80s when Intel launched its series of the microcontrollers
labeled with MCS 051. Although, several circuits belonging to this series had quite modest
features in comparison to the new ones, they took over the world very fast and became a
The reason for success and such a big popularity is a skillfully chosen configuration which
satisfies needs of a great number of the users allowing at the same time stable expanding
(refers to the new types of the microcontrollers). Besides, since a great deal of software has
been developed in the meantime, it simply was not profitable to change anything in the
microcontroller’s basic core. That is the reason for having a great number of various
microcontrollers which actually are solely upgraded versions of the 8051 family. What is it
12
what makes this microcontroller so special and universal so that almost all the world
As shown on the previous picture, the 8051 microcontroller has nothing impressive at first
sight:
128Kb RAM (including SFRs as well) satisfies basic needs, but it is not imposing
amount.
4 ports having in total of 32 input/output lines are mostly enough to make connection to
As it is shown on the previous picture, the 8051 microcontroller have nothing impressive at
first sight:
13
The whole configuration is obviously envisaged as such to satisfy the needs of most
microcontroller is that nothing is missing and nothing is too much. In other words, it is
created exactly in accordance to the average user‘s taste and needs. The other advantage is
the way RAM is organized, the way Central Processor Unit (CPU) operates and ports which
Pins 1-8: (Port 1: P1.0 – P1.7) each of these pins can be configured as input or output.
Pin 9: (Reset) RS Logical one on this pin stops microcontroller’s operating and erases the
contents of most registers. By applying logical zero to this pin, the program starts execution
from the beginning. In other words, a positive voltage pulse on this pin resets the
microcontroller.
Pins10-17: (Port 3: P3.0 – P3.7) Similar to port 1, each of these pins can serve as universal
input or output. Besides, all of them have alternative functions as follows:
Pin 10: (P3.0) RXD Serial asynchronous communication input or Serial synchronous
communication output.
Pin 11: (P3.1) TXD Serial asynchronous communication output or Serial synchronous
communication clock output.
14
Pin 16: (P3.6) WR Signal for writing to external (additional) RAM
Pin 18, 19: (X2, X1) Internal oscillator input and output. A quartz crystal which determines
operating frequency is usually connected to these pins. Instead of quartz crystal, the
miniature ceramics resonators can be also used for frequency stabilization.
Pin 21-28: (Port 2: P2.0 – P2.7) If there is no intention to use external memory then these
port pins are configured as universal inputs/outputs. In case external memory is used then
the higher address byte, i.e. addresses A8-A15 will appear on this port. It is important to
know that even memory with capacity of 64Kb is not used (i.e. note all bits on port are used
for memory addressing) the rest of bits are not available as inputs or outputs.
Pin 29: (PSEN) If external ROM is used for storing program then it has a logic-0 value every
time the microcontroller reads a byte from memory.
Pin 30: (ALE) Prior to each reading from external memory, the microcontroller will set the
lower address byte (A0-A7) on P0 and immediately after that activates the output ALE.
Upon receiving signal from the ALE pin, the external register (74HCT373 or 74HCT375 circuit
is usually embedded) memorizes the state of P0 and uses it as an address for memory chip.
In the second part of the microcontroller’s machine cycle, a signal on this pin stops being
emitted and P0 is used now for data transmission (Data Bus). In this way, by means of only
one additional (and cheap) integrated circuit, data multiplexing from the port is performed.
This port at the same time used for data and address transmission.
Pin 31: (EA) By applying logic zero to this pin, P2 and P3 are used for data and address
transmission with no regard to whether there is internal memory or not. That means that
even there is a program written to the microcontroller, it will not be executed, the program
written to external ROM will be used instead. Otherwise, by applying logic one to the EA
15
pin, the microcontroller will use both memories, first internal and afterwards external (if it
exists), up to end of address space.
Pin 32-39: (Port 0: P0.0 – P0.7) Similar to port 2, if external memory is not used, these pins
can be used as universal inputs or outputs. Otherwise, P0 is configured as address output
(A0-A7) when the ALE pin is at high level (1) and as data output (Data Bus), when logic zero
(0) is applied to the ALE pin.
All 8051 microcontrollers have 4 I/O ports, each consisting of 8 bits which can be configured
as inputs or outputs. This means that the user has on disposal in total of 32 input/output lines
1=input. If a pin on the microcontroller needs to be configured as output, then a logic zero (0)
should be applied to the appropriate bit on I/O port. In this way, a voltage level on the
Similar to that, if a pin needs to be configured as input, then a logic one (1) should be applied
to the appropriate port. In this way, as a side effect a voltage level on the appropriate pin will
be 5V (as it is case with any TTL input). This may sound a bit confusing but everything
becomes clear after studying a simplified electronic circuit connected to one I/O pin.
16
Input/output(I/O)pin
concerns all pins except those included in P0 which do not have embedded pull up resistor.
Port 0
It is specific to this port to have a double purpose. If external memory is used then the lower
address byte (addresses A0-A7) is applied on it. Otherwise, all bits on this port are
ports consisting of pins with embedded pull-up resistor ( connected by its end to 5 V power
supply ), this resistor is left out here. This, apparently little change has its consequences:
If any pin on this port is configured as input then it performs as if it “floats”. Such input has
When the pin is configured as output, it performs as “open drain”, meaning that by writing 0
to some port’s bit, the appropriate pin will be connected to ground (0V). By writing 1, the
external output will keep on “floating”. In order to apply 1 (5V) on this output, an external
Port 1
This is a true I/O port, because there are no role assigning as it is the case with P0. Since it
17
Port 2
Similar to P0, when using external memory, lines on this port occupy addresses intended for
external memory chip. This time it is the higher address byte with addresses A8-A15. When
there is no additional memory, this port can be used as universal input-output port similar by
Port 3
Even though all pins on this port can be used as universal I/O port, they also have an
alternative function. Since each of these functions use inputs, then the appropriate pins have
to be configured like that. In other words, prior to using some of reserve port functions, a
logical one (1) must be written to the appropriate bit in the P3 register. From hardware’s
perspective, this port is also similar to P0, with the difference that its outputs have a pull-up
resistor embedded. The port has pins that are used for other purposes
When configured as outputs ( logic zero (0) ), single port pins can "receive" current of 10mA.
If all 8 bits on a port are active, total current must be limited to 15mA (port P0: 26mA). If all
ports (32 bits) are active, total maximal current must be limited to 71mA.
18
When configured as inputs (logic 1), embedded pull-up resistor provides very weak current,
The microcontroller memory is divided into Program Memory and Data Memory. Program
Memory (ROM) is used for permanent saving program being executed, while Data Memory
(RAM) is used for temporarily storing and keeping intermediate results and variables.
Depending on the model in use ( still referring to the whole 8051 microcontroller family) at
most a few Kb of ROM and 128 or 256 bytes of RAM can be used.
All 8051 microcontrollers have 16-bit addressing bus and can address 64 kb memory. It is
neither a mistake nor a big ambition of engineers who were working on basic core
Program Memory
The oldest models of the 8051 microcontroller family did not have internal program memory
. It was added from outside as a separate chip. These models are recognizable by their label
beginning with 803 (for ex. 8031 or 8032). All later models have a few Kbytes ROM
embedded, Even though it is enough for writing most of the programs, there are situations
when additional memory is necessary. A typical example of it is the use of so called lookup
tables. They are used in cases when something is too complicated or when there is no time
19
for solving equations describing some process. The example of it can be totally exotic (an
using non-linear thermo element or asynchronous motor speed control). In those cases all
needed estimates and approximates are executed in advance and the final results are put in
20
Fig. 2.5.3a : 8051 Memory Organization
EA=0 In this case, internal program memory is completely ignored, only a program stored in
EA=1 In this case, a program from built in ROM is to be executed first (to the last location).
in both cases, P0 and P2 are not available to the user because they are used for data nd
address transmission. Besides, the pins ALE and PSEN are used too.
21
Data Memory
As already mentioned, Data Memory is used for temporarily storing and keeping data and
intermediate results created and used during microcontroller’s operating. Besides, this
microcontroller family includes many other registers such as: hardware counters and timers,
input/output ports, serial data buffers etc. The previous versions have the total memory size
of 256 locations, while for later models this number is incremented by additional 128
available registers. In both cases, these first 256 memory locations (addresses 0-FFh) are the
base of the memory common to all types of the 8051 microcontrollers. Locations available to
the user occupy memory space with addresses from 0 to 7Fh. First 128 registers and this part
The first block consists of 4 banks each including 8 registers designated as R0 to R7. Prior to
access them, a bank containing that register must be selected. Next memory block ( in the
range of 20h to 2Fh) is bit- addressable, which means that each bit being there has its own
address from 0 to 7Fh. Since there are 16 such registers, this block contains in total of 128
bits with separate addresses (The 0th bit of the 20h byte has the bit address 0 and the 7th bit
of th 2Fh byte has the bit address 7Fh). The third group of registers occupy addresses 2Fh-
7Fh (in total of 80 locations) and does not have any special purpose or feature.
In order to satisfy the programmers’ permanent hunger for Data Memory, producers have
embedded an additional memory block of 128 locations into the latest versions of the 8051
22
microcontrollers. Naturally, it’s not so simple…The problem is that electronics performing
addressing has 1 byte (8 bits) on disposal and due to that it can reach only the first 256
locations. In order to keep already existing 8-bit architecture and compatibility with other
Using trick in this case means that additional memory block shares the same addresses with
existing locations intended for the SFRs (80h- FFh). In order to differentiate between these
two physically separated memory spaces, different ways of addressing are used. A direct
addressing is used for all locations in the SFRs, while the locations from additional RAM are
23
Fig. 2.5.3b: 8051 memory bank
24
2.5.4 SFRs (Special Function Registers)
SFRs are a kind of control table used for running and monitoring microcontroller’s operating.
Each of these registers, even each bit they include, has its name, address in the scope of
RAM and clearly defined purpose ( for example: timer control, interrupt, serial connection
etc.). Even though there are 128 free memory locations intended for their storage, the basic
core, shared by all types of 8051 controllers, has only 21 such registers. Rests of locations are
intentionally left free in order to enable the producers to further improved models keeping at
the same time compatibility with the previous versions. It also enables the use of programs
written a long time ago for the microcontrollers which are out of production now.
A Register (Accumulator)
This is a general-purpose register which serves for storing intermediate results during
operating. A number (an operand) should be added to the accumulator prior to execute an
instruction upon it. Once an arithmetical operation is preformed by the ALU, the result is
placed into the accumulator. If a data should be transferred from one register to another, it
must go through accumulator. For such universal purpose, this is the most commonly used
25
register that none microcontroller can be imagined without (more than a half 8051
B Register
B register is used during multiply and divide operations which can be performed only upon
numbers stored in the A and B registers. All other instructions in the program can use this
26
Registers (R0-R7)
This is a common name for the total 8 general purpose registers (R0, R1, R2 ...R7). Even
they are not true SFRs, they deserve to be discussed here because of their purpose. The bank
is active when the R registers it includes are in use. Similar to the accumulator, they are used
for temporary storing variables and intermediate results. Which of the banks will be active
depends on two bits included in the PSW Register. These registers are stored in four banks in
The following example best illustrates the useful purpose of these registers. Suppose that
27
MOV A,R3; Means: move number from R3 into accumulator
accumulator)
MOV R5, A; Means: temporarily moves the result from accumulator into R5
This is one of the most important SFRs. The Program Status Word (PSW) contains several
status bits that reflect the current state of the CPU. This register contains: Carry bit, Auxiliary
Carry, two register bank select bits, Overflow flag, parity bit, and user-definable status flag.
The ALU automatically changes some of register’s bits, which is usually used in regulation
P - Parity bit. If a number in accumulator is even then this bit will be automatically set (1),
otherwise it will be cleared (0). It is mainly used during data transmission and receiving via
serial communication.
- Bit 1. This bit is intended for the future versions of the microcontrollers, so it is not
supposed to be here.
OV Overflow occurs when the result of arithmetical operation is greater than 255 (deci mal),
so that it can not be stored in one register. In that case, this bit will be set (1). If there is no
28
RS0, RS1 - Register bank select bits. These two bits are used to select one of the four
register banks in RAM. By writing zeroes and ones to these bits, a group of registers R0-R7
Space in
RS1 RS2
RAM
Bank0
0 0
00h-07h
Bank1
0 1
08h-0Fh
Bank2
1 0
10h-17h
Bank3
1 1
18h-1Fh
CY - Carry Flag is the (ninth) auxiliary bit used for all arithmetical operations and shift
instructions.
These registers are not true ones because they do not physically exist. They consist of two
separate registers: DPH (Data Pointer High) and (Data Pointer Low). Their 16 bits are used
29
for external memory addressing. They may be handled as a 16-bit register or as two
independent 8-bit registers. Besides, the DPTR Register is usually used for storing data and
A value of the Stack Pointer ensures that the Stack Pointer will point to valid RAM and
permits Stack availability. By starting each subprogram, the value in the Stack Pointer is
1. After any reset, the value 7 is written to the Stack Pointer, which means that the space of
RAM reserved for the Stack starts from this location. If another value is written to this
register then the entire Stack is moved to a new location in the memory.
In case that external memory and serial communication system are not in use then, 4 ports
with in total of 32 input-output lines are available to the user for connection to peripheral
environment. Each bit inside these ports corresponds to the appropriate pin on the
microcontroller. This means that logic state written to these ports appears as a voltage on the
pin ( 0 or 5 V). Naturally, while reading, the opposite occurs – voltage on some input pins is
The state of a port bit, besides being reflected in the pin, determines at the same time whether
it will be configured as input or output. If a bit is cleared (0), the pin will be configured as
output. In the same manner, if a bit is set to 1 the pin will be configured as input. After reset,
30
as well as when turning the microcontroller on, all bits on these ports are set to one (1). This
31
CHAPTER THREE
3.1 INTRODUCTION
This chapter gives details on the considerations made and the factors responsible for the
specific components used in the implementation of the traffic light controller. The traffic
light controller in this project is based on a busy cross-junction, having at least three lanes on
each side (NORTH, EAST, SOUTH and WEST). The system assumes that there are
tributary routes before the junction on each side, and encourages motorists turning to the left
or right to use those routes instead of waiting to get to the junction before turning. This is in
vehicle more time to turn either right or left, than it takes it to move straight across the
junction.
The system also gives time slots for pedestrians to cross the road from whichever side they
are standing, stopping all vehicles moving along the path they are crossing for the allocated
time period.
Fig. 3.2 is a representation of the ‘GO’ states implemented in the traffic light controller. It
shows the transitions in states where vehicle traffic on the four sides are allowed to move.
32
Source: Traffic Advisory Leaflet 1/05, February 2004
In the first stage, all vehicles coming from the south side intending to move in any direction
are allowed to proceed. The same is done in the 4th, 5th and 8th states, for vehicles coming
from the north, west, and east sides respectively. In states two and three, vehicles crossing
from the north to the south and those crossing from the south to the north, are given the
signal to proceed. All vehicles turning to the left or right side from the north or south side are
not allowed to move. This gives a chance for pedestrians on either the south or north side of
the junction, to cross over to the other side. Likewise in states 6 and 7, the vehicles crossing
form east to west or vise versa, are allowed to move on, giving a chance or pedestrians
crossing from the east to the west or vice versa, to over to the other side of the road.
33
34
Table 3.2: Complete Traffic Light Sequence
STATE 1 TRANS 1 STATE 2 TRANS 2 STATE 3 TRANS 3 STATE 4 TRANS 4 STATE 5 TRANS 5 STATE 6 TRANS 6 STATE 7 TRANS 7 STATE 8 TRANS 8
RED 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
NORTH YELLOW 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0
SIDE GREEN 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0
L TURN 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
R TURN 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
RED 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0
EAST YELLOW 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1
SIDE GREEN 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0
L TURN 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
R TURN 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
RED 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0
SOUTH YELLOW 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1
SIDE GRREEN 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0
L TURN 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
R TURN 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RED 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1
WEST YELLOW 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0
SIDE GREEN 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0
L TURN 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
R TURN 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
35
Table 3.2 shows the status of each display in the system throughout the cycle. It also gives
information of the status on the displays during the transition states, where the amber light
There are a total of five display displays on each side. A ‘1’ on any display in any state or
transition period (TRANS) reveals that the display is ON. While a ‘0’ indicates that the
display is OFF. The main states last for 30seconds, while the transition states last for
5seconds.
3.3 DISPLAY
The design that was carried out for the display section was mainly in connection to the
current limiting resistors used to drive the display units in the section. Each display has four
LEDs, and it is typical that an LED has a current limiting resistor of 330Ω. The displays used
in the traffic light controller, each had a total of four LEDs, and is represented in fig. 3.3.
36
The current coming into the circuit is spited to the four LEDs. Since it is typical that a 330 Ω
resistor is used in supplying current to one LED, it is ideal that a resistor of 1320 Ω (330
Ωx4) is used to power such a display. However due to the unavailability of this resistor
5
𝐼= = 5𝑚𝐴 . . . 3.3.1
1000
There are a total of 20 displays, hence the total current drawn by the display section is
All stages in this project use +5v. The power supply stage is a linear power supply type and
involves a step down transformer, a bridge rectifier, filter capacitor, and voltage regulator to
give the voltage level. The power supply circuit diagram is shown below.
37
Figure 3.4 Power Supply
Transformer
The transformer needed is a 220/12V; 1A step-down will be more than sufficient to supply
the current required to various components. However, it is still used so that here is a wide
margin of safety.
The rectifying section uses 4 diodes, each having the ability of handling 25V and 1A. The
diodes used were all IN 4004. The diodes are connected to implement a full wave bridge
The choice of the filter capacitor is dependent on the output current. Given that
2.4×𝐼𝑑𝑐
Vr(rms) = . . . 3.4a
𝐶𝑓
38
Cf = Filter capacitor (F)
= 12𝑉 × √3
= 20.78V
5
𝑉𝑟(𝑟𝑚𝑠) = × 20.78
100
= 1.04V
Therefore,
2.4×𝐼𝑑𝑐
𝐶𝑓 = . . . 3.4c
𝑉𝑟(𝑟𝑚𝑠)
2.4 × 0.1
𝐶𝑓 =
1.04
= 720µF
39
Voltage Regulator
The microcontroller and LEDs in this project need a voltage of 5V. The voltage regulator that
was used in this project has a current rating of 1A and a minimum input voltage of 7.3V. this
The microcontroller that was selected for the purpose of this project was the 89C51
ports, and only two ports are required for the project.
The crystal used to generate the clock was a 4MHz crystal. This was used instead of the more
popular 12MHz crystal, because the loop required to achieve the 30second delay becomes a
40
CHAPTER FOUR
Tests were carried out at the various sections of the traffic light controller. The digital meter
was the main instrument used in carrying out the tests. The sections that gave testable tesults
In this section, voltages were taken at different points, and the results were as follows:
The main result here is the output voltage at the regulator, which is the voltage level supplied
to the rest of the system. The calculated voltage level at the output of the power supply
(which corresponds to the voltage level at the regulator) was 5V. However, from the readings
obtained, it was 0.05 volts greater. This is acceptable, considering the fact that the deviation
was by only 1%, and the microcontroller has a tolerance of over 10%. This makes the power
supply useful, and therefore it can still be used for the purpose of this project.
41
4.3 DISPLAY SECTION
In the display section, the voltages across the resistors supplying the driving current to the
displays were measured. The output across the resistors were not too far from the calculated
values,
42
CHAPTER FIVE
5.1 CONCLUSION
The circuit was designed within the operating limits of the components used. The results
obtained form the various sections constituting the traffic light controller showed some
integrity in the design. The traffic sequence was executed as proposed and designed, meaning
that the system was realized. There was however a little deviation in the results obtained
from some of the sections, indicating that the design was not perfect. A little modification
may solve that problem, making the system of generally acceptable standard.
5.2 RECOMMENDATIONS
The system designed has several draw backs. It is a very simple traffic light controller, with
no special features. Considering the fact that a microcontroller is used in the implementation
of the project, it is possible to include a whole lot of additional features into the system. The
lines connecting the microcontroller to the display units can be multiplexed, so that one port
is used to realize the system, increasing the number of ports available for the implementation
of other features. Features that can be added to the implemented system may include an
emergency sequence, which gives priority to ambulances and fire fighting vehicles whenever
it senses sirens corresponding to their frequencies. It could also include another sequence for
43
hours when traffic is less intense. All these can be done with the aid of a few additional
components.
44
REFERENCES
Paul, H. and Winfield, H. (1995), “The Art of Electronics”; Second edition, Cambridge
Robert, L. B. and Louis N. (1996), “Electronic Devices and Circuit Theory”; Sixth edition, New
Scott I. M.,(1995), “The 8051 Microcontroller”; Second Edition,. R . Donneley and Sons
45
APPENDIX A
46
APPENDIX B
47
APPENDIX C
Source code
MOV TMOD,#01H
MOV 80H,#00H
MOV 90H,#00H
JMP START
MOV P0,#11000111b
CALL DELAY1
MOV P1,#10110111b
MOV P0,#11010111b
CALL DELAY2
MOV P1,#11010111b
48
CALL DELAY1
CALL DELAY2
CALL DELAY1
MOV P0,#10110111b
CALL DELAY2
MOV P1,#11000111b
MOV P0,#01110111b
CALL DELAY1
MOV P1,#10110111b
MOV P0,#01111011b
CALL DELAY2
MOV P1,#01110111b
MOV P0,#01111100b
CALL DELAY1
MOV P1,#01111011b
MOV P0,#01111101b
CALL DELAY2
49
MOV P1,#01111101b
CALL DELAY1
CALL DELAY2
CALL DELAY1
MOV P0,#01111011b
CALL DELAY2
MOV P1,#01111100b
MOV P0,#01110111b
CALL DELAY1
MOV P1,#01111011b
MOV P0,#10110111b
CALL DELAY2
LJMP START
50
MOV TL0,#0B0H
SETB TR0
CLR TF0
CLR TR0
DJNZ R7,REPEAT1
RET
MOV TL0,#0E5H
SETB TR0
CLR TF0
CLR TR0
DJNZ R6,REPEAT2
RET
51
APPENDIX D
(a)
(b)
52
(c)
53