Overview

The HMC5883L is a 3-axis digital magnetometer IC manufactured by Honeywell. It uses Anisotropic Magnetoresistive (AMR) technology to measure both the direction and magnitude of Earth's magnetic fields (typically 0.3 to 0.6 Gauss0.3\text{ to }0.6\text{ Gauss}) for electronic compass navigation in robotics, drones, and mobile devices.

Breakout boards (GY-271) include 3.3V power regulation and I2C level shifting. Note that most low-cost modules sold today contain the pin-compatible replacement chip QMC5883L by QST Corporation, which uses different I2C register addresses.

Quick reference

Module VCC3.3 V to 5.0 V DC (onboard LDO)
Chip VDD / VDDIO2.16 V to 3.6 V DC
Field range±0.88 Gauss\pm 0.88\text{ Gauss} to ±8.1 Gauss\pm 8.1\text{ Gauss} (default ±1.3 Gauss\pm 1.3\text{ Gauss})
ADC resolution12-bit (5 milligauss field resolution)
Output data rate0.75 Hz to 75 Hz (up to 160 Hz in continuous mode)
Communication interfaceI2C (fixed address 0x1E for HMC5883L / 0x0D for QMC5883L)
Heading accuracy1° to 2° (with proper hard/soft iron calibration)

Pinout

Standard GY-271 5-Pin Breakout Header

PinNameTypeDescription
1VCCPowerSupply voltage (+3.3 V to +5.0 V DC)
2GNDPowerGround (0 V)
3SCLDigital InputI2C Serial Clock input
4SDADigital I/OI2C Serial Data line
5DRDYDigital OutputData Ready interrupt pin (Active-HIGH)

Specifications

ParameterSymbolMinTypMaxUnitConditions
Supply VoltageVDDV_{DD}2.163.03.6VDC
Operating CurrentIDDI_{DD}100180µAContinuous measurement mode
Idle CurrentIidleI_{idle}25µAIdle mode
Magnetic Field RangeBB±0.88\pm 0.88±1.3\pm 1.3±8.1\pm 8.1GaussUser selectable via Gain bits
Gain SensitivitySgainS_{gain}23010901370LSB/Gauss1090 LSB/Gauss at ±1.3 G1090\text{ LSB/Gauss at } \pm 1.3\text{ G}
Linearity ErrorNLNL0.1% FSFull scale
Operating Temp RangeTOPT_{OP}-3085°C

Register map (HMC5883L)

AddressRegisterAccessResetDescription
0x00CRAR/W0x10Configuration Register A (Samples averaged, Output rate, Measurement mode)
0x01CRBR/W0x20Configuration Register B (Gain configuration)
0x02MODER/W0x03Mode Register (0x00 = Continuous-measurement, 0x01 = Single-measurement)
0x030x08DATAX_H..DATAZ_LRData Output Registers (Order: X-MSB, X-LSB, Z-MSB, Z-LSB, Y-MSB, Y-LSB)
0x0AIRAR0x48Identification Register A (returns 'H')
Note

HMC5883L Axis Read Order: Notice that the register read order for HMC5883L is X, Z, Y (not X, Y, Z!). Register 0x030x04 is X, 0x050x06 is Z, and 0x070x08 is Y.

HMC5883L vs QMC5883L Differentiation

FeatureHMC5883L (Honeywell)QMC5883L (QST Corp)
I2C Slave Address0x1E0x0D
ID Register (0x0A / 0x0D)Returns 'H' (0x48)Returns 0xFF / 0x00
Control Register0x02 Mode Reg (0x00 = Continuous)0x09 Control Reg 1 (0x1D = Continuous)
Data Register OrderX_MSB, X_LSB, Z_MSB, Z_LSB, Y_MSB, Y_LSBX_LSB, X_MSB, Y_LSB, Y_MSB, Z_LSB, Z_MSB

Wiring

GY-271 Module PinMicrocontroller (Arduino Uno / ESP32)
VCC3.3V (or 5V)
GNDGND
SCLSCL (A5 on Uno, GPIO22 on ESP32)
SDASDA (A4 on Uno, GPIO21 on ESP32)

Common mistakes

  • Using HMC5883L software library for QMC5883L clones: Most modern GY-271 breakout boards ship with QMC5883L ICs. Running an HMC5883L library on a QMC5883L chip will fail with I2C device not found at 0x1E. Run an I2C scanner script to check for 0x1E vs 0x0D.
  • Misinterpreting X, Z, Y register order on HMC5883L: Reading bytes in X, Y, Z order results in swapping the Y and Z values.
  • Ignoring Hard-Iron / Soft-Iron distortion: Nearby metal components, battery wires, or motors cause severe distortion. Calibration is required to map raw X/Y readings to a centered circle before calculating heading (Heading=atan2(Y,X)\text{Heading} = \text{atan2}(Y, X)).

Notes

  • Magnetic Declination angle must be added to the calculated magnetic heading to yield True North heading.

Assets & downloads