Arduino HMC5883L Magnetometer interfacing

arduino magnetic compass


Do you need to Identify the Magnetic North for your project and confused what to do? and how to select magneto meter sensor? Here this article helps you take note.

This project uses HMC5883L triple axis magnetometer from Honeywell, it is a surface mount (Better to buy as breakout board) multi-chip module designed for low-field magnetic sensing with a digital interface for applications such as low-cost compassing and magnetometry.

It utilize I²C (inter integrated circuit) interface technique to communicate with Microcontrollers and consumes 2.16-3.6VDC at low current draw and it gives 5 milli-guass resolution.

Breakout Board

10530-03  hmc5883l pcb





Arduino Hookup

arduino hmc5883l hookup

Connect the Vcc of breakout board to Arduino’s 3.3V power source and Gnd to Gnd of Arduino. Connect SDA (serial data line) to A4 and SCL (serial clock line) to A5 of Arduino, that’s all the hookup is over. Now turning to Arduino code before that get HMC5883L Library here. There you can find from simple example to read sensor data serially to Graphical Magnetic compass using processing code.

Arduino Code

Simple Example to Read HMC5883L Sensor


#include <Wire.h> //I2C Arduino Library

#define address 0x1E //0011110b, I2C 7bit address of HMC5883

void setup(){
  //Initialize Serial and I2C communications
  //Put the HMC5883 IC into the correct operating mode
  Wire.beginTransmission(address); //open communication with HMC5883
  Wire.send(0x02); //select mode register
  Wire.send(0x00); //continuous measurement mode
  void loop(){
  int x,y,z; //triple axis data

  //Tell the HMC5883L where to begin reading data
  Wire.send(0x03); //select register 3, X MSB register
 //Read data from each axis, 2 registers per axis
  Wire.requestFrom(address, 6);
    x = Wire.receive()<<8; //X msb
    x |= Wire.receive(); //X lsb
    z = Wire.receive()<<8; //Z msb
    z |= Wire.receive(); //Z lsb
    y = Wire.receive()<<8; //Y msb
    y |= Wire.receive(); //Y lsb
  //Print out values of each axis
  Serial.print("x: ");
  Serial.print("  y: ");
  Serial.print("  z: ");

Serial Port Data Sample

serial print magnetometer



HMC5883L Arduino Library

pdf-icon HMC5883L-FDS Datasheet

2 thoughts on “Arduino HMC5883L Magnetometer interfacing

  1. hi , thank you for sharing , it is very good , now , how to run a fluxgate magnometer sensor ( fg3 or flc100 or ems100) with ardunio and send data to pc ? thank you

Leave a Reply

Your email address will not be published. Required fields are marked *