Create a Mobile Music Remote Control with micro:bit

Create a Mobile Music Remote Control with micro:bit

This article covers:

1. How to connect micro:bit to a mobile phone via Bluetooth

2. Using micro:bit as a remote control to control mobile music player

Micro:bit is a micro programmable computer launched by the BBC in collaboration with many companies, designed to allow every child to have zero-based access to computer programming without needing to learn any programming language. For more information, please refer to the previous article on how to create a functional compass using micro:bit.

Create a Mobile Music Remote Control with micro:bit

We generally access the website https://makecode.microbit.org for web programming. After writing the instructions, download them to the micro:bit drive or copy the hex file to the drive.

Create a Mobile Music Remote Control with micro:bit

This time we will use micro:bit to create a remote control for mobile music playback and song switching.

Micro:bit comes with a Bluetooth chip that works in low energy Bluetooth mode (BLE), which is supported by Android 4.3 and iOS 6 and above. What we need to do is pair the mobile phone with micro:bit through the micro:bit app on the phone or tablet, and then let micro:bit run the corresponding program to communicate with the phone via Bluetooth. Micro:bit can pair with iOS, Android, or Windows phones/tablets. It is recommended to use Android devices for debugging.

There may be issues connecting micro:bit to mobile Bluetooth on some models. For example, a colleague’s Samsung phone always fails to connect. Even if the connection is successful, iOS devices may not respond normally to micro:bit’s Bluetooth communication requests. All attempts on an iPhone were unsuccessful, and it was only when we switched to an Android phone that we were able to test successfully. The openness of iOS devices may have some issues, and the specific reasons need further analysis.

Both iOS and Android devices can use the micro:bit app to pair with micro:bit, and the methods are basically similar.

Create a Mobile Music Remote Control with micro:bit

Click the pairing button on the app and follow the prompts. Note that you need to press and hold the A and B buttons simultaneously, then press the reset button on the back of the board, hold for a moment before releasing, while keeping the A and B buttons pressed throughout the process. Then micro:bit will display the words “pairing mode” and show a graphic, which we need to draw in the app. Click next.

Create a Mobile Music Remote Control with micro:bit

A prompt will appear to start the connection, and you will be asked to enter a 6-digit number. Pressing the A button on micro:bit will display this 6-digit number. For iOS versions, simply enter it. For Android versions, you need to pull down the notification bar from the top of the screen, click the pairing request notification, and enter the 6-digit number within a 30-second time limit.

Detailed pairing instructions can also be found in this video

After the first pairing is successful, if the connection is interrupted and you need to pair again, click connect and then click the small connection icon to reconnect. If it turns green, the connection is successful. This reconnect feature is more convenient on Android, while iOS devices may have difficulty reconnecting.

Create a Mobile Music Remote Control with micro:bit

Materials and Tools List

  • Micro:bit Main Control Board

  • Data Cable

  • Makecode Online Website, such as https://makecode.microbit.org

  • One mobile phone or tablet, music playback application

Writing the Program

Martin Woolley is a British technician who participated in the development of the Bluetooth module for micro:bit. He has shared some micro:bit Bluetooth programming examples on his blog, and this time we will follow his instructions.

First, we access https://makecode.microbit.org or other online programming websites, open the modular programming interface, and in the advanced -> add package option, add the bluetooth and devices packages.

Create a Mobile Music Remote Control with micro:bit

Create a Mobile Music Remote Control with micro:bit

After that, a prompt will indicate that the radio module is incompatible with these two modules; click continue.

Create a Mobile Music Remote Control with micro:bit

You will see that the Bluetooth and device modules have been added.

Create a Mobile Music Remote Control with micro:bit

The commands in the device module depend directly on the Bluetooth module (adding the device module will automatically add the Bluetooth module as well). Here we will directly use the “remote control” command from the device module.

Create a Mobile Music Remote Control with micro:bit

It is not new for mobile phones and external devices to communicate via Bluetooth. For example, some selfie sticks connect to mobile phones via Bluetooth, allowing you to control the mobile camera application by pressing the button on the selfie stick. The image above shows that there are many commands in the device module, which can control both the music player and the camera.

Create a Mobile Music Remote Control with micro:bit

The program is as shown; pressing the A button skips to the next song, pressing the B button plays the previous song, and pressing A+B simultaneously plays or pauses the music. The variable “playing” is 1 when music is playing and 0 when paused.

Whether the music playback application is displayed in the foreground or playing in the background, the commands from micro:bit are effective. The LED display command is drawn arbitrarily, just to indicate that the program is running normally and to identify which device it is compiled on, whether on a computer or a mobile phone.

Some Notes

After flashing the compiled hex file with Bluetooth commands onto micro:bit, once the board and the mobile/tablet Bluetooth pairing is successful, communication with the mobile phone can be successfully established.

This hex file can either be found directly online or compiled on your computer.

Create a Mobile Music Remote Control with micro:bit

Additionally, you can open the web programming interface on your mobile/tablet, program it on the mobile phone, compile it into a hex file, save it to the mobile phone, and then use the flash option in the micro:bit app to transfer this hex file via Bluetooth to micro:bit. This way, you can complete the entire process using just one mobile phone/tablet without needing a data cable. (However, some phones or browsers may not be able to open the web programming interface.)

Create a Mobile Music Remote Control with micro:bit

The process of opening the web programming interface on your mobile/tablet for compilation and flashing onto micro:bit is not mandatory. In our experiments, we directly compiled a hex file on the computer, copied it to the micro:bit drive, and after pairing the Android phone with micro:bit via Bluetooth, we were able to control the mobile music player to switch songs. The micro:bit app on the mobile phone only serves to pair with micro:bit via Bluetooth.

In our experiments, iPhones and iPads could hardly open the online programming interface using Safari browser under domestic networks, whether using 4G or Wi-Fi. However, Android devices did not have this issue :-D, although it still took some time and not all browsers could succeed. Similarly, when the Bluetooth pairing is disconnected, Android phones can easily reconnect, while iOS may fail to reconnect and require re-pairing.

Let’s take a look at the effect of the program running.

This programming is very simple; you can directly compile the hex file using any web programming interface with a modular interface. If you are using the Android version of the micro:bit app, you can also try the several demo programs included in the app.

Future Improvements

The current code still has some flaws. If you control playback using both the micro:bit and the mobile application screen buttons simultaneously, the judgment of whether the music is in a playing or paused state will be inaccurate.

For example, if you start playing music using the A+B keys on micro:bit and then press pause on the mobile player, the micro:bit program will still think the music is in a playing state. If you press A+B again, it will trigger the pause command, which will not take effect, resulting in no response after pressing the button, and you will need to press it again to control the mobile player normally. However, this does not affect usability.

Recently, we launched a series of micro:bit tutorials; click the link to learn more:

How to create a functional compass using micro:bit

How to create a Morse code transmitter using micro:bit and 3D printing

Create a Mobile Music Remote Control with micro:bit

Stone Axe Makers

The stone axe (Handaxe) may be the earliest tool made by humans. From stone tools to 3D printing, let us create something joyfully like our ancestors.

Leave a Comment

×