# Micro:bit Radio Control of Crickit Robotics

## Overview

https://youtu.be/6VlGi2315kg

The BBC micro:bit continues to gain market share in the educational space. And why not, with an LED matrix display and a built-in Bluetooth LE radio, users can do some advanced projects.

In this guide, one micro:bit will be used as a radio control. Pushing the A and B buttons will transmit commands. A second micro:bit will be connected to an Adafruit Crickit robotics controller. The receiving micro:bit will translate the received radio commands into actions on the Crickit.

## Parts
The Go bundle includes a battery pack, batteries, and a USB cable for a tiny bit more than the micro:bit alone. This is good for the transmitter.

The receiver is not battery powered, so the regular micro:bit pack is fine.

Adafruit Crickit for micro:bit provides robotics, sound, and light support.

### Adafruit CRICKIT for micro:bit

[Adafruit CRICKIT for micro:bit](https://www.adafruit.com/product/3928)
Sometimes we wonder if robotics engineers ever watch movies. If they did, they'd know that making robots into servants always ends up in a robot rebellion. Why even go down that path? Here at Adafruit, we believe in making robots our&nbsp; **friends!**

So if you find...

In Stock
[Buy Now](https://www.adafruit.com/product/3928)
[Related Guides to the Product](https://learn.adafruit.com/products/3928/guides)
![Angled shot of a Adafruit CRICKIT for micro:bit connected to a black squared board.](https://cdn-shop.adafruit.com/640x480/3928-01.jpg)

We'll need a power supply for the Crickit and some interface items. You can choose, but for this tutorial we'll use a servo and an LED NeoPixel strip.

### Part: 5V 2A (2000mA) switching power 
quantity: 1
Barrel connection which matches Crickit
[5V 2A (2000mA) switching power ](https://www.adafruit.com/product/276)

### Part: Micro servo
quantity: 1
A micro servo to move with Crickit
[Micro servo](https://www.adafruit.com/product/169)

### Part: NeoPixel Strip 30 LEDs
quantity: 1
This version has wires that will connect to the Crickit
[NeoPixel Strip 30 LEDs](https://www.adafruit.com/product/2562)

### Part: USB cable - USB A to Micro-B - 3 foot long, data + power
quantity: 1
Connect your micro:bit to your computer, a longer cable if needed.
[USB cable - USB A to Micro-B - 3 foot long, data + power](https://www.adafruit.com/product/592)

## Tools

You can use your own wire stripper, but if you don't have one, this one is great.

### Part: Hakko Professional Quality 20-30 AWG Wire Strippers
quantity: 1
Cuts like butter
[Hakko Professional Quality 20-30 AWG Wire Strippers](https://www.adafruit.com/product/527)

# Micro:bit Radio Control of Crickit Robotics

## Transmitter Code

For this tutorial, we'll use Microsoft MakeCode for micro:bit. MakeCode allows for some very interactive projects with just a few connected code blocks.

Go to [makecode.microbit.org](https://makecode.microbit.org/) to get started. If you'd like to start learning Makecode, check the first project under **Tutorials**.

For this project, we'll use two pieces of code: one for the transmitting (remote controller) micro:bit. And another MakeCode program for the receiving micro:bit which will include blocks for using Crickit.

## Transmitter MakeCode
![](https://cdn-learn.adafruit.com/assets/assets/000/071/940/medium800/microcontrollers_transmit.jpg?1551199446)

[Open this code in MakeCode for micro:bit](https://makecode.microbit.org/_aoYbrq59oCuh)
The radio controls are in the **Radio** block group (pink). On the start of the program, we set the `radio group` to `1`. If multiple micro:bits are in a room, you can keep them from interfering by setting unique radio groups. We do need to keep this number the same as our receiver micro:bit on the next page.

The rest of the code is in two Input blocks: `on button A pressed` and `on button B pressed`. When button A is pressed, the code within the `on button A pressed` block is run, the same for B.

The actions for both are very similar: Display the letter of the button pushed with `show string`, send a unique command (0 for A, 1 for B) via `radio send number`, `pause` a bit so you can see the letter on the display and clear the display by `show string` with a blank character.

If you want to send more commands, I would suggest grabbing the `on shake` block. This allows you to control things via 11 different gestures (click `shake` and the editor will show you the range of options). The `on button` block also accepts on button `A+B`.

## Load the Code

In this area of the editor, select a unique name for your code, I used **transmitter**.

![](https://cdn-learn.adafruit.com/assets/assets/000/071/945/medium800/microcontrollers_save.png?1551200377)

If you click the download button it is similar, the editor will ask you to save the file on your computer storage.

![](https://cdn-learn.adafruit.com/assets/assets/000/071/946/medium800/microcontrollers_download.png?1551200451)

The instructions that pop up are what we follow to download the code.

![](https://cdn-learn.adafruit.com/assets/assets/000/071/947/medium800/microcontrollers_instructions.jpg?1551200514)

Be sure the micro:bit you want to program is plugged in via a good USB data+power cable. The editor saves the code in a file named **microbit-_projectname_.hex**. Our project name is **Transmitter**. Go to your file explorer / finder on your computer. With the micro:bit plugged in via USB, you should see a new flash drive pop up named **MICROBIT**.

![](https://cdn-learn.adafruit.com/assets/assets/000/071/948/medium800/microcontrollers_microbit.png?1551200781)

Navigate to the directory where you saved your **.hex** file. Using the mouse, drag the **.hex** file over to the **MICROBIT** drive. The micro:bit should program itself and start running your code. Press the A and B buttons and you should see the letter **A** or **B** on the LED matrix.

![](https://cdn-learn.adafruit.com/assets/assets/000/071/969/medium800/microcontrollers_drag.png?1551205411)

# Micro:bit Radio Control of Crickit Robotics

## Receiver Code

The receiver code contains a few more blocks than the transmitter. We'll go over things to see why.

![](https://cdn-learn.adafruit.com/assets/assets/000/071/970/medium800/microcontrollers_receive.jpg?1551205517)

[Open the Receiver code in MakeCode for micro:bit](https://makecode.microbit.org/_TCeEC7XJKhM3)
## Download

Download the Receiver code into the second micro:bit per the same method used on the previous page to load the transmitter code.

Click Edit in the upper right corner of the code display to get into the MakeCode editor. You can then save the program. Save it as **Receiver**.

## What the Program is Doing

This code has two new sets of blocks:

- `strip` blocks work with NeoPixel LED strips via the NeoPixel Extension
- `crickit` blocks work with the Adafruit Crickit robotics board via the Crickit Extension

If you load the code via the green button above, MakeCode will load those extensions for you. They provide two new block groups, **Crickit** and **NeoPixel** , which provide robotics and light blocks respectively.

In `on start`, the code sets things up. It sets the `radio group` just like the transmit code. It also sets up a NeoPixel strip with 30 LEDs. Pin P16 is the pin which does NeoPixels for micro:bit on Crickit. We set the whole strip to black which turns all the LEDs off. Then we set two variables, `position` and `light`, for later use.

The other two loops work with each other to process your radio code:

- the `forever` loop acts on the values of `position` and `light` to move a servo or toggle the NeoPixels.
- the `on radio received` loop toggles the variables `position` and `light` if the right radio message is received.

The `on radio received` loop looks for the button press messages 0 and 1 placed in the value `receivedNumber` by MakeCode. If it receives them, the loop will toggle the value of `position` (for button A presses) and `light` (for button B presses). If one of those variables is `1`, it will set it to `0` and if the value is `0` it will set it to `1`.

The `forever` loop does the work for us. It acts on the values of `position` and `light`. If `position` is 0, the angle of the servo is set to zero else it is set to 100 degrees. If `light` is set to 1 the NeoPixel strip is set to a rainbow pattern, otherwise it is turned off.

If you want to add actions, you can have the `on radio received` block look for other radio commands and set a variable. Then add an action in `forever` that acts on the variable.

Next to construct our circuit.

# Micro:bit Radio Control of Crickit Robotics

## Wire It Up

![](https://cdn-learn.adafruit.com/assets/assets/000/071/978/medium800/microcontrollers_microbit_crickit_bb2.png?1551207842)

Plug your servo motor into the Crickit&nbsp; **Servo** block on position 1, such that the lightest color (yellow most likely) faces away from the Crickit and the darkest color (brown or black) wire is closest to the center of the Crickit board.

Wire your NeoPixel strip to the NeoPixel block on Crickit with the black ground wire to GND, the red power wire to 5V and the white signal wire from the Crickit arrow terminal in the middle to the strip Din (Data In) pin. You'll need to strip the ends of the wires if they are not already exposed. Open each terminal block slot using a small screwdriver (the screw does not come out), insert the wire, and then tighten for a snug fit.

Plug the micro:bit you programmed as receiver into the Crickit. Note the text on the Crickit circled in blue - the micro:bit LED matrix should face that text when plugged in. Unfortunately the micro:bit can be plugged in the wrong way. Check twice the LEDs face the way the text indicates.

Put the AAA batteries in the battery pack and plug the battery pack into the transmitter micro:bit. You can press buttons A and B to ensure it is working as the display will light up A or B when the buttons are pressed. If it does not work, be sure the programming was done using the Transmitter Code page.

Plug the wall power transformer into the wall and into the Crickit black power jack. Be sure the on/off switch, circled in yellow, is set to on. A small green LED near the servo connections will light up if the board is happy. The servo may twitch, that is good.

Now we're ready to try it out.

## Troubleshooting

If your servos don't work, try testing your Crickit and servo with the simple programs in the guide [Make it Move with Crickit](https://learn.adafruit.com/make-it-move-with-crickit/use-a-standard-servo-now). If they work there, then there is an issue elsewhere in your build.

If the simple case fails to have your servo work, check:

1. Wiring: to be sure you have the connections right. Non-Adafruit servos may have different connectors and wire colors.
2. Power: motors are power hungry. Be sure the Crickit is connected to a power source that can supply the voltage and current the servo(s) need. Also if you have multiple motors or other power hungry items like NeoPixels, size your power supply appropriately. See [this guide](https://learn.adafruit.com/sipping-power-with-neopixels) for NeoPixel power tips.
3. USB: If you have Crickit connected to USB, ensure it's via a known good USB cable which has both power and data lines. Power only USB cables should be avoided.

# Micro:bit Radio Control of Crickit Robotics

## Use

![](https://cdn-learn.adafruit.com/assets/assets/000/072/002/medium800/microcontrollers_use2.png?1551217781)

If all is well, you can use your transmitter micro:bit (with battery pack) and you can press the A and B buttons and have A and B appear on the screen.

What is happening at the receiver end?

When the micro:bit + Crickit get the button A press, it moves the servo motor. One press moves it to 100 degrees, another press moves it back to zero.

For button B, one press lights the NeoPixel LED strip to a rainbow of colors, a second press turns it off.

Congratulations, you're using radio control!

## Next Steps

Now that you have solid examples of a transmitter and receiver, what would you like to build? A radio-controlled robot? Mood lights for your room?&nbsp;

You can review the numerous examples of [Crickit projects in the Adafruit Learning System](https://learn.adafruit.com/search?q=crickit) to get ideas for Crickit-based projects. Don't worry if they use CircuitPython, you can come back to MakeCode and look to implement your own version. Have fun!


## Featured Products

### BBC micro:bit Go Bundle

[BBC micro:bit Go Bundle](https://www.adafruit.com/product/3362)
Discontinued - [**you can grab** micro:bit v2 Go Bundle - Batteries and USB Cable Included **instead!&nbsp;**](https://www.adafruit.com/product/4834)

The British Invasion is here! No, not music...microcontrollers! New to the USA is the newest and _easiest_ way to...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/3362)
[Related Guides to the Product](https://learn.adafruit.com/products/3362/guides)
### BBC micro:bit

[BBC micro:bit](https://www.adafruit.com/product/3530)
The British Invasion is here! No, not music...microcontrollers! New to the USA is the newest and _easiest_ way to learn programming and electronics - the **BBC micro:bit**.

Designed specifically for kids and beginners, the&nbsp; **micro:bit** &nbsp;is a...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/3530)
[Related Guides to the Product](https://learn.adafruit.com/products/3530/guides)
### Adafruit CRICKIT for micro:bit

[Adafruit CRICKIT for micro:bit](https://www.adafruit.com/product/3928)
Sometimes we wonder if robotics engineers ever watch movies. If they did, they'd know that making robots into servants always ends up in a robot rebellion. Why even go down that path? Here at Adafruit, we believe in making robots our&nbsp; **friends!**

So if you find...

In Stock
[Buy Now](https://www.adafruit.com/product/3928)
[Related Guides to the Product](https://learn.adafruit.com/products/3928/guides)
### 5V 2A (2000mA) switching power supply - UL Listed

[5V 2A (2000mA) switching power supply - UL Listed](https://www.adafruit.com/product/276)
This is an FCC/CE certified and UL listed power supply. Need a lot of 5V power? This switching supply gives a clean regulated 5V output at up to 2000mA. 110 or 240 input, so it works in any country. The plugs are "US 2-prong" style so you may need a plug adapter, but you can pick one...

In Stock
[Buy Now](https://www.adafruit.com/product/276)
[Related Guides to the Product](https://learn.adafruit.com/products/276/guides)
### Micro servo

[Micro servo](https://www.adafruit.com/product/169)
Tiny little servo can rotate approximately 180 degrees (90 in each direction) and works just like the standard kinds you're used to but _smaller_. You can use any servo code, hardware, or library to control these servos. Good for beginners who want to make stuff move without...

In Stock
[Buy Now](https://www.adafruit.com/product/169)
[Related Guides to the Product](https://learn.adafruit.com/products/169/guides)
### Adafruit NeoPixel LED Strip Starter Pack - 30 LED meter - Black

[Adafruit NeoPixel LED Strip Starter Pack - 30 LED meter - Black](https://www.adafruit.com/product/2562)
You can't bake a cake without flour, sugar, and baking soda? Cream cheese? Muscadet?&nbsp;Ok - to be honest we don't do much cake baking. &nbsp;But we do light up a TON of NeoPixel LED strips! They're&nbsp;everywhere - from our <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/2562)
[Related Guides to the Product](https://learn.adafruit.com/products/2562/guides)
### USB cable - USB A to Micro-B

[USB cable - USB A to Micro-B](https://www.adafruit.com/product/592)
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Metro, Feather, Raspberry Pi or other dev-board or microcontroller

Approximately 3 feet / 1 meter long

In Stock
[Buy Now](https://www.adafruit.com/product/592)
[Related Guides to the Product](https://learn.adafruit.com/products/592/guides)

## Related Guides

- [Make it Move with Crickit](https://learn.adafruit.com/make-it-move-with-crickit.md)
- [micro:bit Crickit Robot](https://learn.adafruit.com/microbit-crickit-robot.md)
- [Using micro:bit and CRICKIT with MicroPython](https://learn.adafruit.com/using-micro-bit-and-crickit-with-micropython.md)
- [CRICKIT WobblyBot](https://learn.adafruit.com/crickit-wobblybot.md)
- [Robotic Creatures ](https://learn.adafruit.com/robotic-creatures.md)
- [Rack and Pinion Bot](https://learn.adafruit.com/rack-and-pinion-bot.md)
- [Multi-tasking the Arduino - Part 3](https://learn.adafruit.com/multi-tasking-the-arduino-part-3.md)
- [Madison's NeoClock - A PIC + KiCAD + NeoPixel adventure](https://learn.adafruit.com/madisons-neoclock-a-pic-kicad-neopixel-adventure.md)
- [Native MP3 decoding on Arduino](https://learn.adafruit.com/native-mp3-decoding-on-arduino.md)
- [Make It Bubble](https://learn.adafruit.com/make-it-bubble.md)
- [Quickstart: Adafruit IO WipperSnapper ](https://learn.adafruit.com/quickstart-adafruit-io-wippersnapper.md)
- [Using Circuit Playground Express, MakeCode and CircuitPython on a Chromebook](https://learn.adafruit.com/using-circuit-playground-express-makecode-circuitpython-on-a-chromebook.md)
- [Trellis Feather DSP-G1 Synthesizer](https://learn.adafruit.com/feather-trellis-dsp-g1-synthesizer.md)
- [Make It Switch](https://learn.adafruit.com/make-it-switch.md)
- [Soil Moisture Sensor with Circuit Playground Express and MakeCode](https://learn.adafruit.com/soil-moisture-sensor-with-circuit-playground-express.md)
