This is the code for the Arduino-based Improved Personal Compass as described at the site http://DanTheGeek.com . The programs include:
personal_compass.ino - The code for the compass project
magnetometer_sensor.ino - Code for testing the magnetometer. This is also a good tool to test for interference from the servo motor. Just rotate the compass needle on the servo manually while keeping the device still to see if/how much the compass setting varies.
magnetometer_calibrate.ino - Calibrate the magnetometer using this code and copy the values to the personal_compass.ino . When running, move the device in a figure eight pattern, like holding a toy airplane in your hand and flying it like when you were a kid.