Traffic Lights Project
Traffic Lights Project
Traffic Lights Project
A Project By
Perry Andrews
18 September 2004
Contents
Introduction....................................................................................................................2
Design and Development ...............................................................................................3
Construction.................................................................................................................10
Conclusion ...................................................................................................................12
References....................................................................................................................12
Introduction
With this project I wanted to develop a platform to experiment with traffic flow. The
starting point was to create a simple set of traffic lights for a ‘T’ junction commonly
found on British roads. The lights also include a filter light on one set of lights
allowing traffic to turn from the main road into the side road. This will be explained
further later.
A sensor is used to detect when cars are waiting to turn into the main road. The lights
change for a set period of time and then change back. See the flow chart later for
timings and sequence.
The idea is to expand the project later to make the traffic lights more intelligent. As it
stands the lights do not detect traffic flow and cannot allow for heavy traffic coming
from any direction.
From the road layout I could determine the basic steps required for the simple
simulator:
The flow diagram below contains this logic complete with the times:
The actual change of the traffic lights from red to green and back is not shown in the
flow diagram. The sequence in Britain is RED – RED & AMBER – GREEN and
GREEN – AMBER – RED. This is shown in the diagram below:
The reason red and amber are both lit together is so you can tell the next light in the
sequence is green and not red.
// Test Lights
init();
// turn on filter B
filter();
// wait 5 seconds
wait(8);
// wait 10 seconds
wait(15);
}
}
The program has seven sub programs including ‘main’ which all C programs must
have. ‘main’ is the first program to start and this is where the main program logic
resides. The steps are labelled and loosely tie up with the steps on the flow diagram.
This should make it easy to follow. The first sub program to be called is ‘init’ which
turns on the LED’s to test. The other sub programs are:
The changeToRed and changeToGreen sub programs are supplied with a character
denoting which set of lights to change A, B or C. There is a forth option D which
changes both A and B together.
The program uses about 350 blocks of the 1024 blocks allowed.
Red
+5V
Lights A
Orange
100R 1K 14
+VE 6 Green
4 RB0
MCLR 7
SW1 RB1
8
13 RB2
RB7 17
RA0
PIC 16F84 Red
16 18
OSC1 RA1
100n 1
22K RA2 Orange
3.2768MHz 2 Lights B
RA3
15 10
OSC2 RB4 Green
11
GND RB6 RB5 Green
5 12
10p 10p
Red
Lights C
Orange
Green
10 x 270R
0V
Figure 5 - Prototype
This project was constructed using Vero strip board, as it is quick to work with. A
parts list is shown below:
To start constructing the project I marked the positions of the LED’s. I grouped the
LED’s together as sets A, B and C. Set A is top right, B is top left and C is at the
bottom. This order is the same as shown on the road layout. Next the position of the
IC socket was found.
The socket was orientated so that the outputs used for the LED’s were in the best
position for the LED’s. I also located pin 5 of the socket on the same copper strip as
the LED cathodes to save an additional jumper wire. The socket was then soldered in
place and the copper strips cut between the pins of the IC socket. The resistors were
soldered in next along with the jumper wires. Next the switch and capacitors were
located and soldered in place. Last were the LED’s and the crystal.
All that was left to do was to plug in the PIC and connect the 5V supply to test.
My initial timings were reviewed after programming and running a test using the
development board. I found that one second between lights changing was not enough
so I increased the time to two seconds. The change of lights is much smoother
because of the change. I also increased the length lights ‘C’ were green from ten to
fifteen seconds.
1. Add buttons for lights ‘A’ and ‘B’ so the traffic can be detected on the main
road.
2. Change the program to detect traffic flow to determine the time each set of
lights are green.
3. Make the filter light work more intelligently by detecting if traffic is waiting.
4. Add another set of lights to work on crossroads.
References
Matrix Multimedia Ltd
C for PICmicro microcontrollers by Rob Miles
PIC Tutor development board
Crownhill Associates
Supplier of PIC developer boards and PIC Micro’s.