How to build a traffic light?

Facts about traffic lights:

The world’s first traffic light was a gas-based traffic light, installed in London in December 1868. Sadly, it exploded less than a month after it was implemented, injuring the policeman that operated the traffic light. Earnest Sirrine from Chicago patented the first automated traffic control system in 1910. It used the words “STOP” and “PROCEED”, although neither of the words lit up.

Facts about traffic lights:

The world’s first traffic light was a gas-based traffic light, installed in London in December 1868. Sadly, it exploded less than a month after it was implemented, injuring the policeman that operated the traffic light. Earnest Sirrine from Chicago patented the first automated traffic control system in 1910. It used the words “STOP” and “PROCEED”, although neither of the words lit up.

The world’s first electric traffic signal was put in place on the corner of Euclid Avenue and East 105th Street in Cleveland, Ohio, in 1914.

Traffic lights alternate the right of way accorded to users by displaying lights of a standard colour (red, amber (yellow), and green) following a universal colour code (also referred to signal colours).

In the typical sequence of colour phases: The green light allows traffic to proceed in the direction denoted if it is safe to do so and there is room on the other side of the intersection. The amber (yellow) light warns that the signal is about to change to red. And a red light indicates all must stop.

In a smart city, traffic lights can do much more than only controlling the traffic in a fixed manner. Since there are so many traffic lights in a city, and each of them is provided electrical power while mostly being installed high above the ground, it can also act as data collection points. Video camera and sensors could be installed to see if there are too many people or cars waiting for a signal to change and adjust the signal accordingly. The speed of vehicles, pedestrians and cyclists can also be collected and stored in the cloud for further analysis and future city planning. The connected traffic lights could talk to each other to cooperate together to make the traffic run smoother and faster, according to the current demand. This form of a traffic light backend system is called Intelligent Transportation System (ITS) and requires a central Traffic Management Center (TMC) to control it.

How to build a simple traffic light with MuseLab micro:bit Booster:

Step 1. Install the red, yellow and green LED on Pin 0, Pin 1, Pin 2 of the Shield respectively.

Step 2. Watch the video clip below and record the signal pattern.

Step 3. Write down the time interval of the traffic light in the table below

Time (s) Red Yellow Green
0-5
5-10
10-15
15-20
20-25
25-30
30-35
35-40
40-45
45-50
50-55
55-60
60-65
65-70
70-75
75-80
80-85
85-90
90-95
95-100
100-105
105-110
110-115
115-120
120-125
125-130
130-135
135-140
140-145
140-145

Step 4. Build the traffic light.

Below we are using the Muse Traffic Light of the Muse Mechanical Set I (3in1)

Step 1

Step 1

Step 2

Step 2

Step 3

Step 3

Step 4

Step 4

Step 5

Step 5

Step 6

Step 6

Step 7

Step 7

Step 8

Step 8

Complete

Complete

Step 5. Write the code!

Use the forever blocks to repeat the steps. Use the pause block  to wait where ms means 1/1000 of a second. Use digital write pin block   to turn on or off a certain pin by assign value of 1 and 0. A typical Hong Kong traffic light logic would be similar to the below example.

 

Let’s start making your own traffic light now, Enjoy!

Some inspirations: Why not adding a button to let pedestrians cross the street!?