You might have noticed the sometimes the compass on Physics Toolbox apps require calibration (or any app that uses a compass, for that matter). Although we now include a special notice for users when we anticipate it needs to be calibrated with instructions on how to do so, few resources are available that explain exactly how this works. What this comes down to is the fact that most mobile devices use the three-dimensional magnetic field detector. Some other apps will use GPS, not the magnetometer to display their compass, but these compasses only work accurately on a large-scale, and do not respond to magnets at all.
Whenever a smartphone is exposed to a strong magnet, such as computer speakers, the magnetometer is affected, and the compass might give erroneous or variable directions when used to measure the Earth's weaker magnetic field. To re-calibrate the compass, users are often instructed to move the device in a "figure eight" along all three dimensions of motion.
The video below describes the optimal approach for doing this:
Why does this motion work? The explanation for how this re-calibration takes place is not well-defined in any popular online venue, and it takes place at the level of the sensor, not within the app algorithm. Moving the mobile device in all three dimensions re-sets the magnetometer using the Earth's magnetic field. It is interesting to consider the purpose of the "motion" in the re-setting. Is the motion essential for inductive effects, as some have suggested (moving a closed loop through the presence of a changing magnetic field, causing a flow of electricity), or simply for exposing the sensor to a wide range of magnetic field strengths?
I vaguely recall an undergraduate physics problem in which we considered the size and speed of spinning loops of wire to get "free energy" from the Earth's magnetic field. The result suggested that such an attempt would be futile. Additionally, magnetometers typically work via the Hall effect or the magneto-resistive effect, neither of which require the presence of a changing magnetic field. Otherwise, only changing - not static - magnetic fields could be sensed by the sensor. It is unlikely that a different principle governs re-calibration of the sensor than the principle on which the sensor operates itself.
The best explanation I can find for the figure-8 calibration is in the Electrical Engineering Stack Exchange. In brief, the total magnetic field of the Earth is essentially constant, and it doesn't even matter how the phone is oriented. Allowing the mobile device to rotate into all three dimensions allows the phone to ensure that along multiple angles of rotation that the recorded magnetic field total is the same; if it is not the same, then it appropriately adjusts the values. The above link provides a very nice set of visuals for those who understand vector sums.
Users might be surprised to find, however, that even calibration might not provide exceptional accuracy for direction -- especially depending upon the user's location on the Earth. The reason behind this is far more astronomical in nature and has to do with the make-up and age of the Earth. The poles on which the Earth rotates are not equivalent to the locations of the magnetic poles, and these magnetic poles have shifted in location, strength, and direction throughout history. While most users outside of the arctic or subarctic circles probably won't pay much heed to differences in geographic locations and the directions pointed by the compass, a user in mid-Greenland might find that their "north-seeking" compass arrow points decidedly to the West!