Example Code for micro:bit-WS2812 RGB Ambient Light

Last revision 2025/12/19

This article provides detailed instructions and example code for creating ambient light effects using WS2812 RGB LEDs with a micro:bit, including setup guidance and dynamic lighting effects such as rotating rainbow, breathing light, and flowing water lights.

Hardware Preparation

  • Maqueen V5 Robot Car: 1
    (Purchase Link: https://www.dfrobot.com/product-2937.html)
  • micro:bit Mainboard: 1
  • 3 AA Batteries: 1 set

Software Preparation

To use the ambient lights, you first need to load the "neopixel" library in makecode. The method is shown as follows:

  • MakeCode Platform: https://makecode.microbit.org/
  • Click the Extensions button:
  • Search for "neopixel", and then select "neopixel", as shown in the figure:
  • Maqueen Library: Load via MakeCode Extensions (search for "dfrobot" and select "Maqueen")
  • Neopixel Library: Load via MakeCode Extensions (search for "neopixel" and select "neopixel")

Other Preparation Work

  • Ensure the micro:bit mainboard is properly plugged into Maqueen V5.
  • Install the batteries correctly.
  • Turn on the power switch.
  • Load the Neopixel library in MakeCode.

Sample Code

Example 1: Light up the ambient lights

This example shows the switching display of nine colors for the ambient lights.

Example 2: Breathing Light Color Fusion

This example demonstrates the gradual fusion effect of the breathing state of the ambient lights by setting the RGB color values.
Example Link: https://makecode.microbit.org/_Ao1L5tUXaEkj

Example 3: Rotating Flowing Water Lights

This example demonstrates the effect that the ambient lights present the flowing water lights lighting up one by one.

Example 4: Rotating Rainbow Lights

This example demonstrates that the ambient lights display a gradual rainbow color and present a dynamic switching effect.
Among them, the hue of the rainbow color can be adjustable within the range from 1 to 360, and different color effects will be presented.

Result

  • Example 1: Ambient lights switch between nine colors.
  • Example 2: Ambient lights show breathing color fusion.
  • Example 3: Ambient lights show rotating flowing water effect.
  • Example 4: Ambient lights show rotating rainbow colors.

Was this article helpful?

ON THIS PAGE

TOP