Wireless Remote Control with micro:bit

Pages
Contributors: bboyho
Favorited Favorite 4

Introduction

In this tutorial, we will utilize MakeCode's radio blocks to have one micro:bit transmit a signal to a receiving micro:bit on the same channel. Eventually, we will control a micro:bot wirelessly using parts from the micro:arcade kit!

Wireless Remote Control with micro:bit

Required Materials

To follow along with this tutorial, you will need the following materials at a minimum. You may not need everything though depending on what you have. Add it to your cart, read through the guide, and adjust the cart as necessary.

You Will Also Need

The following materials are optional to make a battle bot.

  • Scissors
  • Electrical Tape or Glue
  • Ping Pong Ball
  • Skewers

Suggested Reading

If you aren’t familiar with the following concepts, we recommend checking out these tutorials before continuing.

Getting Started with the micro:bit

The BBC micro:bit is a compact, powerful programming tool that requires no software installation. Read on to learn how to use it YOUR way!

micro:bot Kit Experiment Guide

Get started with the moto:bit, a carrier board for the micro:bit that allows you to control motors, and create your own robot using this experiment guide for the micro:bot kit.

micro:arcade Kit Experiment Guide

We love games! We love writing games, building games and yes, even building game consoles. So we want to introduce to you the micro:arcade kit for the micro:bit!

Installing the Extensions for Microsoft MakeCode

To make the most out of the carrier boards with the least amount of coding, use the Microsoft MakeCode extensions written for the gamer:bit and moto:bit boards. If you have not already, check out the instructions for installing the extensions for both boards as explained in their respective guides whenever you make a new MakeCode project utilizing the boards.

SparkFun Extensions

gamer:bit Extension

