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

How to Use HMC5883L compass: Examples, Pinouts, and Specs

Image of HMC5883L compass
Cirkit Designer LogoDesign with HMC5883L compass in Cirkit Designer

Introduction

The HMC5883L is a digital compass module equipped with a three-axis magnetometer that measures magnetic fields. It is capable of providing precise heading information, making it an essential component for navigation, orientation, and motion-tracking applications. The module communicates via the I2C protocol, making it easy to interface with microcontrollers like Arduino, Raspberry Pi, and others.

Explore Projects Built with HMC5883L compass

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 compass 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
Raspberry Pi Pico-Based Bluetooth Compass
Image of sat_dish: compass-intro: A project utilizing HMC5883L compass in a practical application
This circuit features a Raspberry Pi Pico microcontroller interfaced with an HC-05 Bluetooth module and an HMC5883L digital compass. The Pico's GPIO pins are configured for serial communication with the HC-05 (TX/RX) and I2C communication with the HMC5883L (SCL/SDA). The circuit is likely designed for wireless data transmission of compass readings.
Cirkit Designer LogoOpen Project in Cirkit Designer
Raspberry Pi Pico-Based Navigation Assistant with Bluetooth and GPS
Image of sat_dish: compass example: A project utilizing HMC5883L compass in a practical application
This circuit features a Raspberry Pi Pico microcontroller interfaced with an HC-05 Bluetooth module for wireless communication, an HMC5883L compass module for magnetic field measurement, and a GPS NEO 6M module for location tracking. The Pico is configured to communicate with the HC-05 via serial connection (TX/RX), with the compass module via I2C (SCL/SDA), and with the GPS module via serial (TX/RX). Common power (VCC) and ground (GND) lines are shared among all modules, indicating a unified power system.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino Nano-Based Portable GSM-GPS Navigator with Compass and Stepper Motor Control
Image of Compass: A project utilizing HMC5883L compass in a practical application
This circuit features an Arduino Nano microcontroller coordinating communication, navigation, and motion control functions. It includes modules for GSM, GPS, and digital compass capabilities, as well as a stepper motor for precise movement, all powered by a LiPo battery with voltage regulation.
Cirkit Designer LogoOpen Project in Cirkit Designer

Explore Projects Built with HMC5883L compass

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 compass 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 sat_dish: compass-intro: A project utilizing HMC5883L compass in a practical application
Raspberry Pi Pico-Based Bluetooth Compass
This circuit features a Raspberry Pi Pico microcontroller interfaced with an HC-05 Bluetooth module and an HMC5883L digital compass. The Pico's GPIO pins are configured for serial communication with the HC-05 (TX/RX) and I2C communication with the HMC5883L (SCL/SDA). The circuit is likely designed for wireless data transmission of compass readings.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of sat_dish: compass example: A project utilizing HMC5883L compass in a practical application
Raspberry Pi Pico-Based Navigation Assistant with Bluetooth and GPS
This circuit features a Raspberry Pi Pico microcontroller interfaced with an HC-05 Bluetooth module for wireless communication, an HMC5883L compass module for magnetic field measurement, and a GPS NEO 6M module for location tracking. The Pico is configured to communicate with the HC-05 via serial connection (TX/RX), with the compass module via I2C (SCL/SDA), and with the GPS module via serial (TX/RX). Common power (VCC) and ground (GND) lines are shared among all modules, indicating a unified power system.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of Compass: A project utilizing HMC5883L compass in a practical application
Arduino Nano-Based Portable GSM-GPS Navigator with Compass and Stepper Motor Control
This circuit features an Arduino Nano microcontroller coordinating communication, navigation, and motion control functions. It includes modules for GSM, GPS, and digital compass capabilities, as well as a stepper motor for precise movement, all powered by a LiPo battery with voltage regulation.
Cirkit Designer LogoOpen Project in Cirkit Designer

Common Applications

  • Navigation systems (e.g., robotic vehicles, drones)
  • Orientation detection in wearable devices
  • Motion tracking in augmented reality (AR) and virtual reality (VR) systems
  • Geomagnetic field mapping
  • Electronic compasses for outdoor activities

Technical Specifications

The HMC5883L module is designed for low-power, high-accuracy magnetic field sensing. Below are its key technical details:

Parameter Value
Operating Voltage 3.0V to 5.0V
Operating Current 100 µA (typical)
Communication Interface I2C (7-bit address: 0x1E)
Measurement Range ±1.3 to ±8 Gauss
Resolution 12-bit ADC
Output Data Rate (ODR) 0.75 Hz to 75 Hz
Operating Temperature -40°C to +85°C
Dimensions 14mm x 13mm x 3.5mm

Pin Configuration

The HMC5883L module typically has four pins for interfacing. Below is the pinout description:

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 module's VCC pin to the Arduino's 5V pin.
  2. Connect the GND pin to the Arduino's GND.
  3. Connect the SDA pin to the Arduino's A4 pin (I2C data line).
  4. Connect the SCL pin to the Arduino's A5 pin (I2C clock line).

Sample Arduino Code

Below is an example Arduino sketch to read data from the HMC5883L and display the heading 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(0x20); // Set gain to 1.3 Gauss
  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
  }

  // Calculate heading in degrees
  float heading = atan2(y, x) * 180 / PI;
  if (heading < 0) {
    heading += 360; // Ensure heading is positive
  }

  // Print heading to Serial Monitor
  Serial.print("Heading: ");
  Serial.print(heading);
  Serial.println("°");

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

Important Considerations

  • Calibration: The HMC5883L requires calibration to account for hard and soft iron distortions. This can be done by rotating the module in all directions and applying correction algorithms.
  • Magnetic Interference: Avoid placing the module near ferromagnetic materials or electronic components that generate strong magnetic fields.
  • Power Supply: Ensure a stable power supply to avoid noise in the readings.

Troubleshooting and FAQs

Common Issues

  1. No Data or Incorrect Readings

    • Cause: Incorrect wiring or I2C address mismatch.
    • Solution: Double-check the connections and ensure the I2C address is set to 0x1E.
  2. Fluctuating or Unstable Readings

    • Cause: Magnetic interference or insufficient power supply.
    • Solution: Move the module away from magnetic sources and ensure a stable power supply.
  3. Heading Stuck at a Fixed Value

    • Cause: Module not initialized properly.
    • Solution: Verify the initialization code and ensure the module is in continuous measurement mode.

FAQs

Q: Can the HMC5883L measure altitude?
A: No, the HMC5883L is a magnetometer and only measures magnetic fields. For altitude, you would need a barometric pressure sensor.

Q: How do I calibrate the HMC5883L?
A: Calibration involves collecting raw data while rotating the module in all directions and applying offset and scaling corrections. Libraries like Adafruit's HMC5883L library include calibration functions.

Q: Can I use the HMC5883L with a 3.3V microcontroller?
A: Yes, the HMC5883L supports a voltage range of 3.0V to 5.0V, making it compatible with 3.3V systems.

By following this documentation, you can effectively integrate the HMC5883L into your projects for accurate navigation and orientation sensing.