Example Code for micro:bit
Last revision 2026/01/14
The article offers a comprehensive guide to using a micro:bit board and PM2.5 sensor for measuring standard particle concentration. It outlines hardware and software requirements, including MakeCode setup, and provides sample code for reading particulate data. Readers can learn to evaluate air quality through coding, wiring diagrams, and result analysis.
Hardware Preparation
- 1 x micro:bit control board
- 1 x PM2.5 Air Quality Sensor
- 1 × MBT0008 micro:IO Extend micro:bit control board IO expansion board
- Several Dupont lines
Software Preparation
- makecode
- How to use makecode software?
MakeCode online graphical programming basic operation tutorial
MakeCode basic operation tutorial - Add the micro:bit library (Temporary)to MakeCode.
Wiring Diagram

Sample Code
1. Sample code-standard particle concentration

Program link: https://makecode.microbit.org/_9HRJ7VTsDaM2
Result
In the state of standard particulate matter, the concentration of PM2.5, PM1.0, PM10 read is: 37ug/m3, 26ug/m3, 41ug/m3. The data printed by the serial port is as follows:

2. Sample code-the number of particles per 0.1 liter of air
Function description: Read the number of particles above 0.3um/1.0um/10um per 0.1 liter of air. Program link: https://makecode.microbit.org/_JMxHs15fK29r

Result
It is read that the number of 0.3um/1.0um/10um particles per 0.1 liter of air is about 1115, 160, and 0 respectively.

Was this article helpful?
