Introduction
In this article, I will show you how we can use our BBC Micro: Bit as a compass. We will be able to see directions based on the angle we read from the Micro: bit. So let us see how we can do this.
Basically, we're going to read the value from the sensor that is built within the Micro: bit. This is called a magnetometer, which is actually used to detect the earth's magnetic field along three perpendicular axes, X, Y, and Z. As we can see below, there is a sensor which is going to give us the readings and based on those reading we are going to decide the directions.
Basically, we're going to read the value from the sensor that is built within the Micro: bit. This is called a magnetometer, which is actually used to detect the earth's magnetic field along three perpendicular axes, X, Y, and Z. As we can see below, there is a sensor which is going to give us the readings and based on those reading we are going to decide the directions.
Tools You Need
- Micro: Bit (1 pcs)
- USB Cable (1 pcs)
- Battery AAA 1.5 v(2 pcs)
- Battery Box (1 pcs)
So this is very easy and it won't take long to read the values from the Micro: bit. We're going to work on the basis of the following image. Based on this we're going to set our Micro: bit to decide on the directions. We can see the trigger zone for every direction and we're going to set the values in the Micro: bit so that when it detects these angles it is going to decide the directions. We can see the trigger zones for:
- North 20 to 340 degrees.
- West 250 to 290 degrees.
- East 70 to 110 degrees.
- South 160 to 200 degrees.
Now, let us code the Micro: bit for this. So go to makecode.microbit.org and create a new project and choose a forever block there. Now, go to the Logic block and choose if then else and then other logic blocks as shown.

Now, we need to take the compass reading so that we can place the compass reading in the logic block, and we can make the decision for the direction. And for this, you need to go to input and choose compassheading(). Actually, copassheading() is a variable that reads the values from the compass or we can use the magnetometer which is built in the Micro: bit so that we can capture these values and use them for our compass.
So, now follow the steps and let's build our compass.
First drag "if", "then", "else" inside the Forever block and place logical AND-OR block inside the if then else block.
First drag "if", "then", "else" inside the Forever block and place logical AND-OR block inside the if then else block.

Hadshana KamalanathanPosted Jul 21, 2018, 10:03 AM
THanks for sharing..