2.6
Automatic Dragster Race Course
Automatic Dragster Race Course
What to Expect
In this activity we will combine all of the dragster race car labs that you have already created into one automatic racetrack. Using the micro:bit’s “Radio” (i.e. Bluetooth) function, all of your groups’ micro:bits can communicate with each other, and the whole race sequence can be automated. When you are ready to begin the race, you will simply press “A” on the Countdown Circuit, and the rest will happen automatically! The automatic dragster race sequence will look like this:
“A” button is pressed on the Countdown Circuit micro:bit
The Countdown Circuit counts down to the race, then sends a signal to the dragster race car to start moving
The dragster race car starts moving, then crosses the race track “Start” line
The race track timing circuit begins timing the race
The dragster race car crosses the “Finish” line
The race track timing circuit sends a signal to the dragster race car to stop
The race track timing circuit displays the elapsed time
Connections
In the last three activities, we built a micro:bit-powered dragster race car, a set of countdown lights, and a drag race track. Today we will combine all three of these components to make an automatic drag race that you control with the push of one button.
Materials
Completed micro:bit dragster race car
Completed countdown circuit
Completed dragster race course track
USB cable to connect computer to micro:bit
Instructions
To create the automatic dragster race, we need to modify the code for all three components: 1. the countdown circuit, 2. the race track, and 3. the car. The micro:bits controlling each of these components need to communicate with each other using the micro:bit’s “Radio” function.
Modifying the Countdown Circuit
The countdown circuit will function similarly to the way it did before, with one exception: when the countdown is finished, it will send a signal to the car to start moving. We need to update the code on the countdown circuit micro:bit to make this small change.
Go to the code for this circuit by clicking here: Countdown Circuit with Automatic Start. Click “Edit” in the upper right corner of the screen. Pause here, and take a moment to think about what this code will do. Note that at the end of the “on button A pressed” loop, the variable “GO” is set to 1 for two seconds before it is changed back to 0. Also note that in the “forever” loop, if “GO” is equal to 1, the micro:bit will send a radio signal of 1.
2. **Important: In the “on start” block, change the radio group to a number that is different from any other group in your classroom. Otherwise, there will be interference. The radio group can be any number from 0 to 255.
3. Connect your car’s micro:bit to the computer with the USB cable and download the code to your micro:bit (instructions) Test out the code by pressing button A. You should hear the countdown sounds and see the arrow moving across the micro:bit LED screen.
4. Connect the micro:bit to the LED strip like you did in the countdown circuit activity. Refer back to that activity if you need a refresher **Hint: red wire to P2, green wire to 3V, and white wire to GND
Test that the circuit is functioning properly by pressing button A. You should hear the sounds, see the arrow on the micro:bit LEDs, and see the colors on the LED strip.
A summary of how this code works
When button A is pressed, the micro:bit plays the countdown sounds and lights up the LEDs in order.
At the end of the countdown, the variable “GO” is set to 1, then there is a 2 second pause, and then “GO” is set back to 0.
In the “forever” loop, whenever the variable “GO” is equal to 1, the micro:bit will send a radio signal of 1. So, at the end of the countdown sequence, the micro:bit will send a radio signal of 1 for two seconds, while “GO” is equal to 1. The dragster race car will receive this signal and start moving.
Modifying the Race Course Circuit
The race track circuit will also function similarly to the way it did before, with one exception: when the dragster race car crosses the finish line, the race track micro:bit should send a signal to the car to stop moving. We need to update the code on the race track timing circuit micro:bit to make this small change.
5. Go to the code for this circuit by clicking here: Automatic Race Course Timing. Click “Edit” in the upper right corner of the screen. Pause here, and take a moment to think about what this code will do. Note that when P1 is pressed (when the car crosses the Finish line), the race course micro:bit will send a radio signal of 2.
6. **Important: In the “on start” block, change the radio group to the same number that you used in the countdown circuit.
7. Connect your micro:bit to the computer with the USB cable and download the code to your micro:bit (instructions). Connect the micro:bit to the race track like you did in the race track construction activity. Refer back to that activity if you need a refresher **Hint: green Start line wire to P0, red Finish line wire to P1, and both black wires to GND.
8. Test that the circuit is working correctly by pressing on the Start line to simulate a car driving over it, then pressing on the Finish line to simulate a car driving over it. The micro:bit should display the elapsed time.
A summary of how this code works
When pin P0 is pressed, indicating a car has driven over the Start line: the micro:bit records the starting time and sets a variable “EnableTimer” equal to 1.
When pin P1 is pressed, indicating a car has driven over the Finish line: if “EnableTimer” is equal to 1, then the micro:bit will record the finish time and send a radio signal of 2.
The micro:bit will calculate the elapsed race time, display the elapsed race time in seconds, and set the variable “EnableTimer” back to 0.
Note: the variable “EnableTimer” is used to ensure that the Finish line is only “active” after something has crossed the Start line. In other words: there cannot be a Finish time unless there is first a Start time.
If button A is pressed, the micro:bit will display the elapsed race time again.
Modifying the Dragster Race Car
The dragster race car will also function similarly to the way it did before, with two changes: the car will start moving when it receives a radio signal of 1 from the countdown circuit, and it will stop moving when it receives a radio signal of 2 from the race track circuit. We need to update the code on the dragster race car micro:bit to make these small changes.
9. Go to the code for this circuit by clicking here: Dragster with Auto Start and Stop. Click “Edit” in the upper right corner of the screen. Pause here, and take a moment to think about what this code will do. Note that when a radio signal of 1 is received, the motors will turn on, and when a radio signal of 2 is received, the motors will turn off.
10. **Important: In the “on start” block, change the radio group to the same number that you used in the countdown and race track circuits.
11. Connect your car’s micro:bit to the computer with the USB cable and download the code to your micro:bit (instructions). Test that the entire automatic drag race system is working correctly by pressing button A on the countdown circuit. After the countdown is complete, the car’s wheels should start to spin. Then press on the Start line to simulate the car driving over it, then press on the Finish line to simulate the car driving over it. The car’s wheels should stop spinning, and the race track micro:bit should display the elapsed time.
You are ready to race your dragster down the race track! How fast can it go?
A summary of how the dragster race car code works
When the car receives a radio signal of 1 from the countdown circuit, both motors are turned on to drive the car forward.
When the car receives a radio signal of 2 from the race track circuit, both motors are turned off.
If button B is pressed, this will also turn the motors off. It is helpful to have this separate way of turning the car off, in case there is a problem with the race track circuit.
Think about it
How fast does your dragster race car go? Hint: Speed = Distance / Time
What would happen if several groups have their micro:bits set to the same radio group?
Could you use your dragster race car with another group’s race track? Why or why not?
Feedback Link
How did you feel about this activity? Change the emoji to show your feelings.
Next Activity We will turn your race car into a remote control car, using another micro:bit as the remote control.