New 3-Axis MagnetoMeter Available (HMC5843)

Yes you got me, i love to make boards. ;-)The new magnetometer is pretty flexible, it will let you (through a solder jumper) select 5V or 3.3V mode, it has a 3.3V voltage regulator and an I2C translator (translate the I2C signals to 3.3V to void damage to the unit), so you are free to use it with any microcontroller (normally you don't suppose to connect it to a micro-controller that uses 5V signals). In other words is the smallest, cheapest, 5V and 3.3V, 3-axis magnetometer on the market (yet).

Another feature is that you can remove the screw holes sides in order to keep the minimum size. If you don't care about the size but you care about holding it very well then just leave as is. My recommendation for ArduIMU+ and other projects is to place it as far as you can from the any magnetic interference, you can solder a long wire all way down to the magneto board, don't worry about the noise because the i2c protocol is digital (not analog) and also the "I2C translator" acts like as a signal booster. Do you want more?

For ArduIMU+ and future ArduPilotMega Shield owners the magneto board will be pin compatible, so you can just place it on top (as the upper picture indicates), without compromising the low profile of the board:

All this for just $49.90, the same price as the SparkFun board but with more feactures. Also it works under any circumstances, thanks to its bigger tantalum capacitor (33uF).You can get yours here: you mix it with the ArduIMU+ it will cost $25 more than the 9DoF Razor board, but just remember that ArduIMU+ runs at 16MHz, has GPS port and you can easily place the magnetometer away from the board in case you have noisy magnetic fields close to that board that normally don't affect the accelerometers and the gyros, also the 9DoF board has I2C accelerometer that i doubt is better than the analog one we have.The advantages of 9DoF Razor is that you have Lithium Battery port, ON&OFF switch, fixed mounting holes, is $25 cheaper and soon will support our DCM code. So is up to you! ;-)Thanks for all your support!
E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones


  • I recently got the magnetometer for my ArduIMU+ based Quadrocopter. Nice! I got it to work with the original ArduIMU code, but need to tweak my quad firmware some more to get it right.

    But I was hesitant to solder it on top of the board directly, as outlined in this blog post. Instead I used pin header connectors, so I could easily swap/replace it (e.g. with a pressure sensor or a generic I2C bus extension to connect both):

    Quadrocopter: ArduIMU+ (V2) flat with HMC5843 triple axis magnetometer

    Now my question - how sensible is the compass to vibrations? Sitting on top of a pin header connector like this, I suspect it will vibrate some more as if it's soldered to the board directly. I'm curious about your thoughts about this type of connection. What other alternative can you suggest, if I want to maintain access to the I2C bus for potentially connecting other devices? Thanks!

  • I will buy it for yaw corecction for arduIMU+ v2 so after I will connect them can you send the cod for yaw correction (my project is indoor and for motion capture graphics)
  • Jordi,


    I am not very clear on how to go about changing the jumper from 3.3v to 5v so additional guidance would be appreciated. Is it just a simple operation of de-soldering the current blob on the right side of the jumper and putting more solder on the left hand side of the magneto board or should I be aware of other considerations that are not obvious? Is there a way to check whether the board is now 5v as opposed to a 3.3v version after the jumper change?





  • Would it be possible to get a PCB schematic for this breakout board...or the eagle file??
  • Sorry for the extra post, but the forum format from arduino didn't work out in the post, so here it is without all of those tags.

    magnetom_x = ((((int)buff[0]) << 8) | buff[1]); // x axis
    magnetom_y = ((((int)buff[2]) << 8) | buff[3]); // y axis

    MAG_Heading = atan2(-magnetom_y,magnetom_x);

    MAG_Heading = MAG_Heading/ PI * 180;

    MAG_Heading = MAG_Heading *10;
    Heading = (int) MAG_Heading;

    cmd_buf[6] = Heading>>8 & 0x07;
    cmd_buf[7] = Heading & 0xff;
    cmd_buf[8] = Heading>>15 & 0x01;
  • Hi Guys,

    I just started working with the 3 axis accelerometer. I'm using the compass.pde from the arduIMU repository to interface with the device and that is working great. However I'm having an odd problem on one side of the output range.

    for the positive values the heading goes from 0 to 180 as it should, because atan2 can only put out -PI to PI ( a conversion to degrees is being done). However for the negative values i'm getting a range from -205 to -25, which means somewhere -25 is being added in. Has anyone had a similar experience that may be caused by hardware?

    Here is the code that I've been using.

        magnetom_x = (((([color=#CC6600]int[/color])buff[0]) << 8) | buff[1]); [color=#7E7E7E]// x axis[/color]
        magnetom_y = (((([color=#CC6600]int[/color])buff[2]) << 8) | buff[3]); [color=#7E7E7E]// y axis[/color]

      MAG_Heading = [color=#CC6600]atan2[/color](-magnetom_y,magnetom_x);

      MAG_Heading = MAG_Heading/ [color=#006699]PI[/color] * 180;

      MAG_Heading =  MAG_Heading *10; 
      Heading = ([color=#CC6600]int[/color]) MAG_Heading;

    cmd_buf[6] = Heading>>8 & 0x07;
    cmd_buf[7] = Heading & 0xff;
    cmd_buf[8] = Heading>>15 & 0x01;


    For right now i'm just adding 25, but I don't feel like that's an adequate solution. Is this what Bill means when he refers to offsets?

  • Hello, I need two library hmc.cpp and hmc.h. Thank you.
  • Jordi -

    You probably already know this, but the issue with the HMC5843 capacitors is ESR, not size. We use the HMC5843 on the SRV-NAV board, and figured out early on that certain capacitors worked while others didn't, but it depended on the manufacturer, not the capacitor size.

    By the way, we have very good results with HMC5843, even indoors as well as in close proximity to very large motors. Performance is a lot better than I would have expected.
  • Scott,

    I think Jordi had already commented on this... the thing is you want the magnetometer as far away from the electronics as you can because of the possible interference in the readings they may cause...

    Anyway... great job Jordi, I just tested my code to interface with the HMC5843... it works really good. Awesome design in a very tiny footprint!
  • Well I can only expand on what others have said....well done Jordi, and elegant solution as always, and sooo tiny. Out of curiosity, are we ever going to see an IMU+ version with this on the board? Now that there are a couple 3-axis single chip gyros, when paired with this HMC5843 and a 3-axis accelerometer, you could have a "9dof" flat shield in the same footprint it currently has...just curious if the though had crossed your mind? (I know...we're never satisfied are
This reply was deleted.