BBC micro:bit – Digital Compass

compass-iconIn this challenge we will use the compass sensor from the BBC micro:bit to create a digital compass.

Based on the compass heading (retrieved ftom the sensor), the micro:bit will display one of the four cardinal points:

  • N for North
  • E for East
  • S for South
  • W for West

For the micro:bit to decide which cardinal point to display it will have to look at the compass headings (angle given in degrees).

Check the following pictures to understand how angles and cardinal points work:
compass-full

cardinal-points

Heading (in degrees) Cardinal Point
Between 315° and 360°
OR
Between 0° and 45°
North
Between 45° and 135° East
Between 135° and 225° South
Between 225° and 315° West

Coding the compass


Access the micro-bit website:
micro-bit-logo

Use the Block Programming interface to add the following code (click on picture to zoom in):
digital-compass-bbc-microbit-javascript-code

Calibrating the compass


The first time you will run this program, the BBC micro:bit will ask you to “Draw a circle”.

This step is required to calibrate the compass. Without this step the readings would be inaccurate.

To draw the circle on the LED display simply rotate the device to move “the light” around the LED screen and display a circle as follows:

micro-bit-circle .

Did you like this challenge?

Click on a star to rate it!

Average rating 4.6 / 5. Vote count: 9

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: