Example Code for micro:bit-Read Line-tracking Sensor
Last revision 2026/01/14
This article provides detailed instructions and sample code for using the line-tracking sensor on Maqueen Lite with micro:bit, enabling users to read sensor outputs for robotics applications.
Hardware Preparation
- Maqueen Lite x1
- micro:bit V1/V2 x1
- MicroUSB cable x1
Software Preparation
- Programming Platform: makecode
- Libraries: maqueen, neopixel
Wiring Diagram
No additional wiring is required except inserting the micro:bit into Maqueen Lite.
Other Preparation Work
- Load MakeCode Graphical Library for Maqueen as described in the previous example.
Sample Code
Effect: when a Maqueen's line-tracking sensor is put on the black line, the sensor outputs 0, and display 0 on the micro:bit LED matrix; if put on white area, output 1 and display 1 on the LED matrix.
Code URL: https://makecode.microbit.org/_EvtX1yD0RWpj
Code File: maqueen7.hex
Code Screenshot:
Result
When a Maqueen's line-tracking sensor is put on the black line, the micro:bit LED matrix displays 0; if put on white area, displays 1.
Additional Information
The Maqueen car has two line-tracking sensors as shown in the following figure:

Was this article helpful?
