|R- Red, Y- Yellow, G-Green, GL- Green Left|
Traffic light system was one of the fascinating applications of Embedded systems and have been using the same till this day. I have previously posted a simple Traffic light system for one way roads with small timings check it out if you are interested in it. This is the four way traffic light system using embedded systems which was bit complex in nature as we need to consider the traffic flow in four different directions providing appropriate timings to each of the lights.
This system uses 8051 microcontroller ( AT89C52) , 7-segments and LED's for indication. The LED's which was used as lights was connected to the Microcontroller by means of common Anode configuration. In this configuration the Microcontroller was used to sink the current from the LED to its ports. That means logic 0 signal in the Microcontroller switches the LED ON and logic 1 signal switches the LED off. Here we are using 6 MHz crystal for the 8051 Microcontroller operation and you can use upto 12MHz crystal with this controller.
COMMON CATHODE 7-SEGMENT:
In this design, we are about to use a Common Cathode 7-segment in which the LED's are connected in a manner sourcing from the Microcontroller. As you can see in the above pin configuration there is two common ground pins, we can use any one of it. The 7-segment should be connected to the port in the following order P2.0 to pin "a" of the 7 segment, P2.1 to b , P2.2 to c and ends up with P2.7 to h. These are the connection configurations and components we are going to use in this 4-way Traffic light system using 8051 Microcontroller.
The above diagram illustrates the traffic flow layout of the four way road. And this is just a model of the four way road ,schemes and layout may subjected to change. I have chose this one for easier explanation of the traffic flow.
The traffic flow can be classified in to four phases in the above diagram and i have considered the North as starting point of this traffic flow. And in the above scheme vehicles are allowed to make a free right turn so we need to consider only two directions straight and left. So the green signal was classified into two types one for G for permitting vehicle to proceed forward and GL for permitting vehicles to left.
- Initially Vehicle from A needs to travel to F and from E to B roads.
- So in the first Phase forward green signal in A and E permits vehicles to pass through while East and west roads are stopped by red signal.
- Phase II permits the vehicle to pass from G to D and from C to H roads.
- Traffic flow from rest of the two roads North and south was stopped by means of Red signal.
- Phase three permits traffic flow in the left directions from A to D and from E to H.
- Traffic flow in East and west are stopped by means of red signal.
- Phase four permits traffic flow from C to F and from G to B.
- Traffic flow in the North and south are stopped by means of red signal.
- The cycle repeats again from Phase I to Phase IV and thus the traffic is regulated.
The above scheme is just an example and are subjected to change in real time roads, as different four way traffic flow schemes are followed widely around the world. This illustration was aimed to make you understand the flow and guide in designing the system according to the flow of traffic.
TIMING OF THE SIGNALS:
The timing is one of the important factor to consider in a traffic light system. Here in this design i have programmed in such a way a red light will be on for 50 seconds and 10 seconds for Yellow light. So adding up a traffic flow or a Green signal will be On for 60 seconds totally before switching the flow to the next phase.
The 7 segment was used in this design to to display the timing to the vehicle users in the road. This ease up the vehicle users and provides knowledge of the timing left before the switching of the next signal.
PROGRAM OF TRAFFIC LIGHT SYSTEM:
The coding was done using Embedded C language using IDE 8051 software. The code was given below.
ROOM FOR MODIFICATIONS :
- Modifying the array can extend your timings to different lights.
- Changing the lighting schemes or increasing the phases can be done by replacing the signal bits in the program.
- Additional lights for pedestrian can be added just by connecting LED's parallel to the ports, MC capable of sinking currents of multiple LED's.
- Array can be extended upto 90 seconds of timing.
I have also added the Proteus simulation file and hex file of this program below. Get the files here
Share this with others through social networks if you like it. Feel free to post your comments and opinions regarding this post and i am happy to help you with queries. Thank you for visiting and Happy Coding.