Honeywell HMC5883L compass sensor for autonomous robot

One big part of my ‘relaxation’ project – ‘building’ an autonomous maze solving car is the sensors.

Installation of the four ultrasonic sensor and experimental avoidance code has shown (again) just how bad I am at visualising in 2 & 3D space. My simple avoidance logic attempts always end up avoiding big objects, but then get stuck in a tight loop “go forward” – “avoid = go back” – “go forward”.

So I thought it was time to add the Honeywell HMC5883L compass sensor (part of Christmas present to self). The sample code ran up easily (once converted all the wire-I2C commands to Arduino v1.0), so I ported the code into my code. Weeks later after umpteen different project sidetracks I noticed that the output from the compass was not linear and very different if you rotated clockwise or anticlockwise!

After lots of web searching and help from others with this sensor, I have now started to get more sensible output. While this work is not fully complete, it is a big improvement over the standard sample code that is commonly found, so I thought I better start publishing before I loose momentum on this.

Details are on the wiki, and I also updated the SeeedStudio site sample code on their wiki. The main point to note is that it takes some effort to calibrate, but hopefully the sample code provided helps simplify the tasks.