Traffic lights, also known as traffic signals, traffic lamps, signal lights, stop lights and robots, and also known technically as traffic control signals are signalling devices positioned at road
intersections, pedestrian crossings and other locations to control competing flows of traffic. Traffic lights were first installed in 1868 in London and are now used all over the world.
Traffic lights alternate the right of way accorded to road users by displaying lights of a standard color (red, yellow, and green) following a universal color code. In the typical sequence of color phases:
the green light allows traffic to proceed in the direction denoted, if it is safe to do so
the yellow light denoting prepare to stop short of the intersection, if it is safe to do so
the red signal prohibits any traffic from proceeding
well, there are several types of Signals, some are for vehicles, railways, airplanes. But we will proceed in road traffic signals.
Usually, you can also see that in some country like india (which has very large population and road traffic), while switching of signal light. there is no yellow light in between the transition of signal light from red to green. Instead, yellow light glows in between the transition of light from green to red. Actually, logic behind this functioning is that, if a car is at high speed comming towards crossing and signal is going red very soon, in that case driver will get prenotification by yellow light that he has to stop the car to avoid accident.
On other hand, i have seen on european roads that while transiting to green from red light, yellow light is turned on for some seconds. In jmy personal opinion, reason behind this, is that there is no count-down at red signals in europe(like germany) where drivers of vehicle waiting at red signal gets nothing about the timming information that when they will be allowed to go, or when lights will be green.
Before, we proceed, i highly recommend you to read detailed information 8051 microcontroller intro & programming environment setup.
Here is the snapshot of the setup, which we will make in this tutorial. You can see that, there are four sets of signal LEDs for all four sides. Note that, in this particular tutorial, i have not included the right and left turn lights. For simplicity, we will just make these four sets functional without any extension of countdowns or turn lights.
Now for further information i want you to see my youtube video embedded here. In this video, i have explained the working of this project.
I hope that, you have clear understanding about the circuit through this video. I have not given a seperate circuit diagram to you people because i want you to understand the working and not just see and make circuits. But after this video, you could still not figure out how to make circuit on this board or at your custom board then for that, i have made a small PDF file for all the steps you should follow, while making this circuit. you can download this file from here. With this, you can also download the codes of 8051 microcontroller interfacing and specially the code for this project on this git link.
A bit code explaination
Below given code snippet of this project.
Our code is divided into 3 C source files. one is just to test all LEDs circuits and other two are functional mode of traffic light controll system. In one mode, only Yellow light blinks (low traffic) and in other mode is the default one, where you will see the normal functionality of the traffic light controller.
Lets discuss the main code, which is written for normal functionality of traffic light. Code contains several global declaration with sbit keyword which gives us the access to single pin to which only one LED is connected individually. With this, you can also see that i have also declared array for all three traffic signal with size 4 where at index (0 to3), all the 4 sides are considered.
Now, lets discuss about the makegreen() function of this code. This function is used to set the green light on the side depending upon value of i parameter. It takes this input integer and change the lights array on that index, which after that are used to initialize the main identifier holding LED pin status.
Thirdly, in main function, you can see while(true) loop, inside it, we are calling makegreen() function, after that, i have written code for transition of Lights. Please note that the delay function call inside the makegreen() is the time delay for the state of Red and green signals, On the hand the delay(2000); which is used in while braces in main function, is the time of transition from green to red through yellow light transition.
Obviously, i cant explain you whole code line by line. Its so long, but i have already divided this project into smaller modules. You can find articles about them in Learning sections. And also, i if you dont know how to compile and then burn the hex file into your microcontroller, then follow this tutorial.
I hope this article helped you. Please feel free to comment below or contact me, for any query. :)