Introduction – In this series of tutorials so far, we’ve looked briefly at the motor:bit STEM Education Robot for the BBC micro:bit including the different capabilities of the motor:bit STEM Education Robot. We explored the capability of the motor:bit main board, learned more about the line sensor module for the motor:bit STEM Education robot, learned about the ultrasonic module for the motor:bit STEM Education robot, connected up all of the different bits that make up the motor:bit STEM Education robot and programmed the motor:bit robot to follow a line. We then moved on and programmed the motor:bit STEM Education robot to detect obstacles and navigate around them and learned howto make use of the radio capability built into the micro:bit to broadcast and receive signals for purposes of creating a smart remote control. In this tutorial we will use the Bluetooth protocol and program the micro:bit so as to control the motor:bit STEM Education robot from an Andriod phone.
This tutorial builds on all of the learning we’ve gained so far. If you’ve skipped the earlier tutorials we would highly recommend you go back, read through and perform each of the tutorials provided. Please note that it’s possible to control the motor:bit STEM education robot over Bluetooth from an IOS phone, however our focus for this tutorial will just be Bluetooth control through Android.
About the motor:bit STEM Education Robot – The Motor:bit STEM education robot is a DIY (Do It Yourself) robot based on the highly popular BBC micro:bit. The Motor:bit STEM education robot is designed to get kids (12 and older) introduced to the world of coding, electronics and robotics. The Motor:bit STEM education robot is designed from ground up to be an easy to easy to work with, easy to assemble robot and simply built with the aim of giving educators, parents and kids a great opportunity to get a taste of robotics, electronics and coding.
The Motor:bit is really easy to assemble and can be put together in less than an hour. We would recommend the Motor:bit STEM education robot to kids and adults who are willing to put in some effort to put together their robot and take on a small maker challenge assembling the robot from its different components. So if you are keen to introduce your child to the world of STEM and are keen to get them coding, introduced to the world of robotics using the micro:bit the Motor:bit is for you. Overall the Motor:bit STEM education robot is a great way to get started with the basics of coding and robotics using a flexible, affordable and easy to work with robotic platform.
If you haven’t read the initial article in this series please head over and check out –
- Exploring robotics with the motor:bit STEM Education Robot for the BBC micro:bit – Introduction
- Exploring robotics with the motor:bit STEM Education Robot for the BBC micro:bit – Diving into the capabilities of the motor:bit main board
- Exploring robotics with the motor:bit STEM Education Robot for the BBC micro:bit – Learning to use Line Sensors
- Exploring robotics with the motor:bit STEM Education Robot for the BBC micro:bit – Learning to keep distance (Learning to use ultrasonic sensors with the motor:bit)
- Exploring Robotics with the motor:bit and BBC micro:bit – Line Following Challenge
- Exploring Robotics with the motor:bit and BBC micro:bit – Avoiding Obstacles
- Exploring Robotics with the motor:bit and the BBC micro:bit – Remote Control
- Exploring Robotics with the motor:bit and the BBC micro:bit – Use Your Andriod Phone as a Remote Control (This tutorial)
If you are interested in purchasing the motor:bit STEM Education Robot for the BBC micro:bit then head over to OzToyLib and grab one now.
BBC micro:bit and the on-board Radio – The BBC micro:bit has an inbuilt Bluetooth Low Energy (BLE) radio which can be used for short range communication. Bluetooth was designed for short range communication between devices while wireless (or Wi-Fi which we are quite used to) was designed for longer range communication between devices. It’s this Bluetooth radio functionality that we’ll be exploring in this article. With Bluetooth functionality enabled we can pair up the BBC micro:bit with any other Bluetooth device (in our case an Android Cell phone) and control the motor:bit STEM Education robot from our cell phone.
For purposes of this tutorial we will make use of the bitty controller. The bitty controller is an application for the Android phone developed by bitty software. You can read more about the bitty controller at – http://www.bittysoftware.com.
The bitty controller lets you remote control a Bluetooth connected device which uses a micro-controller or computer like a BBC micro:bit, Arduino or Raspberry Pi. It provides a choice of user interfaces including several digital switches for switching things and and off, a dual d-pad controller, an analog touchpad for fine control and an enhanced UI which includes support for up to 5 sensors and has an extra button.
The Bitty controller software needs to be purchased from the Google Play store. Please speak with your parents and get them to purchase the application for you.
Let’s now dive some code and implement remote control capability for our robot so that we can control our motor:bit STEM Education robot using the bitty controller on the Android phone.
Download the software : Let’s now download the software for our Android phone. Head over to the Google Play store and purchase the application.
Setup Bluetooth : To activate the Bluetooth on our BBC micro:bit, we will need to press button “A+B” simultaneously and then press reset button. The BBC micro:bit screen will then display PAIRING MODE！and a special character. This character is unique to each micro:bit. Do note that this is the special identifier for Bluetooth for your BBC micro:bit.
Once paired successfully with your Android or IOS device, your micro:bit screen will display a “√”(a tick).
Load some custom packages using Makecode – So let’s open up a browser and head over to BBC MakeCode for micro:bit https://makecode.microbit.org and load up the programming interface. Once you have MakeCode open head over to the “Advanced” section. We’ll now add the “motor:bit” module from the Advanced options on the BBC Makecode interface. See image below for details –
Let’s now add the following package “motor:bit” as shown below. You will also need to search and add the “bluetooth” package for your BBC micro:bit as shown below.You will have to search for the package “motor:bit” within the Advanced option which then imports the relevant libraries into your program.
Let’s write some code – Open up your makecode block editor and create the blocks shown below.
- At startup the micro:bit will display “EF-motorbit”
- When we are connected via bluetooth the micro:bit will display “T”
- When disconnected the micro:bit will display “F”
For purposes of safe operations we set speed to 0 in each of the cases.
Set event source block and name it MES_DPAD_CONTROLLER_ID, which is the joystick controlling panel of the APP. Name the event value
MICROBIT_EVT_ANY so that it can obtain all event information. If the event value is
MES_DPAD_BUTTON_A_DOWN, we can know from the event table above that the event is the left top circle button is pressed. Thus, the operation status is 1 (move forward). At the same time, set both motors run at its full speed to make the car move forward. If the event value is
MES_DPAD_BUTTON_A_UP, we know from the event table above that the left top circle button is released. Thus, the operation status is 0 (stop). At the same time, set the speed of both motors to 0 and the car stops. See the image below for the code block.
Create a variable and name is
flag, which stands for the car movement status. When
flage is 1, it means the car is moving forward. If the event value is
MES_DPAD_BUTTON_3_DOWN, we can known from the table above that the right square button is pressed. Thus, the car will turn right. If the event value is
flag is 1, we can know from the table above that the left square button is pressed. Thus, the car will turn left. If none of the above two situations happened when
flag is 1, then set the speed of both motors to 100 and the car will move forward at its full speed. See code below for details.
Here’s the entire code block for the BBC micro:bit connected to the motor:bit STEM Education robot as seen within the BBC makecode editor. See code below for details.
Load up the entire code block above onto the BBC micro:bit housed on the motor:bit STEM Education robot. Power up the motor:bit STEM Education robot and then use the bitty controller application to scan for micro:bit devices in the room.
Testing things out – Set your robot out on a flat surface, pair up the micro:bit with your Android phone and use the Bitty controller to navigate the robot around the room.
Conclusion – If you’ve followed through each of the tutorials in this series you would have by now introduced yourself to the basics of robotics. You would have learned about the motor:bit main board used to build the motor:bit STEM Education robot, learned about line sensors, learned about ultrasonic sensors, coded the robot to successfully move around a track, given your robot the ability to spot obstacles and navigate around it and finally learned how to control your robot remotely both over radio and bluetooth. Give yourself a pat on the back for having come this far. Very well done!!!!
For more tutorials please do check out the development track at KidzCanCode.com for detailed tutorials on the motor:bit STEM Education Robot for the BBC micro:bit. If you are looking to purchase the motor:bit STEM Education Robot head over to the store at <OzToyLib> and check it out.
About BBC micro:bit – The Micro Bit (also referred to as BBC Micro Bit, is an ARM-based embedded system designed by the BBC for use in computer education in the UK. The board is 4 cm × 5 cm and has an ARM Cortex-M0 processor, accelerometer and magnetometer sensors, Bluetooth and USB connectivity, a display consisting of 25 LEDs, two programmable buttons, and can be powered by either USB or an external battery pack.
Explore our FREE coding, electronics and robotics resources for the BBC micro:bit at www.KidzCanCode.com – <Link>. Hopefully you have enjoyed the post. If you have any questions, comments or suggestions for future tutorials drop us a note at – learning at hack2 dot live.
FREE STEM learning at KidzCanCode – At KidzCanCode.com we offer FREE access to various STEM (Science, Engineering, Technology, Math) development courses at KidzCanCode.com. At KidzCanCode.com you will find courses on Scratch, BBC Micro:Bit, Raspberry Pi, Arduino, 3D modelling, Robotics and Electronics.
If you are looking for a BBC micro:bit, Arduino, Raspberry Pi, starter kits, electronics kits, robotics kits including other STEM learning kits we would recommend you drop by our online store here – <OzToyLib>.