Example Code for micro:bit-Lighting up the LED strip
This article offers a comprehensive guide on lighting up an RGB LED strip with a micro:bit, covering hardware and software preparation, wiring, and sample code for controlling LED brightness and hue to produce colorful lighting effects.
Hardware Preparation
![]() |
![]() |
![]() |
|---|---|---|
| M011.00184 RGB LED Strip | MBT0039 micro:bit | BOS0040 micro:bit BOSON Expansion Board |
Software Preparation
Before using the colorful light strip, load the library in Mind+. Open the Mind+ programming platform, find the "Extension" in the lower left corner and click it, then click the WS2812 RGB light in the "display" to load the relevant commands. At this time, the display module will appear in the command area. After completing the above steps, connect the light strip to the micro:bit board to control the effect of the light strip through programming.
Wiring Diagram

Other Preparation Work
① Select the LED strip's pin to be connected to micro:bit, and the number and brightness of the LED of the strip. The command statement is as follows. Here we set the pin to P0, the number of LED to 7, and the brightness to 255 (range 0-255).
② Determine the range of usable LED. The commands to be called are shown below.
Here the range is 0-6 in Mind+ and 1-7 in MakeCode.
Then determine the range of the LED strip hue, and the commands to be called are shown below. Here the hue range is 1-360 (red - green - blue).
Sample Code
Mind+ Sample Code:
MakeCode Sample Code:
Result
Colorful Effect:
Add the "rotate pixels" block into the main program so that the LED strip can light up and shows gradient color recurrently. It's more beautiful to present a light ring effect.
Video Demo
| Programming |
|---|
![]() |
Additional Information

Was this article helpful?




