MYP Design · Year 8 · Radio control

Coding the Cars 2

Today one micro:bit becomes a remote in your hand. Tip it, and the micro:bit inside your TPBot hears the message and drives. Then take on the challenge course.

  • One car, two micro:bits
  • Seven steps
  • Three challenges
A B battery Remote: tip to steer forward Car: drives what it hears
Computer accessIf your laptop will not connect to the micro:bit, sit with a classmate whose laptop has downloaded code before, and build on theirs together.

Radio on the micro:bit

Every micro:bit has a small radio built in. It sends short messages through the air to other micro:bits nearby: no wires and no internet. You tip the remote, it sends a message such as forward, and the micro:bit in the car hears it and drives. Your pair has one car and two micro:bits. Write your answers on the handout as you go.

Today's steps

Open each step as you reach it. The pictures match what you will see in MakeCode.

1Your radio group is your car's numberOnly micro:bits in the same group hear each other.

Your car's number is on its label. Write it on your handout. Use it as the radio group in both programs, with radio set group in on start. Every pair then drives only its own car, even with eight cars in the room.

2Add the TPBot blocks to MakeCodeFour clicks. Do it in the car project too.

Start a new project called remote. Then add the TPBot extension:

  1. Open ExtensionsAt the bottom of the block list, click Extensions.The Extensions button at the bottom of the MakeCode block list.
  2. Search for TPBotType TPBot in the search box and press Enter.The Extensions search box with TPBot typed in it.
  3. Click the TPBot cardClick the picture of the blue car.The TPBot extension card.
  4. The teal drawer appearsA teal TPBot drawer joins the list.The teal TPBot drawer in the block list, above Extensions.
3Program the remoteProject remote: tip it, and it shows an arrow and sends a message.

Build it

  1. In on start, put radio set group 1 and change 1 to your car's number.
  2. Each forever holds a while from Loops, with is logo down gesture from Input in its gap.
  3. Inside goes radio send forward. To name a message, click the dropdown, choose New message and type forward. Make back, left, right and stop the same way, all in small letters.
  4. Above each radio send, add show arrow pointing the way the car will go, and show icon with a cross for stop. Now the remote's screen shows what you are sending.
  5. Download it to the micro:bit that stays in your hand.

The blocks

The remote. Tip forward, back, left or right to drive, and the screen shows an arrow; shake to stop.
The remote. Tip forward, back, left or right to drive, and the screen shows an arrow; shake to stop.
The pink Radio drawer in MakeCode.

The pink Radio drawer holds radio set group. Scroll down the same drawer for radio send and on radio … received.

To find any block fast, type its name in the Search box at the top of the block list, for example gesture.

4Program the carProject car-2: each message sets the two wheel speeds.

Start a project called car-2 and add the TPBot extension (step 2). Use the same group number and the same five message names as the remote. Download it to the second micro:bit and slot that one into the car.

The blocks

The car. One block for each message.
The car. One block for each message.
MessageLeft wheel, right wheel
forwardboth +50
backboth −50
left−50 and +50
right+50 and −50
stopstop the car

The idea. Opposite wheel speeds spin the car on the spot, as on Friday. The car keeps doing its last order until a new message arrives, so stop is a message too.

5Drive itTry each move and write what the car did.

Switch the car on, on the floor. Hold the remote flat, screen up.

You do this with the remoteThe remote showsMessage sent
Tip the logo down↑forward
Tip the logo up↓back
Tilt left←left
Tilt right→right
Shake✕stop

Write what the car did for each one in the table on your handout.

6Tune it for the courseChange the percentages until it drives the way you want.

Your car may need different percentages on its wheels to drive perfectly straight, or to turn more smoothly. You decide what to change. Change a number in car-2, download, and drive again. Write what you changed and what happened on your handout.

7The challengesRemote only, hands off the car. Record your best time for each.

Drive with the remote only: hands off the car once it starts. Record your tries and best time for each.

  1. 1. The straight laneDrive the length of the classroom down one lane, perfectly straight, touching nothing.
  2. 2. Round the tablesDrive all the way around the three rows of student tables.
  3. 3. Table-leg slalomWeave in and out of the legs of one row of tables. The hardest of the three.

Test, change one thing, test again. After each challenge, change one percentage in car-2 that would make the next run better, and write down whether it helped. This is how designers work.

To go further

  • Turn the headlights green on forward and red on stop, with Set headlight color to.
  • Make gentler turns: try 0 and 50 for left instead of −50 and 50.
  • Design challenge 4 for another pair: mark it with tape, write its rules, and time their best run.
The tilt remote and car programs are Mr. Rawson's, after ELECFREAKS TPBot Case 05. Block pictures and screenshots are from Microsoft MakeCode. The first radio lesson is on the Radio page, and the robot car lessons on Coding the TPBot.