← Robotics challenges

Remote control

One micro:bit sends numbers by radio; the robot turns each number into a move.

Rescue robots go into collapsed buildings and bomb-disposal robots up to suspicious bags, while the person driving stays far away and safe. Each button press is a short message over radio.

In micro:bit Foundations you sent radio messages between micro:bits. Now the messages drive a robot. The remote sends a number for each button; the robot listens and turns each number into a move. Both micro:bits must be in the same radio group.

When a program uses radio, the simulator shows two micro:bits and two robots, running the same program. Each micro:bit is a remote for the other robot.

PredictRead the code and say what it will do before you run anything. A wrong guess is fine: it shows you what to look for.

Predict

The program as blocks
Show as code
remote.ts
input.onButtonPressed(Button.A, function () {
    radio.sendNumber(1)
})
input.onButtonPressed(Button.B, function () {
    radio.sendNumber(2)
})
input.onButtonPressed(Button.AB, function () {
    radio.sendNumber(0)
})
radio.onReceivedNumber(function (receivedNumber) {
    if (receivedNumber == 1) {
        robot.motorTank(50, 50)
    } else if (receivedNumber == 2) {
        robot.motorTank(50, -50, 400)
        robot.motorStop()
    } else {
        robot.motorStop()
    }
})
robot.elecfreaksCuteBot.start()
radio.setGroup(1)
You press A on the first micro:bit. Which robot drives forward?

RunRun it and compare the result with your prediction.

Run

Press A, B and A+B on the first micro:bit, and watch the second robot. Then try the buttons on the second micro:bit.

The program as blocks
Show as code
remote.ts
input.onButtonPressed(Button.A, function () {
    radio.sendNumber(1)
})
input.onButtonPressed(Button.B, function () {
    radio.sendNumber(2)
})
input.onButtonPressed(Button.AB, function () {
    radio.sendNumber(0)
})
radio.onReceivedNumber(function (receivedNumber) {
    if (receivedNumber == 1) {
        robot.motorTank(50, 50)
    } else if (receivedNumber == 2) {
        robot.motorTank(50, -50, 400)
        robot.motorStop()
    } else {
        robot.motorStop()
    }
})
robot.elecfreaksCuteBot.start()
radio.setGroup(1)
Try it yourselfYour edits are saved in this browser.
It opens full screen, so the robot simulator has room, and takes a few seconds to load. Esc comes back. Your work in this step is kept.

InvestigateTrace how each line of code connects to what you see.

Investigate

The program as blocks
Show as code
remote.ts
input.onButtonPressed(Button.A, function () {
    radio.sendNumber(1)
})
input.onButtonPressed(Button.B, function () {
    radio.sendNumber(2)
})
input.onButtonPressed(Button.AB, function () {
    radio.sendNumber(0)
})
radio.onReceivedNumber(function (receivedNumber) {
    if (receivedNumber == 1) {
        robot.motorTank(50, 50)
    } else if (receivedNumber == 2) {
        robot.motorTank(50, -50, 400)
        robot.motorStop()
    } else {
        robot.motorStop()
    }
})
robot.elecfreaksCuteBot.start()
radio.setGroup(1)

Match each button with its message and the robot's move.

Ben's remote:

The program as blocks
Show as code
input.onButtonPressed(Button.A, function () {
    radio.sendNumber(1)
})
radio.setGroup(1)

Ben's robot:

The program as blocks
Show as code
radio.onReceivedNumber(function (receivedNumber) {
    if (receivedNumber == 1) {
        robot.motorTank(50, 50)
    }
})
robot.elecfreaksCuteBot.start()
radio.setGroup(2)

Match each button with the number it sends and what the robot does.

A sends 1
B sends 2
A+B sends 0

Ben has two programs: one for his remote, one for his robot. Pressing A does nothing. Why?

ModifyChange the code on purpose and check the result.

Modify

A driver needs to know what the robot heard. Make the robot's micro:bit show each number it receives.

Need a hint?

show number is in Basic. Put it at the top of on radio received, and drag receivedNumber into it.

Add a fourth command: shaking the remote sends 3, and the robot backs up for one second.

Need a hint?

on shake sends 3. In on radio received, add an else if: receivedNumber = 3.

Another hint

Inside it: robot motor tank −50 −50 for 1000 ms, then robot motor stop.

Try it yourselfYour edits are saved in this browser.
It opens full screen, so the robot simulator has room, and takes a few seconds to load. Esc comes back. Your work in this step is kept.

The robot's micro:bit shows each number it receives.

This ticks by itself when your blocks do what is asked.

Add a reverse command: shaking the remote sends 3, and the robot backs up for 1 second.

This ticks by itself when your blocks do what is asked.

MakeBuild something new using what you have learned. Expect a few tries; that is normal.

Make

Make a remote for a rescue robot that moves in small, careful steps:

Use the first micro:bit to steer the second robot round a box and back.

Try it yourselfYour edits are saved in this browser.
It opens full screen, so the robot simulator has room, and takes a few seconds to load. Esc comes back. Your work in this step is kept.
Need a hint?

Four buttons: A, B, A+B and the logo. Each sends a different number.

Another hint

In on radio received, one branch per number: small left turn, small right turn, forward for 1 second, stop.

A rescue-robot remote: left, right, forward and stop, each a different number.

This ticks by itself when your blocks do what is asked.

Info

On a real robot

With real micro:bits, download the program to the remote and to the micro:bit in the robot. Things to notice:

For teachers

Students turn a micro:bit into a radio remote control; each button sends a number and the robot turns each number into a move. About 45 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

Before class

Students used radio in micro:bit Foundations (Send and receive, Messages with meaning). Here the remote sends a number for each command and the robot decides what each number means, in on radio received. The two sides must agree on the group and on the code (1 = forward, 2 = turn, 0 = stop). A micro:bit never hears its own messages.

When a program uses radio, the simulator runs it on two micro:bits, each with a robot, in one arena. Each is the remote for the other robot. This is a little odd at first; say it up front. With real hardware, the same program can go on both micro:bits.

Untested on real hardware: whether the robot start block shows an error on a micro:bit that is not in a robot. If it does, give the remote a copy without that block. Real classrooms need a different radio group for every pair. MOVE Motor classes can use this lesson unchanged on the remote side, and Kitronik blocks on the robot side.

Running the lesson

  1. Predict: many say the first robot. Ask: does a micro:bit hear its own radio? (Foundations: no.)
  2. Run: watch the other robot. Then swap: the second micro:bit drives the first robot.
  3. Investigate: write the code table on the board (1 forward, 2 turn, 0 stop). Ben's robot is the group mismatch from Foundations.
  4. Modify: show number on the robot side is how real operators check what was heard.
  5. Make: four commands, small steps. Challenge pairs to steer round a box and back.
  6. Real robot (optional): assign each pair a radio group before anyone downloads.

The hard part (on purpose)

Both sides must agree on the code and the radio group. Ask which robot they're watching and what number was sent last.

When students get stuck

Stretch and support

Stretch: Steer by tilting: in forever on the remote, send 1 when tilted left (acceleration x < −300), 2 when tilted right, and 0 when level.

Support: Give the robot side complete; students build the remote buttons to match the code table.

Where it leads

Next: one micro:bit cues several robots to dance in time to music. Real-world links: rescue and bomb-disposal robots, drones, robots on Mars (where each message takes minutes to arrive, so the robot must also decide things for itself).

What each step is for

Now you can
Next lesson8. Conductor and dancersOne micro:bit plays a tune and sends a cue as each phrase starts; robots dance the move for each cue, in time.