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

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

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

Introduction

The Adafruit HMC5883L is a surface-mount, multi-chip module designed for low-field magnetic sensing with a digital interface for applications such as low-cost compassing and magnetometry. The HMC5883L includes our state-of-the-art, high-resolution HMC118X series magneto-resistive sensors plus an ASIC containing amplification, automatic degaussing strap drivers, offset cancellation, and a 12-bit ADC that enables 1° to 2° compass heading accuracy. The I²C serial bus allows for easy interface.

Explore Projects Built with Adafruit 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 Adafruit 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 Ethernet with LSM303DLHC Accelerometer and Compass Interface
Image of Compass: A project utilizing Adafruit 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
Arduino Mega 2560-Based Multi-Sensor System with Distance, Magnetometer, and Camera Integration
Image of Junior Design - Sensors: A project utilizing Adafruit 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 UNO R4 WiFi and Adafruit LIS3DH Accelerometer-Based Motion Detection System
Image of circuit: A project utilizing Adafruit HMC5883L Triple-axis Magnetometer in a practical application
This circuit consists of an Arduino UNO R4 WiFi connected to an Adafruit LIS3DH Triple-Axis Accelerometer via I2C communication. The Arduino reads acceleration data from the LIS3DH sensor and outputs it to the serial monitor for further analysis or processing.
Cirkit Designer LogoOpen Project in Cirkit Designer

Explore Projects Built with Adafruit 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 Adafruit 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 Compass: A project utilizing Adafruit 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 Junior Design - Sensors: A project utilizing Adafruit 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 circuit: A project utilizing Adafruit HMC5883L Triple-axis Magnetometer in a practical application
Arduino UNO R4 WiFi and Adafruit LIS3DH Accelerometer-Based Motion Detection System
This circuit consists of an Arduino UNO R4 WiFi connected to an Adafruit LIS3DH Triple-Axis Accelerometer via I2C communication. The Arduino reads acceleration data from the LIS3DH sensor and outputs it to the serial monitor for further analysis or processing.
Cirkit Designer LogoOpen Project in Cirkit Designer

Common Applications and Use Cases

  • Electronic compasses
  • Navigation systems
  • Position detection
  • Motion sensing and detection
  • Robotics

Technical Specifications

Key Technical Details

  • Power Supply: 2.16V to 3.6V
  • Interface: I²C (up to 400kHz)
  • Operating Temperature: -30°C to +85°C
  • Magnetic Field Resolution: 5 milli-gauss

Pin Configuration and Descriptions

Pin Number Name Description
1 VDD Power supply (2.16V to 3.6V)
2 GND Ground
3 SCL Serial Clock Line for I²C
4 SDA Serial Data Line for I²C
5 DRDY Data Ready (optional use)

Usage Instructions

How to Use the Component in a Circuit

  1. Powering the Device:

    • Connect VDD to a 2.16V to 3.6V power source.
    • Connect GND to the ground of your power supply.
  2. I²C Communication:

    • Connect SCL to the I²C clock line on your microcontroller.
    • Connect SDA to the I²C data line on your microcontroller.
  3. Data Ready Pin (Optional):

    • Connect DRDY to a digital input on your microcontroller if you wish to use the data ready feature.

Important Considerations and Best Practices

  • Ensure that the power supply is within the specified range to prevent damage.
  • Use pull-up resistors on the SCL and SDA lines as required by the I²C protocol.
  • Place the magnetometer away from magnetic sources like motors and speakers.
  • Calibrate the magnetometer for accurate readings in your specific environment.

Example Code for Arduino UNO

#include <Wire.h>
#include <HMC5883L.h>

HMC5883L magnetometer;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  
  // Initialize HMC5883L
  magnetometer.initialize();
  
  // Verify connection
  if (magnetometer.testConnection()) {
    Serial.println("HMC5883L connected");
  } else {
    Serial.println("HMC5883L connection failed");
  }
}

void loop() {
  // Read magnetometer values
  int16_t mx, my, mz;
  magnetometer.getHeading(&mx, &my, &mz);
  
  // Output the results via the serial port
  Serial.print("X: "); Serial.print(mx); 
  Serial.print(" Y: "); Serial.print(my); 
  Serial.print(" Z: "); Serial.println(mz);
  
  delay(500);
}

Troubleshooting and FAQs

Common Issues Users Might Face

  • Inaccurate Readings: Ensure that the magnetometer is calibrated and that there are no nearby magnetic sources affecting the readings.
  • No Data on I²C: Check the connections and ensure pull-up resistors are in place. Also, verify that the correct I²C address is being used.

Solutions and Tips for Troubleshooting

  • Calibration: Perform a calibration routine to account for any magnetic interference in your environment.
  • Connection Issues: Double-check wiring, solder joints, and ensure that the microcontroller's I²C lines are functioning correctly.

FAQs

Q: What is the I²C address of the HMC5883L? A: The default I²C address of the HMC5883L is 0x1E.

Q: Can the HMC5883L be used with a 5V microcontroller? A: Yes, but a level shifter is recommended for the I²C lines to ensure compatibility with the HMC5883L's voltage levels.

Q: How do I know if the HMC5883L is functioning correctly? A: Run the testConnection() method in the setup routine to verify communication with the device. If it returns true, the device is functioning correctly.

Q: How often should I calibrate the magnetometer? A: Calibration should be performed whenever the device is placed in a new environment or if there is a significant change in the surrounding magnetic field.