Using our website means you agree to using cookies which help us improve microbit.org.Learn more
Skip to content

Activity

Compass bearing

Beginner | MakeCode, Python | Buttons, Compass | Input/output, Magnetism, Sensors, Using a compass

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

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

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.