2.7
Remote Control Race Car
Remote Control Race Car
What to Expect
In this activity we will turn your race car into a remote control car, using another micro:bit as the remote control. We will do this by using the “radio” (i.e. Bluetooth) communication between the two micro:bit devices.
Connections
In the last car activity, we built an automatic drag race track that you controlled with the push of one button. Today we will re-purpose your dragster race car and turn it into a remote control car.
Materials
Completed micro:bit dragster race car
Another micro:bit to be used as a remote control
USB cable to connect computer to micro:bit
Instructions
There are two steps to this activity. First, we will modify the micro:bit code for the race car. Second, we need to create the new micro:bit code that will be used for the remote control.
Programming the Car
In the previous activity, the car’s motors were switched on when the countdown circuit’s micro:bit sent a radio signal for the car to start. The car’s motors were switched off when the race track timer circuit’s micro:bit sent a radio signal for the car to stop after it sensed that the car had crossed the finish line. In today’s activity, we will not use the countdown circuit or the race track timer.
Instead, we want to use another micro:bit as a remote control. We will use the remote’s “A” button to control the motor driving the car’s left wheel, and the remote’s “B” button to control the motor driving the car’s right wheel. Think of this control scheme as similar to a bulldozer, a skid steer, or a tank.
Go to the code for this circuit by clicking here: RC Car. Click on “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 the car’s motors will do different things depending on what radio signal is received by the remote control micro:bit.
2. In the “on start” block, change your car’s 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. Connect your car’s micro:bit to the computer with the USB cable and download the code to your micro:bit (instructions). You should see a single LED light in the middle of the micro:bit LEDs. If so, the car is ready!
A summary of how this code works
When the car receives a signal of “1” from the remote control, it will turn the left motor on at high power and the right motor on at low power.
When the car receives a signal of “2” from the remote control, it will turn the right motor on at high power and the left motor on at low power.
When the car receives a signal of “3” from the remote control, it will turn both motors on at full power.
When the car receives a signal of “4” from the remote control, it will turn both motors off.
If the “B” button is pressed on the car’s micro:bit, it will also turn the motors off.
Code for the Remote Control
We need the remote control micro:bit to send a “1” radio signal to the car when we want to power the left motor, a “2” signal when we want to power the right motor, a “3” signal when we want to power both motors, and a “4” signal to turn both motors off.
To do this, the program on the remote control micro:bit will “read” the position of button A and button B. Button A is internally connected to the micro:bit’s connection pin P5, and button B is internally connected to pin P11. When button A is pressed, the program will “read” a value of 0 on pin P5, and when button A is not pressed, the program will read a value of 1 on P5. When button B is pressed, the program will “read” a value of 0 on pin P11, and when button B is not pressed, the program will read a value of 1 on P11. We can use this information to construct the logic that you will see in the program.
3. Go to the code for this circuit by clicking here: RC Car Remote. Click on “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 the remote control’s micro:bit will send different radio codes depending on the status of pin P5 (button A) and pin P11 (button B).
4. **Important: Make sure your car and your remote control are set to the same radio group, and make sure that no other group in the room is using the same radio group as you. The radio group can be any number from 0 to 255. Connect your remote control micro:bit to the computer with a USB cable and download the code to your micro:bit (instructions)
You should see a single LED light in the middle of the micro:bit LEDs. If so, the remote is ready!
You are now ready to test your car. Try creating an obstacle course, and see who in your group can drive your car around the obstacle course the fastest!
A summary of how this code works
When button A is pressed and B is not pressed, pin P5=0 and pin P11=1. The remote sends a radio signal of “1”.
When button A is not pressed and B is pressed, pin P5=1 and pin P11=0. The remote sends a radio signal of “2”.
When button A is pressed and B is pressed, pin P5=0 and pin P11=0. The remote sends a radio signal of “3”.
When button A is not pressed and B is not pressed, pin P5=1 and pin P11=1. The remote sends a radio signal of “4”.
Think about it
This code is written so that the A button on the remote control causes the left wheel of the car to spin, and the B button on the remote control causes the right wheel of the car to spin. How could you program it so that pressing the A button causes the car to turn left, and pressing the B button causes the car to turn right?
Could you program the car so that it is capable of going in reverse? Note: there is a third input button on the micro:bit, called the logo button, that is directly above the array of LEDs.
Feedback Link
How did you feel about this activity? Change the emoji to show your feelings.
Next Activity The next unit brings us from electric vehicles to air quality. Why are electric vehicles such an important part of solutions to climate change?