

The HMC5843 is a three-axis digital magnetometer designed to measure magnetic fields with high precision. It is widely used in applications such as navigation systems, robotics, and electronic compasses. The device provides digital output data via I2C or SPI interfaces, making it easy to integrate into a variety of microcontroller-based systems. Its compact size and low power consumption make it ideal for portable and embedded applications.








The following table outlines the key technical details of the HMC5843:
| Parameter | Value |
|---|---|
| Operating Voltage | 2.5V to 3.3V |
| Interface | I2C (400 kHz) / SPI |
| Measurement Range | ±4 gauss |
| Resolution | 12-bit |
| Output Data Rate (ODR) | 0.5 Hz to 160 Hz |
| Operating Temperature | -40°C to +85°C |
| Power Consumption | 100 µA (typical) |
| Package | 16-pin LCC |
The HMC5843 is available in a 16-pin LCC package. The pin configuration and descriptions are as follows:
| Pin Number | Pin Name | Description |
|---|---|---|
| 1 | VDD | Power supply (2.5V to 3.3V) |
| 2 | GND | Ground |
| 3 | SCL | I2C clock input |
| 4 | SDA | I2C data input/output |
| 5 | DRDY | Data ready output (active high) |
| 6 | CS | Chip select for SPI (active low) |
| 7 | MOSI | SPI master-out/slave-in data line |
| 8 | MISO | SPI master-in/slave-out data line |
| 9 | SCLK | SPI clock input |
| 10-16 | NC | Not connected |
Below is an example of how to interface the HMC5843 with an Arduino UNO using the I2C protocol:
#include <Wire.h> // Include the Wire library for I2C communication
#define HMC5843_ADDRESS 0x1E // I2C address of the HMC5843
void setup() {
Wire.begin(); // Initialize I2C communication
Serial.begin(9600); // Start serial communication for debugging
// Configure the HMC5843
Wire.beginTransmission(HMC5843_ADDRESS);
Wire.write(0x00); // Select configuration register A
Wire.write(0x70); // Set measurement mode to normal and data rate to 15 Hz
Wire.endTransmission();
Wire.beginTransmission(HMC5843_ADDRESS);
Wire.write(0x01); // Select configuration register B
Wire.write(0xA0); // Set gain to ±1.3 Gauss
Wire.endTransmission();
Wire.beginTransmission(HMC5843_ADDRESS);
Wire.write(0x02); // Select mode register
Wire.write(0x00); // Set continuous measurement mode
Wire.endTransmission();
}
void loop() {
int16_t x, y, z;
// Request 6 bytes of data from the HMC5843
Wire.beginTransmission(HMC5843_ADDRESS);
Wire.write(0x03); // Set pointer to data output X MSB register
Wire.endTransmission();
Wire.requestFrom(HMC5843_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 magnetic field values
Serial.print("X: ");
Serial.print(x);
Serial.print(" Y: ");
Serial.print(y);
Serial.print(" Z: ");
Serial.println(z);
delay(100); // Delay for 100 ms
}
No Data Output:
Inaccurate Measurements:
Communication Errors:
Q: Can the HMC5843 operate at 5V?
A: No, the HMC5843 operates within a voltage range of 2.5V to 3.3V. Using 5V may damage the device.
Q: How do I switch between I2C and SPI modes?
A: The HMC5843 automatically detects the communication protocol based on the connections. Ensure only one protocol is connected at a time.
Q: What is the maximum measurement range of the HMC5843?
A: The HMC5843 can measure magnetic fields within a range of ±4 gauss.
Q: Do I need to calibrate the sensor?
A: Yes, calibration is recommended to achieve accurate measurements, especially in environments with magnetic distortions.