Sensor hygiene
How to calibrate a phone compass
Short answer
Hold the phone away from your body and trace a figure of eight in the air two or three times, rotating your wrist as you go. Do it away from metal and magnets.
A magnetometer does not measure direction. It measures the strength of the magnetic field along three axes, and the direction is inferred. Anything that adds a steady field of its own, a speaker magnet, a case clasp, the phone's own components, shifts all three readings by a constant offset and the inferred direction is wrong.
Calibration is the process of measuring that offset so it can be subtracted. That is why it involves moving the device: the software needs readings from many orientations to separate the fixed offset from the earth's field.
Method
Step by step
In this order. Each step assumes the one before it is done.
-
01
Get clear of interference first
Calibrating next to the thing that is causing the problem bakes the problem in. Step two metres away from laptops, monitors, speakers, desks with steel frames, cars and anything with a magnet in it, and take the phone out of a magnetic case or car mount.
-
02
Trace a figure of eight
Hold the phone out in front of you and draw a large figure of eight in the air, rotating your wrist so the phone presents different faces as it moves. Two or three passes is enough. It looks silly and it is doing real work: each orientation is another equation in the solve for the offset.
-
03
Tell interference apart from miscalibration
Turn slowly through a full circle and watch the bearing. A miscalibrated compass is offset but smooth: every reading is wrong by roughly the same amount. Interference is lumpy: the bearing sticks, jumps, or runs fast through part of the turn and slow through the rest. Lumpy means move, not calibrate.
-
04
Sanity check against something you know
Check the reading against a direction you already know, a street that runs north-south on a map, or the sun at noon. If a freshly calibrated compass in open air still disagrees with a known direction by a fixed amount, check whether you are comparing a magnetic reading against a true direction. That is the most common explanation by a wide margin.
How wrong can this be?
Accuracy
A calibrated phone in open air is typically good to within about five degrees. Uncalibrated, or near steel, the error can exceed thirty and there is no warning on screen, which is why the check in the last step is worth doing.
Related
Other guides
The basic one
Which way is north?
If you are on a phone, press Start compass and turn until the bearing reads 000. If you are not, and the sun is up, stand with the sun on your right in the morning and you are facing roughly north.
No instrument
Without a compass
Put a stick upright in the ground, mark the tip of its shadow, wait fifteen minutes and mark it again. The line from the first mark to the second points roughly east.
Fixed installation
Aim a solar panel
In the northern hemisphere, face a fixed array due true south, 180 degrees. In the southern hemisphere, due true north, 000. Tilt it at roughly your latitude.