18 responses to “MAG3110 magnetometer and Arduino”

  1. george

    Hello, can I ask you what process did you follow to find the maximum and minimum offset values?

  2. george

    hello again!yes i did!the problem is that after calibration my sensor should detect the magnetic field of the earth(since i got it in open air environment) but the magnitude of the magnetic field it measures is approximately 20uT and it should be around 45uT!

  3. george

    for example when i apply the calibration code with z vertical to the desk and rotating around z i get x_off = -2517 , y_pff = 1869 z_pff = -270 which is totally different from what you get as offset values and i am a bit confused :S

  4. george

    yes you are right…but after calibration shouldn;t we get the magnetic field of our area!for me it should be around 45uT but the magnitude of the magnetic field sqrt(x^2+y^2+z^2) although is close to being constant,it has a value of 20uT!any tip onwhat could be wrong?i am stuck at it for around a week now and can not find something to fix it!thanx for your time 🙂

  5. Hem Pratap Singh Sisodiya


    Can you please help me in ADXL345 code as well. I have ADXL345 sensor and planning to use MAG3110 sensor with it as it is more cheaper than HMC5883L. But i am at first struggling with ADXL345 to get the correct reading. Also suggest if this combination will work for me. I am using STM32F207VC controller from ST microelectronics.

    Also please suggest me which sensor would be good to go in terms of stability and accuracy out of HMC5883L and MAG3110.
    Awaiting your reply eagerly.

    Best Regards

  6. Hem Pratap Singh Sisodiya

    Thanks a lot for the link.
    Can you please help me in working aof ADXL345 for data flow.
    I am giving a CLOCK out of 16MHz from my controller with prescaler of 32 for SCLK.

    Please help and suggest me or provide the working flow if available.

    Also integration of ADXL345 and MAG3110

    Best Regards

  7. Marcus

    Hello, me and two friends are doing a school project where we want to have a compass on an object. We have a MAG 3110 and an accelerometer and we are able to run your sketch but we aren’t quite sure of what the sketch does. Could you maybe explain it to me? And is it possible to fix the direction to another direction?

    Thank you.

  8. Marcus

    I get an error saying i2cReadRegister was not declared in this scope. I have included the i2c library and all.

  9. Marcus

    Okay, it only prints the heading once and then prints gibberish and then wont work again. Just sometimes. Do you know why?

  10. Ken

    Marcus’ “I get an error saying i2cReadRegister was not declared in this scope. ”
    The line:


    indicates a library and so it looks for the file with the libraries.
    Change it to:

    #include “i2c.h”

    and it should work, at least it did for me.

  11. humza

    how i should give addresses for my i2c interfaced with my magnetometer…

  12. humza

    Actually i am making the project of pipeline inspection guage for which I had to use MAG3110,HMC5883L using arduino mega 2560….I am unable to acquire the data from each of them individually.I need to know the procedure for acquiring the data from these sensors using the concept of i2c pins.

Leave a Reply