Publish Data from Micro:bit v2 to Qubitro IoT Platform

Publish Data from Micro:bit v2 to Qubitro IoT Platform

Publish built-in sensors' BBC Micro:bit v2 data to Qubitro IoT platform through MQTT protocol.

Full tutorial BBC Micro:bit v2 & Qubitro IoT platform

In this tutorial, we will learn how to publish sensor readings from BBC Micro:bit v2 to Qubitro IoT platform through the MQTT protocol.

Qubitro is the fastest way to build IoT applications with predictable pricing, developer-friendly features, and scalability you’ll love. You can connect your hardware to Qubitro, collect the data and create data visualization on your own dashboard. For more information about Qubitro, you can check its official site:

We will use the BBC Micro:bit v2, a pocket-sized microcontroller based on 32 bit Arm Cortex-M4. It's equipped with Bluetooth Low Energy, radio antenna, 5x5 LED matrix, two buttons, MEMS microphone, speaker, and several sensors like touch sensor, light, accelerometer, magnetometer, and temperature sensor. For more information about BBC Micro:bit v2, you can check its official site:

Step 1. Create Qubitro Project

Signup or login to Qubitro Portal, then create a new project. Click the New Project button, add the project name & description, then click Create Project button.

Create a project on Qubitro

Then create a new device inside your project. Choose your device connectivity method, in this case, MQTT. Then enter device details name, description, brand, model, and location.

Create a device on Qubitro

After that, you'll get your credentials (host, port, username, password & clientId) to connect to the Qubitro MQTT broker. Please note these values because we'll use them on our code later. You can check these values on the device Settings menu. Your username & clientId are your Qubitro Device ID, and your password is your Qubitro Device Token.

Qubitro credentials

Step 2. Code the Micro:bit

Go to Microsoft Makecode editor and create a new project. Then, Install ESP8266 extension: click the gear icon, choose Extensions, search for ESP8266 and install the one named iot-environment-kit, an ESP8266 extension by Elecfreaks.

Install ESP8266 extension: iot-environment-kit by Elecfreaks

Using block programming, arrange the following block codes:

Block codes

You can also code using JavaScript or Python:


ESP8266_IoT.initWIFI(SerialPin.P16, SerialPin.P2, BaudRate.BaudRate115200)
ESP8266_IoT.connectWifi("your_ssid", "your_pwd")

basic.forever(function () {
    ESP8266_IoT.connectMQTT("", 1883, false)
    ESP8266_IoT.publishMqttMessage("{\\\"temperature\\\":" + input.temperature() + "}", "YOUR_QUBITRO_DEVICE_ID", ESP8266_IoT.QosList.Qos0)

ESP8266_IoT.init_wifi(SerialPin.P16, SerialPin.P2, BaudRate.BAUD_RATE115200)
ESP8266_IoT.connect_wifi("your_ssid", "your_pwd")

def on_forever():
    ESP8266_IoT.connect_mqtt("", 1883, False)
    ESP8266_IoT.publish_mqtt_message("{\\\"temperature\\\":" + str(input.temperature()) + "}",

Download its hex file, then insert it into the Micro:bit v2. Once done, Micro:bit will display a heart icon on its 5x5 LED matrix, connect to the WiFi and publish data to Qubitro every 5 seconds.

Micro:bit ❤️ Qubitro


On the Qubitro device Data tab, you'll see the data stream from your Micro:bit. You can create data visualization on the Analytics tab or create your own centralized dashboard in the "Monitoring" section.

Data streams

Subscribe to Qubitro Blog

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.