Wireless Remote Control with micro:bit

Pages
Contributors: bboyho
Favorited Favorite 4

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
1
SparkFun micro:arcade kit for micro:bit v2.0

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

KIT-16403
$52.50
USB Micro-B Cable - 6"

USB Micro-B Cable - 6"

CAB-13244
$2.10
3

750 mAh Alkaline Battery - AAA

PRT-09274
Retired
Panasonic Alkaline Battery - AA

Panasonic Alkaline Battery - AA

PRT-15201
$0.55

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