To complete this tutorial you will need another Micro:Bit. In this tutorial we will program another Micro:Bit to control Bit:bot using the radio service.
To start we will write the program for the remote controller. The controller will communicate with the robot using the radio service. This utilises the Bluetooth transceiver on the Micro:Bit however it does not use the Bluetooth protocol instead it uses a Nordic propriety protocol.
The controller will send characters to the robot. The controls are as follows;
- When Button A is pressed, the letter L will be sent to the robot indicating that the robot should turn left.
- When Button B is pressed, the letter R will be sent to the robot indicating that the robot should turn right.
- When Button A and button B is pressed, the letter F will be sent to the robot indicating that the robot should go forwards.
- When no buttons are pressed, the letter S will be sent indicating that the robot should stop.
I have used a sleep command at the end of the code, this is needed if this is taken out the receiver will receive corrupt data and an error will be displayed. When editing the code keep the delay in or you will have issues.
Next we will change the program loop to interpret the commands. The code for the robot can be seen below;
Now upload the Remote code to one Micro:Bit and upload the Robot code to the Micro:Bit that is plugged into Bit:Bot. If you don’t have a battery pack for you remote Micro:Bit you can plug it into you computer via the USB port to power it. Have a play and see how the code works the change the code and add more features. Perhaps you could use the accelerometer or compass to add features.
Click the following link to download the code file; RCAUTO