Step 1: Make it
What is it?
Turn your micro:bit into a simple compass which shows its bearing from magnetic North in degrees.
![micro:bit showing 0 degrees numerical reading and a compass pointing North](https://cdn.sanity.io/images/ajwvhvgo/production/4bc56a46a71bee56bc2c7c98cdc94b9cbc30ec46-10223x6264.png?w=653&q=80&fit=max&auto=format)
How it works
- Your micro:bit has a built-in compass sensor called a magnetometer. You can use it to measure the Earth’s magnetic field and use it as a compass.
- When you first use the micro:bit compass you have to calibrate it – a little game appears on the screen where you have to tilt the micro:bit to light up every LED, then you’re ready to go.
- When you press the button A input, the micro:bit takes a reading from the compass sensor and shows the device’s numerical compass bearing on the LED display output. Point the micro:bit North and you should see a reading of 0 degrees.
![compass rose showing angles for each point, North, South, South-East etc](https://cdn.sanity.io/images/ajwvhvgo/production/c1ba4627f246bc638f48cd51afb80342fd1db540-2019x1878.png?w=653&q=80&fit=max&auto=format)
What you need
- micro:bit (or MakeCode simulator)
- MakeCode or Python editor
- battery pack (optional)
- a planet with magnetic poles to stand on – for example, Earth!
Step 2: Code it
Step 3: Improve it
- Add another button to recalibrate the compass.
- Have the micro:bit make a sound when it’s pointing in a particular direction – this could be useful to help navigation when you can’t look at a display or for people with impaired vision.
- Make the micro:bit display letters or arrows to show if it’s pointing North, South, East or West.
This content is published under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) licence.