There is a compass on the micro:bit.

The compass detects the earth’s magnetic field, allowing you to detect which direction the micro:bit is facing. The compass has to be calibrated before it can be used.

‘Calibrating’ the compass ensures the compass results are accurate. To calibrate the compass in Python use compass.calibrate().

When the calibration begins, the micro:bit will scroll the instruction « Tilt to fill screen ». To calibrate the compass, tilt the micro:bit to move the dot in the centre of the screen around until you have filled up the whole screen.

from microbit import *

compass.calibrate()

while True:
    angle = (compass.heading())
    display.scroll(angle)
    sleep(1000)

The micro:bit measures the compass heading from 0 to 359 degrees with its magnetometer chip.

DIY

Scroll the message ‘North’ when the compass is between 355° and 5°.