Skip to content

Interfacing HMC5883L / QMC5883 Digital compass with Arduino


Hi, and welcome,

Before I start, I want to mention an important thing: I recently bought an Arduino module which is HMC5883L (GY-273) I tried it with its library but unfortunatley it doesn’t work, after some research on the internet I found out that they are actually QMC5883 modules.

How to know it’s a real HMC5883L:

  • If you try after wiring it with arduino with i2c scanner you gonna find that the address is “0x1E
  • Or if you look on the chip itself it’s marked L883

How to know it’s a fake one:

  • If you try after wiring it with arduino with i2c scanner you gonna find that the address is “0x0D” as i found out or something else
  • Or if you look on the chip itself it’s marked DA5883

A picture I took from :


But actually it’s not a fake but it’s the QMC5883 which is a similar module but cheaper and not stable, and in this post I’m using one of them.

So the HMC5883L or QMC5883 are called digital compass, they are detecting the magnetic north and calculate the value comparing to it while moving, and they are very sensitive, but the cheap version which is QM5883 is more sensitive and difficult to calibrate.

While sensing the magnetic north the module can know in which direction its moving and comparing to which axis, this module has 3 axis (x, y and z) gives you three values and they change while moving, and they can be positive or negative depending on the orientation of your module, similar to the gyro that I interface it before: Interfacing L3G4200 triple axis gyro module with Arduino, but here we are detecting translating and movement, not tilting.


to not be confused I let the HMC5883L module in the wiring because the “fake” one is marked like the real one

HMC5883L Wired with Arduino UNO



The library I used is a QMC5883 library: Download library here


For i2c scan:

i2c Scanner:  Download here (it’s a separate code that uses “wire.h” library that you already have and it detects i2c devices addresses)

For using the module:

Since the code I used is just an example of the library all you have to do after installing the library is to go to examples

(MechaQMC5883lmaster -> example -> raw)

Yassine View All

Automation and Electrical Engineer, Electronics amateur trying to share my little projects.

23 thoughts on “Interfacing HMC5883L / QMC5883 Digital compass with Arduino Leave a comment

  1. Did you get it to work? You mentioned difficult calibration but what did you do with respect to calibration?

    • Hello, the main problem solved here is the issue of interfacing it with the Arduino board, for calibration you can fix your own reference then add some math operations to make it like 0,0,0 and the values will change proportionally to this reference

  2. Thank you for the video and information. I also had the same problem. I thought I damaged by board, but then found this info and realized they sent me the module with the fake chip. I complained and got a refund.

  3. I would love to make a puppet head that mimics man head in 3axis .Using 3 servos that puppet moves its head same as the master person moves his head. Where the 3 axis sensor is put on the person head and sends the signal through RF or bluetooth to a recever arduino that controls 3 servo of puppet head. Can anyone please heal with this code ?

    • Hello, it depends on what movements are you trying to mimic, don’t forget there are 3 translations and 3 rotations, this module only picks up the translating ones, if you’re willing to detect the head tilt and node you’ll need a gyro module like “L3G4200”, or the six of them by using “MPU-6050”.
      Sorry I still haven’t tried them for projects but I recommend you to check some “Gesture controlled cars” projects.

  4. Olá estou tentando fazer um sensor de movimento com o módulo GY-85, só que também recebi o falso que é este qmc 5883 no lugar do hmc 5883 como proceder na configuração.
    Pode me ajudar? ?

  5. I tried everything, i even tried with 2 new modules, all of which were qmc5883L, but still i am getting constant values, and the output is not at all changing ! Please do help me, im stuck in middle of a project.

  6. Yassien, Thanks! You are my hero for the day. You and I2C scanner fixed it for me. After downloading the QMC library, and code, my project works. It took two days to discover that I had purchased 2 fakes. While the fake board/chips work as a magnetometer the time spent on $1.50 chip was wasted – except for the learning. In review of the QMC library, I think the HMC and QMC use different registers and have different addresses.

  7. Although an old thread, but for general future reference…

    I drove the QMC5883 magnetometer with a humble dsPIC for a professional project and have found it to be very stable The device was used to differentiate physical position with 1mm tolerance referenced to a small magnet (avoiding saturation). The issue is that the HMC… features a 12-bit ADC, whereas the QMC… has 16-bit, requiring noise to be filtered out in the program flow.

    Using simple moving averages (SMA-8) and (SMA-1024), continuously polling updates at 200Hz (400kHz I2C), and bit-shifting all post-averaged readings by >>4 for compares, I can confirm that all readings were rock-stable with no perceptible drift or jumps.

    The QMC… is a perfectly good chip – Just needs to be processed accordingly.

  8. how did you calibrate your hmc5883L, I bought the good one yesterday and I want to learn it for my thesis project :(. can you give the complete source code for the calibration? the example one in the lib you shared is not working properly in my hmc5883l.

Leave a Reply

%d bloggers like this: