In 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:
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:
Use the Block Programming interface to add the following code (click on picture to zoom in):
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:
.