شحن مجاني للأوردرات فوق
1000 ج
رمضان كريم
High-Sensitivity Digital Compass Module for Arduino Projects
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.

Measures X, Y, Z magnetic fields simultaneously
1-2 milli-gauss resolution (up to 8 Gauss range)
100μA operation current (0.5μA standby)
Standard digital output (3.3V or 5V compatible)
| 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 | 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 |
// Basic Connections: // VCC → 3.3V (use regulator if needed) // GND → GND // SCL → A5 (or SCL) // SDA → A4 (or SDA) // DRDY → (optional interrupt pin)
#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);
}
// 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
// Set output data rate (default 15Hz)
mag.setDataRate(HMC5883_DATARATE_15HZ);
// Other options: 0.75, 1.5, 3, 7.5, 30, 75, 220Hz
// Set continuous measurement mode
mag.setMeasurementMode(HMC5883_CONTINUOUS);
// Other options: SINGLE (power saving), IDLE
// Hard iron calibration offsets
mag.setOffset(-10.35, 58.95, -40.59);
// Obtain values from calibration routine
No account yet?
Create an Account
Recent Comments