3.2.2
RC Car
RC Car
Have you ever seen the movie Ford v Ferrari? The Le Mans is a auto race in France that lasts 24 hours. Cars exceed 320 kilometer per hour and at night the brakes glow red due to 1000 degree Celsius temperatures.
The Ferrari 250 LM won the Le Mans in 1965 and inspired the very first commercial RC car!
Images credit: top image https://www.ferrari.com/en-EN/auto/250-lm; bottom image instagram Motoring Attitude
What to expect
Today we will start adding features to the model electric vehicle that you built in the last activity. In this activity, we will use a game controller as a remote control, and we will use it to drive the car that you built last week. The remote control will be programmed with a micro:bit and will use the radio feature to send commands to the vehicle.
Connections
In this activity we will add remote control capability to the :MOVE motor electric vehicle. In the next several weeks we will add several more capabilities, like the ability to follow lines on the ground and the ability to communicate with other devices.
Materials
Kitronik :MOVE motor car
Kitronik ARCADE game controller
(2) Micro:bits (one for the car and one for the game controller)
(7) AA batteries (4 for the MOVE motor car + 3 for the ARCADE controller)
USB connection cable for the micro:bit
Instructions
In this activity we will use a micro:bit for the game controller, and another micro:bit to control the :MOVE motor car. The two micro:bits will communicate with each other, allowing us to control the car with the game controller.
I. Program the game controller
Figure 1: Kitronik ARCADE game controller highlighting the direction buttons, on/off switch, and micro:bit slot
The game controller has a lot of input buttons, which means we could use it in a lot of different ways. The buttons that we will use today are the up, down, left, and right buttons on the left side of the controller. Also notice the on/off switch and the slot for the micro:bit on the top side of the controller. For now, leave the on/off switch in the OFF position.
Figure 2. Change the “radio set group” number to a unique number between 0 and 255.
2. Plug one of your micro:bits into your computer using the USB cable, then go to this site to download the code for the game controller: https://makecode.com/_Fy8TAP02RHuX
Click the “Edit Code” button. This takes you to the MakeCode Arcade programming site. Notice what the code will do: when you press a direction button, the image on the LCD screen will change, and it will send a radio signal.
Change the number in the “radio set group” block to a number between 0 and 255 that no other group in your classroom is using. This is to prevent interference. Remember this number, because you will set your car’s micro:bit to the same number.
Figure 3. MakeCode tile for Kitronik Arcade for micro:bit
3. Click “Download” in the lower left corner of the screen. You will be asked to “Choose your hardware”. Scroll down and select the “Kitronik Arcade for micro:bit” tile shown below (not “Kitronik ARCADE”, which does not use a micro:bit).
Figure 4: Micro:bit inserted in controller. Note the LED array and buttons on the micro:bit facing
4. Upload the file to the micro:bit by dragging it from the Downloads folder to the micro:bit drive. Then unplug the micro:bit from your computer.
Insert three AA batteries into the game controller, paying attention to the + and - side of the batteries. Then slide the micro:bit into the slot in the game controller with the micro:bit’s buttons and LEDs facing up toward you.
You are ready to test the game controller! Slide the on/off switch to ON. You should see a vehicle sprite on the LCD screen, and the direction of the vehicle should change when you push a different direction button. If it doesn’t work, i. check the direction of the batteries, ii. check the direction of the micro:bit in the slot, and iii. re-download the code to the micro:bit.
II. Program the :MOVE motor car
Figure 5. “Forward” function. When this function is called, this block of code applies 30% power to the left and right motors, displays an up arrow on the micro:bit LEDs, and turns the car’s front LEDs to white and the rear LEDs to red.
Set aside the game controller, and plug your other micro:bit (the one you will use for the car) into your computer with the USB cable. Then go to this site to download the code for the :MOVE motor car: https://makecode.microbit.org/_RjjJJt8FPAvu
Click the “Edit Code” button. This takes you to the MakeCode programming site. The code may look complicated, but it’s actually straightforward. The “on start” block sets the radio channel, turns the car’s LEDs off, and sets the initial values of several variables. The “on radio received” block receives inputs from the game controller. The “forever” loop takes the input from the game controller and calls a specific function. In coding, a function is a set of instructions for a specific purpose. Each individual function (Forward, Reverse, Left, Right, Stop) drives the motors and turns on LEDs in a unique way.
Figure 5. Change the “radio set group” number to the same number between 0 and 255 that you used for the game controller code.
2. Change the number in the “radio set group” block to the same number between 0 and 255 that you used in the game controller code.
Figure 6. Make sure the side of the micro:bit with the buttons and LED lights is facing forward
3. Click “Download” in the lower left corner of the screen. Then upload the file to the micro:bit by dragging it from the Downloads folder to the micro:bit drive.
Unplug the micro:bit from your computer and insert it into the slot on the car. Make sure the side of the micro:bit with the buttons and LED lights is facing forward.
Turn the car’s on/off switch to ON. If the code is working properly, you will see an “X” on the micro:bit LEDs. If it doesn’t work, i. check the direction of the car’s batteries, ii. check the direction of the micro:bit in the slot, and iii. re-download the code to the micro:bit.
Now you are ready to test the remote control car! Make sure both the game controller and the car are powered on, and set the car on the floor. You should be able to drive the car around the room with the game controller. Notice how the LED lights on the car and the LEDs on the car’s micro:bit change when the car changes direction.
If your car doesn’t drive straight ahead when you push the up arrow, try adjusting the left and right motor speed settings in the Forward function.
Optional Extensions
Set up an obstacle course in your classroom, and see how fast you can drive your car around the course. Who can complete the course fastest?
What happens when you press the forward and right (or left) buttons at the same time? Can you look at the car’s code and see why it does this? (Hint: look at the “forever” loop, and the sequence of the blocks within it)
Wrap-up
In this activity we used the game controller, the :MOVE motor vehicle, and the micro:bit radio function to create a remote control car.
Could you use the A or B buttons on the game controller to make the car do something else?
Why could it be a problem to have every remote control car on the same radio group?
How else could you use the game controller?
Next Activity
Party! In next week’s activity we will program the car to move all by itself. We will use the built-in microphone on the micro:bit, and make the car move and dance to the music that it “hears”.