What to expect
How do vehicles like ambulances and fire trucks not get into accidents while speeding through traffic? Why do they never stop at traffic lights? In cities around the world, like Chicago, emergency response vehicles use infrared signals to coordinate with traffic controls. In this activity, we will build an intersection with two traffic lights that work together! Additionally, we will build in an emergency response condition similar to real life!
Connections
In the last activity, we used the radio controls to coordinate a train gate and a traffic light to keep everyone safe. In this activity, we will use a gate and two traffic lights to create a functioning intersection that allows emergency vehicles to pass through. Next week we will connect our traffic light to a game controller and go head-to-head against our friends to earn the highest score!
Materials
USB-A to Micro-USB Cable
STOP:bit (2)
ACCESS:bitt
Micro:bit (3)
Micro:bit Battery Pack (3)
Instructions
In this activity, we are creating a working intersection that is ready for an emergency situation nearby! We will start by coding a transmitter traffic light. This will be the micro:bit that sends out directions. Next, we will code a receiver traffic light that will respond to signals from the transmitter. This will give us a realistic traffic cycle. Finally, we will code our emergency gate to block traffic when an emergency vehicle passes.
Figure 1. Kitronik Access:bit Selection
Open make code studio and create a new project. Then, give your project a name. Click on the extensions button and then search “Access:bit” to select it as shown in Figure 1. You can create the code for the intersection on your own or you can download the code here.
Figure 2. Figure 2. Radio Set Group Selection
2. After you have added this add-on, you should have “ACCESS:bit” on the left- hand side. From here, we will start making the code for the gate. Under the “on start” block, add a set radio group as shown in Figure 2.
Figure 3. On Radio Received Number Block
3. Make sure to set a unique radio group that is not the same as any other group, or your code will interfere with other groups. Next we want to make an “on radio received” block and have it activated when a number is received as shown in Figure 3.
Figure 4. On Radio Received Number Block Condition Setting Preparation
4. Next, we want to set conditions for when and what will activate. Set if to be true if 3 is selected, and else if, when the number is either 0, 1, or 2 as shown in Figure 4.
Figure 5. On Radio Received Number Block Finalized Condition
5. Now we want to fill the statements so that some actions are taken when the statement is true. We want to set “if receivedNumber” at 3 to move the barrier down and play a melody. And in the “else if” set, stop all sounds and move the barrier up as shown in Figure 5.
Figure 6. The code for the intersection
6. We will construct the code for the other two micro:bits, one for the intersection (Figure 6) and the other for the traffic light (Figure 7). You can create the code for the intersection traffic light (Transmitter) on your own or you can download the code here.
Figure 7. The code for the traffic light
7. Likewise, you can create the code for the traffic light (Receiver) on your own or you can download the code here. Now, please make sure to set the radio groups so all this code works together.
8. Finally, set the gate and light next to each other and turn them on. The light will cycle on its own on the controller but if you press the A button you will watch as the gate comes down and the light turns red, giving way for any emergency vehicles, and then set back to its normal cycle all on its own.
Extension
Opposite traffic lights would not switch to green and red simultaneously. This might result in many crashes caused by drivers stopping too slowly or too early. To fix this, traffic lights are slightly offset to create a safety delay. How would you program this to the micro:bits to work together?
In real life, emergencies can happen anywhere! Emergency vehicles do not only drive in one direction. How would you program the micro:bit in the intersection to allow emergency vehicles to come from any direction?
Wrap-up
How did the use of a third micro:bit affect your ability to succeed in this challenge?
What other real life contexts need improved traffic flow?
Next Activity
In the next activity, you'll create and program a video game using a game controller that interacts with a traffic signal. You will use the game controller to navigate a busy city like Chicago!