What is an accelerometer or a magnetometer? Many Android apps rely on the accuracy of sensors within your device to work properly. Below I have set out what these sensors are, with a focus on how they are used to produce an accurate compass bearing. I have also included some advice on how to calibrate your device to ensure that you get the best readings from these sensors.
The sensors in your Android device
Most Android powered devices have built-in sensors that measure motion, orientation, and various environmental conditions. Android app developers make use of these sensors to monitor three-dimensional device movement or positioning. Within our Accurate Compass, and Sun Position apps, we use the magnetometer and accelerometer within your device to calculate a compass bearing.
It’s worth noting that not all Android devices contain a magnetometer sensor. If they don’t have one you won’t be able to use many compass apps, so if this is important to you, you might want to check before you buy a new phone!
What are a magnetometer and accelerometer?
The magnetometer sensor in your device measures the direction of the magnetic field acting on your device. (i.e. it monitors which way is north).
The accelerometer sensor measures the acceleration force that is applied to your device along the three axes. When your phone is stationary, it will determine which way gravity is pulling. Within our compass apps, we use this sensor to determine the angle at which your device is rotated from horizontal. This allows us to know how to draw the direction to magnetic north on your screen (as it will look different if your phone is held vertical than if it is horizontal).
Checking the accuracy of your sensors
If you are unsure of the accuracy of your sensors, you can check this within the “sensor status” or “calibrate” menu option of our Accurate Compass or Sun Position apps. This will show an information screen setting out the accuracy of your magnetometer and whether any calibration is required.
The information screen will also give an indication of whether your accelerometer is working correctly. However, you can check this further using one of the many apps on the Play store which give sensor readings (Accelerometer is a good example). Once you have installed one of these apps there are a few tests you can carry out:
1. Lay your phone flat on a table - you should get a steady reading of 9.8 m/s2 (gravity) on the Z axis, 0 on the x and y axis.
2. Hold your phone vertically against a wall, resting the bottom edge flat on a table - you should get a reading of 9.8 m/s2 on the y axis, 0 on the others.
Calibrating your sensors
Unfortunately the magnetometer sensor within your device will be very sensitive to interference from local magnetic fields, even if these are very small (such as a metal button on your phone case). Once they have been exposed to this interference over a prolonged period, the sensor will no longer be accurate and will need re-calibrating.
To calibrate your device move it a far away as you can from any magnetic interference (cars, computers etc).
You should then wave your device in a figure of 8 pattern rotating it in different directions as you do this. If your device is very hot you may need to wait for it to cool down. You can also try switching it off and on again.