GY-271 HMC5883L Triple Axis Magnetometer Sensor Module
GY-271 HMC5883L Triple Axis Magnetometer
High-Sensitivity Digital Compass Module for Arduino Projects
Introduction
The GY-271 HMC5883L is a 3-axis digital compass module featuring the Honeywell HMC5883L magnetometer IC. With 1° to 2° heading accuracy and a resolution up to 5 milli-gauss, it’s ideal for navigation systems, robotics, and orientation detection applications.

Key Features
Triple Axis
Measures X, Y, Z magnetic fields simultaneously
High Sensitivity
1-2 milli-gauss resolution (up to 8 Gauss range)
Low Power
100μA operation current (0.5μA standby)
I2C Interface
Standard digital output (3.3V or 5V compatible)
Technical Specifications
| Measurement Range | ±1.3 to ±8.1 Gauss (selectable) |
|---|---|
| Resolution | 0.73 to 4.35 milli-gauss (depending on range) |
| Update Rate | Up to 160Hz |
| Supply Voltage | 2.16V to 3.6V (5V tolerant I/O) |
| I2C Address | 0x1E (fixed) |
| Accuracy | 1°-2° heading (typical) |
Pin Configuration

| Pin | Label | Description | Arduino Connection |
|---|---|---|---|
| 1 | VCC | Power (3.3V recommended) | 3.3V |
| 2 | GND | Ground | GND |
| 3 | SCL | I2C Clock | A5 (Uno) or SCL |
| 4 | SDA | I2C Data | A4 (Uno) or SDA |
| 5 | DRDY | Data Ready (Optional) | Any digital pin |
Important: Requires 3.3V power (use voltage regulator if needed)
Wiring Diagram (Arduino Uno)
// Basic Connections: // VCC → 3.3V (use regulator if needed) // GND → GND // SCL → A5 (or SCL) // SDA → A4 (or SDA) // DRDY → (optional interrupt pin)
Basic Compass Example
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_HMC5883_U.h>
Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345);
void setup() {
Serial.begin(9600);
if(!mag.begin()) {
Serial.println("Could not find HMC5883L");
while(1);
}
}
void loop() {
sensors_event_t event;
mag.getEvent(&event);
float heading = atan2(event.magnetic.y, event.magnetic.x);
float declinationAngle = 0.22; // Adjust for your location
heading += declinationAngle;
// Correct for when signs are reversed
if(heading < 0) heading += 2*PI; if(heading > 2*PI) heading -= 2*PI;
float headingDegrees = heading * 180/M_PI;
Serial.print("Heading: ");
Serial.print(headingDegrees);
Serial.println("°");
delay(500);
}
Library Required: Install “Adafruit HMC5883 Unified” via Arduino Library Manager
Advanced Configuration
Measurement Range
// Set measurement range (default ±1.3 Ga)
mag.setRange(HMC5883_RANGE_1_3GA);
// Other options: 1.9GA, 2.5GA, 4.0GA, 4.7GA, 5.6GA, 8.1GA
Data Rate
// Set output data rate (default 15Hz)
mag.setDataRate(HMC5883_DATARATE_15HZ);
// Other options: 0.75, 1.5, 3, 7.5, 30, 75, 220Hz
Measurement Mode
// Set continuous measurement mode
mag.setMeasurementMode(HMC5883_CONTINUOUS);
// Other options: SINGLE (power saving), IDLE
Calibration
// Hard iron calibration offsets
mag.setOffset(-10.35, 58.95, -40.59);
// Obtain values from calibration routine
Troubleshooting
No Device Detected
- Verify I2C connections (SDA/SCL)
- Check with I2C scanner sketch
- Confirm 3.3V power supply
Incorrect Readings
- Keep away from magnetic sources (motors, speakers)
- Perform hard/soft iron calibration
- Set proper declination for your location
Erratic Values
- Add 0.1μF decoupling capacitor near VCC
- Ensure stable power supply
- Check for electromagnetic interference
Related Posts
IC 74173 – 4-Bit D-Type Register with 3-State Outputs
IC 74173 - 4-Bit D-Type Register with 3-State Outputs
TTL Quad D Flip-Flop with Asynchronous Clear and Output ...
DIY Metal Detector Kit
DIY Metal Detector Kit
DC 3V-5V Non-Contact Sensor Module with 60mm Detection Range
Introduc...
CNC V3 Shield with 4 A4988 Drivers
CNC V3 Shield with 4 A4988 Drivers
Complete Arduino-compatible CNC controller for 3D printers and mi...
CN3791 12V MPPT Solar Charger Module
CN3791 12V MPPT Solar Charger Module
Maximum Power Point Tracking Solar Charge Controller for Lead-Acid/Lithiu...
CJMCU-TRRS 3.5mm Jack AV Stereo Module
CJMCU-TRRS 3.5mm Jack AV Stereo Module
Compact breakout board for audio/video signal interfacing with TRRS con...
TTP223 Capacitive Touch Sensor Module (Red)
TTP223 Capacitive Touch Sensor Module (Red)
Single-Key Touch Detection with Digital Output for Arduino and DIY...
Capacitive Soil Moisture Sensor
Capacitive Soil Moisture Sensor
Corrosion-Resistant Humidity Detection for Plants and Agricultural Application...
VHM-314 Bluetooth Audio Receiver Board Module
VHM-314 Bluetooth Audio Receiver Board Module
High-fidelity stereo audio receiver with Bluetooth 5.0 and 3.5mm...
BD243 DIY Mini Tesla Coil Prototyping Kit
BD243 DIY Mini Tesla Coil Prototyping Kit
High-Voltage Wireless Power Demonstration - Build Your Own Spark Gap...
BF120-3AA Precision Strain Gauges (120Ω)
BF120-3AA Precision Strain Gauges (120Ω)
High-precision foil strain gauges for load cell applications with 120...
AI Thinker ESP32-CAM Development Board
AI Thinker ESP32-CAM Development Board
WiFi + Bluetooth with OV2640 Camera Module - Arduino Compatib...

Recent Comments