Understanding traffic signal
A traffic signal has three LEDs, green, yellow, and red, which are either horizontally, or vertically, mounted.
When two roads cross, you need two pair of two traffic signals for all directions. A pair of two traffic signals behave identically, when one is red, the other is also red. Let’s say one pair is “Signal 1”, and the other is “Signal 2”.
- When Signal 1 is green, Signal 2 must be red.
- When Signal 1 becomes red from green, it must become yellow first, and then red.
- When Signal 1 is yellow, Signal 2 must stay red.
- When Signal 1 is green or red, it must stay that color for 5 seconds.
- When Signal 1 is yellow, it must stay yellow for 1 second.
The logic of the traffic lights above is described in a chart, called flow chart. A flowchart describes what a program does.
Signal 2: Green); R_G -- 5 sec --> R_Y(Signal 1: Red
Signal 2: Yellow); R_Y -- 1 sec --> G_R(Signal 1: Green
Signal 2: Red); G_R -- 5 sec --> Y_R(Signal 1: Yellow
Signal 2: Red); Y_R -- 1 sec --> R_G;
Create two traffic signals with six LEDs. Connect them to an Arduinol. Write a program that implements the logic above.
Other lessons in Electronics Basic Course: