Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Component Documentation

How to Use HMC5883L Triple-axis Magnetometer: Examples, Pinouts, and Specs

Image of HMC5883L Triple-axis Magnetometer
Cirkit Designer LogoDesign with HMC5883L Triple-axis Magnetometer in Cirkit Designer

Introduction

The HMC5883L is a digital magnetometer manufactured by Adafruit (Part ID: 1746). It is designed to measure magnetic fields in three dimensions (X, Y, and Z axes) and is widely used in navigation, orientation, and compass-based applications. This compact and versatile sensor communicates via I2C, making it easy to integrate into microcontroller-based systems such as Arduino and Raspberry Pi.

Explore Projects Built with HMC5883L Triple-axis Magnetometer

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Arduino Uno R3 and HMC5883L Compass Interface
Image of Magnometer: A project utilizing HMC5883L Triple-axis Magnetometer in a practical application
This circuit connects an HMC5883L compass module to an Arduino Uno R3 for the purpose of reading magnetic field data. The Arduino is programmed to initialize the compass module, continuously read its X, Y, and Z magnetometer data, and output the readings to the Serial Monitor. The compass module is interfaced with the Arduino via I2C communication, using the SDA and SCL lines, and powered through the Arduino's VIN pin.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino Mega 2560-Based Multi-Sensor System with Distance, Magnetometer, and Camera Integration
Image of Junior Design - Sensors: A project utilizing HMC5883L Triple-axis Magnetometer in a practical application
This circuit features an Arduino Mega 2560 microcontroller interfaced with multiple VL53L0X distance sensors, an OV7725 camera module, and an Adafruit LIS3MDL triple-axis magnetometer. The Arduino reads data from these sensors and the camera, likely for a robotics or environmental sensing application, and processes the data for further use or transmission.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino Ethernet with LSM303DLHC Accelerometer and Compass Interface
Image of Compass: A project utilizing HMC5883L Triple-axis Magnetometer in a practical application
This circuit connects an Adafruit LSM303DLHC Triple-axis Accelerometer+Magnetometer (Compass) to an Arduino Board Ethernet using I2C communication protocol. The SCL and SDA pins of the sensor are connected to the A5 and A4 pins of the Arduino, respectively, for serial clock and data transfer. The sensor is powered by the Arduino's 5V output, and both devices share a common ground.
Cirkit Designer LogoOpen Project in Cirkit Designer
STM32F4-Based Multi-Sensor GPS Tracking System
Image of Phase 1 fc: A project utilizing HMC5883L Triple-axis Magnetometer in a practical application
This circuit integrates an STM32F4 microcontroller with a GPS module (NEO 6M), an accelerometer and gyroscope (MPU-6050), a barometric pressure sensor (BMP280), and a compass (HMC5883L). The microcontroller communicates with the sensors via I2C and the GPS module via UART, enabling it to gather and process environmental and positional data.
Cirkit Designer LogoOpen Project in Cirkit Designer

Explore Projects Built with HMC5883L Triple-axis Magnetometer

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of Magnometer: A project utilizing HMC5883L Triple-axis Magnetometer in a practical application
Arduino Uno R3 and HMC5883L Compass Interface
This circuit connects an HMC5883L compass module to an Arduino Uno R3 for the purpose of reading magnetic field data. The Arduino is programmed to initialize the compass module, continuously read its X, Y, and Z magnetometer data, and output the readings to the Serial Monitor. The compass module is interfaced with the Arduino via I2C communication, using the SDA and SCL lines, and powered through the Arduino's VIN pin.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of Junior Design - Sensors: A project utilizing HMC5883L Triple-axis Magnetometer in a practical application
Arduino Mega 2560-Based Multi-Sensor System with Distance, Magnetometer, and Camera Integration
This circuit features an Arduino Mega 2560 microcontroller interfaced with multiple VL53L0X distance sensors, an OV7725 camera module, and an Adafruit LIS3MDL triple-axis magnetometer. The Arduino reads data from these sensors and the camera, likely for a robotics or environmental sensing application, and processes the data for further use or transmission.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of Compass: A project utilizing HMC5883L Triple-axis Magnetometer in a practical application
Arduino Ethernet with LSM303DLHC Accelerometer and Compass Interface
This circuit connects an Adafruit LSM303DLHC Triple-axis Accelerometer+Magnetometer (Compass) to an Arduino Board Ethernet using I2C communication protocol. The SCL and SDA pins of the sensor are connected to the A5 and A4 pins of the Arduino, respectively, for serial clock and data transfer. The sensor is powered by the Arduino's 5V output, and both devices share a common ground.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of Phase 1 fc: A project utilizing HMC5883L Triple-axis Magnetometer in a practical application
STM32F4-Based Multi-Sensor GPS Tracking System
This circuit integrates an STM32F4 microcontroller with a GPS module (NEO 6M), an accelerometer and gyroscope (MPU-6050), a barometric pressure sensor (BMP280), and a compass (HMC5883L). The microcontroller communicates with the sensors via I2C and the GPS module via UART, enabling it to gather and process environmental and positional data.
Cirkit Designer LogoOpen Project in Cirkit Designer

Common Applications

  • Electronic compasses
  • GPS navigation systems
  • Robotics and drone orientation
  • Magnetic field detection and mapping
  • Augmented reality devices

Technical Specifications

The HMC5883L is a high-performance magnetometer with the following key specifications:

Parameter Value
Manufacturer Adafruit
Part ID 1746
Operating Voltage 3.0V to 5.0V
Communication Interface I2C
Measurement Range ±1.3 to ±8.1 Gauss
Resolution 12-bit ADC
Output Data Rate 0.75 Hz to 75 Hz
Operating Temperature -40°C to +85°C
Dimensions 14.8mm x 12.0mm x 3.5mm

Pin Configuration and Descriptions

The HMC5883L module typically has 4 pins for interfacing:

Pin Name Description
1 VCC Power supply input (3.0V to 5.0V)
2 GND Ground connection
3 SDA I2C data line
4 SCL I2C clock line

Usage Instructions

Connecting the HMC5883L to an Arduino UNO

To use the HMC5883L with an Arduino UNO, follow these steps:

  1. Connect the VCC pin of the HMC5883L to the 5V pin on the Arduino.
  2. Connect the GND pin of the HMC5883L to the GND pin on the Arduino.
  3. Connect the SDA pin of the HMC5883L to the A4 pin on the Arduino (I2C data line).
  4. Connect the SCL pin of the HMC5883L to the A5 pin on the Arduino (I2C clock line).

Arduino Code Example

Below is an example Arduino sketch to read data from the HMC5883L and display it on the Serial Monitor:

#include <Wire.h>

// HMC5883L I2C address
#define HMC5883L_ADDRESS 0x1E

void setup() {
  Wire.begin(); // Initialize I2C communication
  Serial.begin(9600); // Start serial communication

  // Initialize HMC5883L
  Wire.beginTransmission(HMC5883L_ADDRESS);
  Wire.write(0x00); // Select configuration register A
  Wire.write(0x70); // Set 8-average, 15 Hz default, normal measurement
  Wire.endTransmission();

  Wire.beginTransmission(HMC5883L_ADDRESS);
  Wire.write(0x01); // Select configuration register B
  Wire.write(0xA0); // Set gain to 5
  Wire.endTransmission();

  Wire.beginTransmission(HMC5883L_ADDRESS);
  Wire.write(0x02); // Select mode register
  Wire.write(0x00); // Continuous measurement mode
  Wire.endTransmission();
}

void loop() {
  int16_t x, y, z;

  // Request 6 bytes of data from the HMC5883L
  Wire.beginTransmission(HMC5883L_ADDRESS);
  Wire.write(0x03); // Start reading from data output register
  Wire.endTransmission();
  Wire.requestFrom(HMC5883L_ADDRESS, 6);

  if (Wire.available() == 6) {
    x = (Wire.read() << 8) | Wire.read(); // Combine MSB and LSB for X-axis
    z = (Wire.read() << 8) | Wire.read(); // Combine MSB and LSB for Z-axis
    y = (Wire.read() << 8) | Wire.read(); // Combine MSB and LSB for Y-axis
  }

  // Print the values to the Serial Monitor
  Serial.print("X: ");
  Serial.print(x);
  Serial.print(" Y: ");
  Serial.print(y);
  Serial.print(" Z: ");
  Serial.println(z);

  delay(500); // Wait for 500ms before the next reading
}

Important Considerations

  • Ensure pull-up resistors (typically 4.7kΩ) are connected to the SDA and SCL lines if they are not already present on the module.
  • Avoid placing the sensor near strong magnetic fields or ferromagnetic materials, as they can interfere with measurements.
  • Calibrate the sensor for accurate readings, especially if used in a new environment.

Troubleshooting and FAQs

Common Issues and Solutions

Issue Solution
No data or incorrect readings Check wiring connections and ensure proper I2C address (0x1E).
Sensor not detected by Arduino Verify pull-up resistors on SDA and SCL lines.
Inconsistent or fluctuating measurements Calibrate the sensor and avoid magnetic interference.
Arduino hangs during data reading Ensure proper I2C communication and check for loose connections.

FAQs

Q: Can the HMC5883L operate at 3.3V?
A: Yes, the HMC5883L supports an operating voltage range of 3.0V to 5.0V, making it compatible with both 3.3V and 5V systems.

Q: How do I calibrate the HMC5883L?
A: Calibration involves rotating the sensor in all directions to collect raw data and then applying an offset correction. Libraries like Adafruit's HMC5883L library can simplify this process.

Q: What is the maximum range of the HMC5883L?
A: The sensor can measure magnetic fields up to ±8.1 Gauss, depending on the selected gain setting.

Q: Can I use the HMC5883L for tilt compensation?
A: Yes, but you will need an accelerometer or gyroscope to calculate tilt angles and combine the data for accurate compensation.

By following this documentation, you can effectively integrate and utilize the HMC5883L Triple-axis Magnetometer in your projects.