To install the extension for the controller:bit (formerly known as the gamer:bit, head over to our micro:arcade kit experiment guide to follow the instructions.

moto:bit Extension

To install the extension for the moto:bit, head over to our micro:bot kit experiment guide to follow the instructions.

Experiment 1: Sending and Receiving a Signal

Introduction

There are a few methods of transmitting data between two or more micro:bits. You can send a number, or a string. For simplicity, we will send one number between two micro:bits.

Parts Needed

You will need the following parts:

  • 2x micro:bit Boards
  • 2x Micro-B USB Cables

For a few items listed, you will need more than one unit (i.e. micro:bits, micro-B USB cables, etc.). You may not need everything though depending on what you have. Add it to your cart, read through the guide, and adjust the cart as necessary.

USB Micro-B Cable - 6"

USB Micro-B Cable - 6"

CAB-13244
$2.10
3

micro:bit Board

DEV-14208
10 Retired

1.1: Sending

For this part of the experiment, we are going to send a number from one micro:bit to another micro:bit on the same channel.

Hardware Hookup

Connect the first micro:bit to your computer via USB cable.

micro-B USB Cable Inserted into Micro:bit

Running Your Script

We are going to use Microsoft MakeCode to program the micro:bit. You can download the following example script and move the *.hex file to your micro:bit. Or use it as an example to build it from scratch in MakeCode.


Note: You may need to disable your ad/pop blocker to interact with the MakeCode programming environment and simulated circuit!

Code to Note

When the micro:bit is powered up, we'll want it set up the radio to a certain channel. In this case, we head to the Radio blocks, grab the radio set group __ block, and set it to 1. We will use the built-in button A on the micro:bit. From the Input blocks, we use the on button A pressed, Once the button is pressed, we will transmit a number 0 wirelessly. For feedback, we will use the Basic blocks to have the LEDs animate with a dot expanding out into a square to represent a signal being sent out. Once the animation is finished, we will clear the screen.

MakeCode Sending Number Example

Having a hard time seeing the code? Click the image for a closer look.


1.2: Receiving

For this part of the experiment, we are going to have a second micro:bit receive a number from the first micro:bit.

Hardware Hookup

To avoid confusion when uploading code, unplug the first micro:bit from your computer. Then connect the second micro:bit to your computer via USB cable.

Insert Second micro:bit

Running Your Script

Download the following example script and move the *.hex file to your micro:bit. Or use it as an example to build it from scratch in MakeCode. You will need to open a new project to receive the data from the first part of this experiment.


Note: You may need to disable your ad/pop blocker to interact with the MakeCode programming environment and simulated circuit!

Code to Note

When the second micro:bit is powered up, we'll want to set the radio to the same channel as the first micro:bit. In this case, it will be 1. Using the on radio received __________ block, we will want to check to see what signal was received. In this case, we will want to check for a receivedNumber that is equal to 0 since a number was sent from the first micro:bit. Using the if statement from the Logic blocks, we will want to check if the variable holding the received number matches 0. If it matches, we will want the micro:bit to do something. Visually, using LEDs would be the easiest so an animation of a square shrinking to a dot was chosen to represent the received signal. Once the animation is finished, we will want to clear the screen until we receive another signal.

MakeCode Receiving Number Example

Having a hard time seeing the code? Click the image for a closer look.


What You Should See

Pressing on button A with the first micro:bit (our transmitting) will send a number out in channel 1. In this case, the number that is transmitted is 0.

The second micro:bit (our receiving) will take that number that was sent on channel 1 and do something based on the condition statement. In this case, there is an animation using the LED array to indicate when we have received the number.

Demo of micro:bit transmitting to another microbit


Experiment 2: Wirelessly Driving Forward

Introduction

Remember our micro:bot? The micro:bot was running around loose by itself the last time we were working with the robot. Let's give it some commands so that it only moves when you want it to using the controller:bit carrier board!

Parts Needed

You will need the following parts:

  • 2x micro:bit Boards
  • 2x Micro-B USB Cables
  • 1x Assembled micro:bot Kit
  • 1x controller:bit Carrier Board
  • 4x AA Batteries
  • 2x AAA Batteries (if you are using the battery pack with switch for the controller)

For a few items listed, you will need more than one unit (i.e. micro:bits, AA batteries, etc.). You may not need everything though depending on what you have. Add it to your cart, read through the guide, and adjust the cart as necessary.

SparkFun micro:bot kit for micro:bit - v2.0

SparkFun micro:bot kit for micro:bit - v2.0

KIT-16275
$74.95 $63.71
1
USB Micro-B Cable - 6"

USB Micro-B Cable - 6"

CAB-13244
$2.10
3

SparkFun micro:arcade kit for micro:bit v2.0

KIT-16403
Panasonic Alkaline Battery - AA

Panasonic Alkaline Battery - AA

PRT-15201
$0.55

750 mAh Alkaline Battery - AAA

PRT-09274
Retired

micro:bit Board

DEV-14208
10 Retired

2.1 Remote Control

For this part of the experiment, we will use the same method as experiment 1 to transmit a command. As soon as a certain combination of buttons are pressed on the controller:bit, the attached micro:bit will transmit one command to a receiving micro:bit. For debugging purposes, we are going to have a short animation when the buttons are pressed for feedback.

Hardware Hookup

If you have not already, insert one micro:bit into the controller:bit's carrier board. Make sure to insert the micro:bit with the LED array facing up (the same direction as all of the buttons) as explained in the micro:arcade kit experiment guide. We’re continuing on from experiment 3. Make sure to check out the guide before continuing on.

micro:arcade Kit Experiment Guide

July 21, 2017

We love games! We love writing games, building games and yes, even building game consoles. So we want to introduce to you the micro:arcade kit for the micro:bit!

Then connect the micro:bit to your computer via USB cable.

controller:bit micro:bit and USB Cable

Running Your Script

Download the following example script and move the *.hex file to your micro:bit. Or use it as an example to build it from scratch in MakeCode. Remember, if you are building from scratch, you will need to install the appropriate extension when using the controller:bit.


Note: You may need to disable your ad/pop blocker to interact with the MakeCode programming environment and simulated circuit!

Code to Note

When the micro:bit is powered up, we'll want it set up the radio to a certain channel. In this case, we set the radio block to 1 just like experiment 1. Then we'll want to check if the P16 button is pressed on the controller:bit, just like an accelerate button used in driving games. For simplicity, we will want the robot to move forward when pressing the up (P0) button on the direction pad. We will be using a nested if statement to check on the buttons defined in the gamer:bit extension. A nested if statement is one or more if statements "nested" inside of another if statement. If the parent if statement is true, then the code looks at each of the nested if statements and executes any that are true. If the parent if statement is false, then none of the nested statements will execute. By using the logic statement, we will be using the gamer:bit ____ is pressed block.

Once both buttons are pressed, we will send a command out. In this case, it will be number 0. For feedback, to see if our code works as expected, we will have the LEDs animate with an arrow pointing up and a square growing bigger. We then give the micro:bit a short pause before clearing the screen and looping back to the beginning of the forever loop.

MakeCode Remote Control Example

Having a hard time seeing the code? Click the image for a closer look.


2.2 Robot Receive

In this part of the experiment, we need to have a receiving micro:bit recognize the command that was sent from the first micro:bit in order to control the micro:bot. For simplicity, we will have the robot drive forward. To debug, the LED array will display an arrow to indicate the direction where the robot should move for feedback.

Hardware Hookup

At this point, you should have your micro:bot kit assembled! We're continuing on from experiment 5. Make sure to check out the guide before continuing on.

micro:bot Kit Experiment Guide

February 20, 2020

Get started with the moto:bit, a carrier board for the micro:bit that allows you to control motors, and create your own robot using this experiment guide for the micro:bot kit.

To avoid confusion when uploading code, unplug the first micro:bit from your computer. Connect the second micro:bit to your computer via USB cable.

Micro:bot Moto:bit Micro:Bit USB Cable

Running Your Script

Download the following example script and move the *.hex file to your micro:bit. You can also use it as an example to build it from scratch in MakeCode. Remember, if you are building from scratch, you will need to install the appropriate extension when using the moto:bit.


Note: You may need to disable your ad/pop blocker to interact with the MakeCode programming environment and simulated circuit!

Code to Note

When the second micro:bit is powered up, we'll want to set the radio to the same channel as the first micro:bit; again to 1. As explained in the micro:bot experiment guide, we will want to set the left and right motors' logic based on the way we connected the motors to the motor:bit. For consistency, we will make both true. Using the on radio received __________ block from the moto:bit extension, we will want to check to see what command was received. In this case, it should be a 0 that was sent from the first micro:bit. If the command that was sent matches 0, we will want the moto:bit to drive forward at 100%. For feedback, we will have an arrow point up. After a short pause of about 50ms, we will want to clear the screen and turn the motors off before checking again. If the pause is too long, the micro:bot will continue to drive forward even after you remove your fingers from the controller:bit's buttons.

MakeCode Receiving micro:bot Code

Having a hard time seeing the code? Click the image for a closer look.


What You Should See

Now that both micro:bits are programmed, let's the test code out. Disconnect the USB cables from both micro:bits and power each with the respective battery packs.

Inserting JST Connector into micro:bit 2xAA Battery Pack INserted into JST Connector of micro:bit

For the micro:bot, insert the 4xAA battery pack into the barrel jack.

Barrel Jack Being Inserted into moto:bit 4xAA Battery Pack Inserted into Barrel Jack of moto:bit

Then move the switch labeled as RUN MOTORS to the ON position. Pressing on the drive button (P16) and up button (P0) on the controller:bit will cause the micro:bot to drive forward. You should also see the LED array animate.

Demo Test Wireless Control micro:bot with controller:bit


Experiment 3: Wirelessly Controlling the micro:bot

Introduction

Now that we are able to wirelessly move our robot forward, we will want additional commands for turning and driving in reverse. While we are at it, we are going to give a special function to control the servos attached to our battle bot.

Parts Needed

You will need the following parts:

  • 2x micro:bit Boards
  • 2x Micro-B USB Cables
  • 1x Assembled micro:bot Kit
  • 1x controller:bit Carrier Board
  • 4x AA Batteries
  • 2x AAA Batteries (if you are using the battery pack with switch for the controller)

For a few items listed, you will need more than one unit (i.e. micro:bits, AA batteries, etc.). You may not need everything though depending on what you have. Add it to your cart, read through the guide, and adjust the cart as necessary.

SparkFun micro:bot kit for micro:bit - v2.0

SparkFun micro:bot kit for micro:bit - v2.0

KIT-16275
$74.95 $63.71
1
USB Micro-B Cable - 6"

USB Micro-B Cable - 6"

CAB-13244
$2.10
3

SparkFun micro:arcade kit for micro:bit v2.0

KIT-16403
Panasonic Alkaline Battery - AA

Panasonic Alkaline Battery - AA

PRT-15201
$0.55

750 mAh Alkaline Battery - AAA

PRT-09274
Retired

micro:bit Board

DEV-14208
10 Retired

3.1 Full Remote Control

For this part of the experiment, we will repeat the steps in 2.1 to transmit commands for turning or driving in reverse. The built-in accelerometer will be used to detect a shake. A command to control the servo motors will be sent out as soon as there is a shake detected.

Hardware Hookup

If you have not already, insert one micro:bit into the controller:bit's carrier board. Make sure to insert the micro:bit with the LED array facing up (the same direction as all of the buttons) as explained in the micro:arcade kit experiment guide. We’re continuing on from experiment 3. Make sure to check out the guide before continuing on.

micro:arcade Kit Experiment Guide

July 21, 2017

We love games! We love writing games, building games and yes, even building game consoles. So we want to introduce to you the micro:arcade kit for the micro:bit!

Disconnect the battery pack from micro:bit from the previous experiment. The JST connector is a tight fit in the micro:bit so you will need to carefully remove the connector out by wiggling it side to side using your index finger and thumb. It is easier to remove the micro:bit from the controller:bit carrier board.

JST Connector Removed

Then connect the first micro:bit to your computer via USB cable.

controller:bit micro:bit and USB Cable

Running Your Script

Download the following example script and move the *.hex file to your micro:bit. Or use it as an example to build it from scratch in MakeCode. You will need to open a new project to receive the data from the first part of this experiment. Remember, if you are building from scratch, you will need to install the appropriate extension when using the controller:bit.


Note: You may need to disable your ad/pop blocker to interact with the MakeCode programming environment and simulated circuit!

Code to Note

Using the same template for driving forward, we assign a unique number to the right (P2), down (P8), and left (P1) buttons on the direction pad. For simplicity, we will just want the robot to move forward when turning right or left. There is not as much animation with the LED array in this example since it can slow down your micro:bit. Using the Input's on shake block from the Input, a unique number is sent out to control the servos. Again, an arrow will display briefly for feedback in each case.

MakeCode Remote Control

Having a hard time seeing the code? Click the image for a closer look.


3.2 Full Battle Bot Control

For this part of the experiment, we will repeat the steps in 2.2 to receive the commands before moving the robot. Instead of just driving forward, the robot can now turn, reverse, and control the servo motors.

Hardware Hookup

We'll be using the same servo connection on the battle bot as explained in experiment 5. Make sure to check out the guide before continuing on.

micro:bot Kit Experiment Guide

February 20, 2020

Get started with the moto:bit, a carrier board for the micro:bit that allows you to control motors, and create your own robot using this experiment guide for the micro:bot kit.

Remove the battery pack from the moto:bit carrier board from the previous experiment.

Remove Barrel Jack

To avoid confusion when uploading code, unplug the first micro:bit from your computer. Then connect the second micro:bit to your computer via USB cable.

micro:bit moto:bit micro:bit and USB Cable

Running Your Script

Download the following example script and move the *.hex file to your micro:bit. Or use it as an example and build it from scratch in MakeCode. You will need to open a new project to receive the data from the first part of this experiment. Remember, if you are building from scratch, you will need to install the appropriate extension when using the moto:bit.


Note: You may need to disable your ad/pop blocker to interact with the MakeCode programming environment and simulated circuit!

Code to Note

We set up the second micro:bit to use the same channel and motor logic as explained in experiment 2.2. Four more commands were added to the on radio received __________ to turn right, reverse, turn left, and control the servo motors of our battle bot. When turning, the motor closest to the inside of the turn is set to a lower value. That way the robot will continue to drive forward but also move right or left. To reverse, both motors used the reverse option to drive backwards. Finally, if the robot receives a command indicating that there was a shake from the first micro:bit, the servos will move. If you look closely at the receivedNumber, each of the commands match the same number that was transmitted from the first micro:bit.

MakeCode Receiving micro:bit

Having a hard time seeing the code? Click the image for a closer look.


What You Should See

Now that both micro:bits are programmed with more commands, let's test the code out. Disconnect the USB cable from both micro:bits and power each with the respective battery packs again.

2xAA Battery Pack Inserted into JST Connector of micro:bit 4xAA Battery Pack Inserted into Barrel Jack of moto:bit

Pressing the controller:bit's drive button (P16) and any of the buttons located in the direction pad (P0, P2, P8, P1) will cause the robot to move. Shaking the first micro:bit will make the servos on the micro:bot move.

Full Control of micro:bot

Powering Down Your Controller and Robot

When finished, make sure to power down your controller and micro:bot by disconnecting the JST connector and barrel jack on the battery packs. This will save you some power in the long run for more fun! Again, the JST connector is a tight fit in the micro:bit so you will need to carefully remove the connector out by wiggling it side to side using your index finger and thumb.

Disconnecting JST Connector into micro:bit Disconnecting Barrel Jack from moto:bit

Coding Challenges

Transmitting Other Things

Instead of sending a number, try adjusting the code to transmit a value or string between the two micro:bits.

2-Way Communication

Try adjusting experiment 1's code to have the second micro:bit send a signal back to the first micro:bit.

Broadcasting

Have more than two micro:bits? Try modifying code to broadcast a signal from one micro:bit to several micro:bits by having the receiving micro:bits on the same channel! Or try coding with a friend to make two micro:bits fighting for control of a third micro:bit attached to a micro:bot.

Add More Movement!

Ok, so experiment 3 did not have "all" the specified movements. We just gave some basic movements so that the micro:bot can move around the floor. Try adjusting the codes to turn when the micro:bot is moving backwards. Can you adjust the code so that the robot can rotate without driving forward or back? Or maybe program the robot to dance when a certain button(s) are pressed.

Arcade Joystick and Buttons

Go retro and wire the gamer:bit with the joystick and buttons for a different style controller. The joystick and buttons are great for more intense gamers.

Sensor Control

Try flipping the control of the buttons and sensors. Instead of using the buttons to control the robot's motion, try using the accelerometer or magnetometer. Can you control the motor intensity based on the sensor reading? Then, to control the battle bot's servos, try using the buttons.

Monitoring Environment

Try using parts from the micro:climate kit to relay sensor data and monitor an environment at a distance between two micro:bits.

Troubleshooting

Not working as expected? Below are a few troubleshooting tips to get your micro:bits working as expected. For your convenience, relevant troubleshooting tips from the micro:arcade and micro:bot experiment guides were included below.

  • Not Receiving a Signal?

    • Make sure that the micro:bits are on the same channel.
    • Make sure that the number sent is the same.
    • Make sure that your are sending and receiving a number.   

  • The Second Micro:bit is Reacting Without Sending Data from the First Micro:bit.

    • If you have more than one micro:bit transmitting on the same channel, the receiving micro:bit may be reacting to other micro:bits sending on the same channel. Make sure that each micro:bit pair is on their own unique channel. You can also try to adjust the number being transmitted on each micro:bit to react to certain number.   

  • Micro:bit is Not Showing Up.

    • Try unplugging the USB cable and plugging it back in. Also, be sure that you have the cable inserted all the way into your micro:bit.   

  • Gamer:bit or Moto:bit Blocks are Not Visible.

    • Make sure you have a network connection and you have added the extension to your MakeCode environment.
    • Try installing it again from the add extension option in MakeCode.   

  • Robot Not Driving Straight!

    • This may be due to the floor that the micro:bot is driving on. The wheels and motors might have slight differences in the way they were manufactured. Having the robot drive on certain floors like carpet can make the slight differences more apparent. To correct for these differences, you may want to adjust the intensity of each motor moving forward or reverse.    

  • Robot is Not Moving After Sending a Command from the Gamer:bit.

    • Make sure your motors are hooked up correctly in the motor ports and your motor power switch is set to "RUN Motors", the battery pack is plugged in, and you have fresh batteries.
    • Make sure the transmitting and receiving micro:bits are using the correct code.    

  • Moving in Reverse?!

    • There are two options if you notice the micro:bot moving in the wrong direction. As explained above, you can flip the wiring of your motors or use the set ____ motor invert to ____ block in your on start block to change what is forward vs. reverse.   

  • Servo Moves in the Wrong Direction.

    • Flip your servos, or change your code so that it rotates the correct direction.   

  • Servo Doesn't Move at All!

    • Double check your connections of the servos to the moto:bit to make sure that they are hooked up correctly.

Resources and Going Further

Now that you've successfully got your micro:bits communicating, it's time to incorporate it into your own project! Need some inspiration? Check out our other robots found in our robotics section.

Wireless Joystick Hookup Guide

A hookup guide for the SparkFun Wireless Joystick Kit.

Wireless Motor Driver Shield Hookup Guide

Get started with the SparkFun Wireless Motor Driver Shield!

SparkFun Inventor's Kit Experiment Guide - v4.0

The SparkFun Inventor's Kit (SIK) Experiment Guide contains all of the information needed to build all five projects, encompassing 16 circuits, in the latest version of the kit, v4.0a.

SparkFun Auto pHAT Hookup Guide

The pHAT to get your projects moving. This guide will help you get started using the Auto pHAT.

Looking for more wireless fun? Check out the following using wireless applications.

Using the BlueSMiRF

How to get started using the BlueSMiRF and Bluetooth Mate Silvers.

Experiment Guide for the Johnny-Five Inventor's Kit

Use the Tessel 2 and the Johnny Five Inventors kit to explore the world of JavaScript enabled hardware through 14 awesome experiments!

MicroMod WiFi Function Board - ESP32 Hookup Guide

The MicroMod ESP32 Function Board adds additional wireless options to MicroMod Processor Boards that do not have that capability. This special function board acts as a coprocessor that takes advantage of Espressif's ESP32 WROOM to add WiFi and Bluetooth® to your applications.

GNSS Correction Data Receiver (NEO-D9S) Hookup Guide

Add GNSS correction data to your high precision GNSS (HPG) receiver with the u-blox NEO-D9S! This tutorial will get you started with the ZED-F9P, NEO-D9S, and the ESP32 IoT RedBoard.

Or try checking out these cool robots from AVC.