micro:bit has integrated multiple sensors including accelerometer. Today, we are going to use accelerometer to make a level device and display the inclination on NeoPixel ring in bar chart format.

Component List


**Tips: If you want all components above, you may need Elecfreaks Micro:bit Starter Kit.**

Major Component Introduction


There is an accelerometer on your micro:bit which detects the speed change of micro:bit. It converts analog information into digital form that can be used in micro:bit programs. Output is in milli-g. The device will also detect a small number of standard actions, e.g. shake, tilt and free-fall.

The corresponding X, Y, Z axle direction of accelerometer are showed below:

Experimental Procedure

Hardware Connection

Connect your components according to the picture below:

After connection, we can see:

Software Programming

Click to open Microsoft Makecode, write the following code in the editor.(https://makecode.microbit.org/)

Add Package

Click “Advanced”in the choice of the MakeCode to find more choices.

Click “Extensions”, search “neopixel”in the dialog box and then download the “neopixel”.

Program as the picture shows:

Details for the code:



You can also download the links directly:


The RGB LED ring lights on in different color with the movement of the micro:bit.


If we want to set 4 of the LEDs to light on in turns, how can we design the circuit and program?