Do you know compass? I believe most of you have played it ever. Today I am going to use micro:bit to create a compass and display its direction on NeoPixels ring. Want to know how I do it? Just read the article below and follow my steps. Let’s go!

Component List


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

Major Component Introduction


Here, compass in reality is a magnetometer. The magnetometer is a separate chip that provides magnetic field strength sensing. A software algorithm in the standard runtime uses the on board accelerometer to turn these readings into a board orientation independent compass reading. The compass must be calibrated before use, and the calibration process is automatically initiated by the runtime software. This device is connected to the application processor via the I2C bus.

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:


Rotate the whole device, you can see the Rainbow LED Ring always point at the same direction. Note: Every time you start to use the compass (for example, if you have just turned the micro:bit on), the micro:bit will start to calibrate compass (adjust itself). It will ask you to draw a circle by tilting the micro:bit. If you are calibrating or using the compass near metal, it might confuse the micro:bit.


If this experiment does not use Rainbow LED Ring but use the arrow displayed on micro:bit as indicator, then how to design circuit and program?