Introduction

Nrf51822 is a BLE (Bluetooth Low Energy) module allows micro:bit to send and receive Bluetooth signals. We can use the built-in bluetooth module to communicate with the mobile phone’s APP, thereby using the APP to control external devices connected to the micro:bit control board.

About Bluetooth

Bluetooth® is a wireless technology standard for exchanging data over short distances (using short-wavelength UHF radio waves in the ISM band from 2.4 to 2.485 GHz[3]) from fixed and mobile devices, and building personal area networks (PANs). We can use Bluettoth to connect multiple devices which resolves the difficulty of simultanuous data transmission.

Install APP

Before programming, you need to install the Bluetooth APP to your phone. (This app only support Android)

https://play.google.com/store/apps/details?id=com.bluetooth.mwoolley.microbitbledemo

Add Extensions

Click on “Advanced” in the MakeCode Drawer to see more code sections.

We need a new Extension for coding to bluetooth and OSOYOO Robot. Click on “Add Package” at the bottom of the code block and search for “bluetooth” and type the URL “https://github.com/osoyoo/OSOYOO-MICRO-BIT-CAR” to add them to your project.

Note:If you get a warning telling you some packages will be removed because of incompatibility issues, either follow the prompts or create a new project in the Project file menu.

Bluetooth Connction Settings

To connect with micro:bit, we should first pair then connect, Click the icon on the top right: More… ->Project Setting, check the first option
“No Pairing Required: Anyone can connect via Bluetooth”

CODE PROGRAM

Download the script to micro:bit and test

Bluetooth Connection

After downloading, open Bluetooth service of your phone, then open App, and change its setting, clock the three-dots icon on the top right, choose settings, then uncheck option “Filter unpaired micro:bit from scan results.

After setting, scanning devices again. BBC micro:bit[t****] is listed, then you can click it to connect with micro:bit.

操作图片

After connecting, control options are listed as below, and LEDs matrix shows the smile icon.

app主页面操作图片

Then you can try to control micro:bit by Bluetooth. Click Accelerometer, tilt your
micro:bit, and the micro:bit image in APP tilt as well

陀螺仪操作图片

Click button option. Press buttons of your micro:bit. The buttons icon in APP react the button event.

分别按下按键A按键B,APP上亮灯图片

Click LEDs option, edit the LEDs matrix then clock SET DISPLAY, or send a text

app输入字符或者符号,显示到micro bit图片

.Click Temperature option, the current temperature is showed in APP

app显示温度

When disconnecting the Bluetooth connection, you can see the icon “X” displayed on the led matrix.

Bluetooth remote control Robot

In the App, you can find an option named Dual D-Pad Controller. Click it to enter a control page with dual D-pad (eight buttons). Click the top right three-dots icon you can change the settings. Every time virtual buttons are pressed, related signals are sent to micro:bit via Bluetooth. Gamepad events are triggered by these signals on micro:bit.

Code Program

Download the script to micro:bit and test

Download the script and test.

Running Result

“Smile” is displayed on Bluetooth connection, and “X” is displayed on Bluetooth disconnection.

The buttons on the left of the control panel control the movement of the car, and the buttons on the right of the control panel control the headlights and horns of the car.