GY-511 LSM303DLHC 3-Axis Digital Compass Module with Accelerometer – High Precision Magnetometer & Motion Sensor for Arduino, Robotics, and Navigation

SKU: FA2171
Sensor IC

LSM303DLHC (STMicroelectronics)

Operating Voltage

3.6V – 6V DC (via onboard regulator)

Logic Voltage

1.8V – 3.3V (3.3V output available from regulator)

Current Consumption

110 µA (active), 1 µA (idle/slee

Acceleration Ranges

±2g, ±4g, ±8g, ±16g (user-selectable)

Magnetic Ranges

±1.3 / ±1.9 / ±2.5 / ±4.0 / ±4.7 / ±5.6 / ±8.1 gauss

Output Resolution

16-bit data output

Interface

I²C (100kHz / 400kHz)

Operating Temperature

-40°C to +85°C

Module Dimensions

21mm × 14.5mm × 3.5mm (excluding pin headers

Description

The GY-511 is a high-performance 6-degree-of-freedom (6DOF) sensor module that combines a 3-axis digital accelerometer and a 3-axis digital magnetometer in a single compact package. Built around the STMicroelectronics LSM303DLHC system-in-package, this module delivers both motion sensing and electronic compass functionality, making it an ideal solution for applications requiring precise orientation and heading detection.

The accelerometer component provides user-selectable full-scale ranges of ±2g, ±4g, ±8g, or ±16g, allowing you to measure both subtle tilt changes and significant impact events. The magnetometer offers seven selectable magnetic field ranges from ±1.3 to ±8.1 gauss, with a resolution down to 8 milligauss (mG), enabling accurate detection of the Earth’s magnetic field for reliable heading determination.

What sets the GY-511 apart from simpler magnetometer-only modules (such as the HMC5883L-based GY-271) is the inclusion of the 3-axis accelerometer. This accelerometer enables tilt-compensated compass functionality, where the module can calculate accurate heading even when the device is not held level. The accelerometer measures pitch and roll angles, which are then used to correct the raw magnetometer readings for accurate azimuth calculation.

The module features an onboard 3.3V low-dropout voltage regulator, accepting input voltages from 3.6V to 6V DC, making it compatible with both 3.3V and 5V microcontroller systems. The I²C interface supports standard (100 kHz) and fast mode (400 kHz) communication speeds, ensuring seamless integration with Arduino, ESP32, STM32, Raspberry Pi, and other popular embedded platforms.

Additional features include two independent programmable interrupt generators for free-fall and motion detection, an embedded temperature sensor, and a built-in FIFO buffer for efficient data collection. The module also supports 6D/4D orientation detection, enabling applications such as display rotation and position-aware user interfaces.

Whether you are building a robotic navigation system, a tilt-compensated digital compass, a motion-activated controller, or a wearable step counter, the GY-511 LSM303DLHC module provides the precision, versatility, and ease of use required for both prototyping and production.


Key Features

  • 6DOF Integration – Combines 3-axis accelerometer and 3-axis magnetometer in a single compact module

  • Tilt-Compensated Compass – Accelerometer enables accurate heading calculation when device is tilted

  • Selectable Measurement Ranges – ±2g/±4g/±8g/±16g acceleration; ±1.3 to ±8.1 gauss magnetic field

  • High-Resolution Output – 16-bit digital output for both accelerometer and magnetometer channels

  • I²C Digital Interface – Supports 100kHz and 400kHz communication speeds

  • Wide Voltage Compatibility – Onboard regulator accepts 3.6V to 6V DC input

  • Low Power Consumption – 110µA in normal mode; 1µA in idle/sleep mode

  • Programmable Interrupts – Two independent interrupt generators for free-fall and motion detection

  • Embedded Temperature Sensor – Provides onboard temperature monitoring

  • Additional Features – Embedded FIFO buffer, 6D/4D orientation detection


Technical Specifications

Specification Value
Sensor IC LSM303DLHC (STMicroelectronics)
Operating Voltage 3.6V – 6V DC (via onboard regulator)
Logic Voltage 1.8V – 3.3V (3.3V output available from regulator)
Current Consumption 110 µA (active), 1 µA (idle/sleep)
Acceleration Ranges ±2g, ±4g, ±8g, ±16g (user-selectable)
Magnetic Ranges ±1.3 / ±1.9 / ±2.5 / ±4.0 / ±4.7 / ±5.6 / ±8.1 gauss
Output Resolution 16-bit data output
Interface I²C (100kHz / 400kHz)
Operating Temperature -40°C to +85°C
Module Dimensions 21mm × 14.5mm × 3.5mm (excluding pin headers)

Pinout Description (8-pin single-row header)

Pin Function
VIN Power input (3.6V – 6V DC)
GND Ground connection
SCL I²C Clock line
SDA I²C Data line
3.3V 3.3V output from onboard regulator
INT1 Programmable interrupt 1 output
INT2 Programmable interrupt 2 output
(Varies) Additional pin configurations may vary by supplier

Typical Usage

  • Tilt-Compensated Digital Compass – Calculate accurate heading (azimuth) even when the device is tilted, using accelerometer data to correct magnetometer readings

  • Robotics Navigation – Provide orientation feedback for autonomous robots, quadcopters, and drones

  • Motion Detection Systems – Detect free-fall, taps, activity/inactivity events for security or user interface applications

  • Pedometer & Step Counting – Track user steps in wearable fitness devices

  • Display Orientation – 6D/4D orientation detection for screen rotation in portable devices

  • Position Detection – Determine device position relative to gravity for gesture recognition

  • Vehicle Navigation – Heading reference for automotive navigation systems

  • Educational Projects – Learn about sensor fusion, Earth’s magnetic field measurement, and attitude estimation algorithms

Basic Wiring Example (Arduino)

GY-511 Pin Arduino Connection
VIN 5V
GND GND
SCL A5 (or dedicated SCL pin on newer boards)
SDA A4 (or dedicated SDA pin on newer boards)

Note: The GY-511 module uses 3.3V logic. With the onboard level-shifting circuitry and 5V-tolerant I²C pull-ups, it can safely interface with 5V Arduino boards. For native 3.3V boards (ESP32, Raspberry Pi, STM32), power from 3.3V or 5V as appropriate.

Q: What is the difference between GY-511 and GY-271 (HMC5883L) modules?

The GY-511 is based on the LSM303DLHC, which includes both a 3-axis accelerometer and a 3-axis magnetometer. The GY-271 (HMC5883L) has only a magnetometer. The accelerometer in the GY-511 enables tilt compensation—accurate compass heading even when the module is not held level. Without tilt compensation, a magnetometer-only module will give incorrect heading when tilted.

Q: Why do I need tilt compensation for a compass?

When a device is tilted, the Earth’s magnetic field vector is no longer measured correctly in the horizontal plane. The accelerometer measures the tilt angles (pitch and roll), allowing the microcontroller to mathematically “rotate” the magnetometer readings back to the horizontal plane before calculating heading. For a handheld compass, tilt compensation is essential for accurate readings in real-world use.

Q: What is the heading accuracy of this module?

The LSM303DLHC magnetometer has a resolution of approximately 8 mG (milligauss). The Earth’s horizontal magnetic field is about 200-250 mG, giving a theoretical heading resolution of approximately 2.3° [= arctan(8/200)]. With proper calibration, practical accuracies of 1-3° are achievable. For accuracies better than 2°, calibration of both accelerometer and magnetometer is recommended.

Q: Does this module work with Arduino Uno?

Yes. Connect VIN to 5V, GND to GND, SDA to A4 (or dedicated SDA), and SCL to A5 (or dedicated SCL). Popular libraries include the “LSM303” library from Pololu and “Adafruit_LSM303_Accel” / “Adafruit_LSM303_Mag”. The HMC5883L_Simple library by James Sleeman also works with this module for basic compass functions.

Q: Can I use this with 3.3V systems like ESP32 or Raspberry Pi?

Yes. The onboard regulator accepts 3.6V to 6V, but the logic level is 3.3V. For native 3.3V systems, you can either power from the 3.3V pin (bypassing the regulator) or use the 5V pin and rely on the onboard level-shifting. The SDA and SCL lines are 5V-tolerant due to onboard MOSFET level shifters.

Q: What is the temperature sensor used for?

The embedded temperature sensor can be used for monitoring ambient temperature or compensating for temperature drift in the magnetometer and accelerometer readings. However, note that the temperature sensor is primarily intended for relative measurements rather than absolute temperature sensing.

Q: How do I calibrate the magnetometer?

Magnetometer calibration involves measuring the hard-iron and soft-iron distortions caused by nearby magnetic materials. The typical procedure is to rotate the module in a figure-8 pattern while logging the raw X, Y, Z readings, then determine the offsets (min/max) to center the ellipsoid. Multiple stationary orientations (e.g., 6 positions) can also be used with least-squares fitting to determine calibration parameters.

Q: What is the difference between single-shot mode and continuous mode?

In single-shot mode, the module performs one measurement when triggered, then enters sleep mode—useful for battery-powered applications. In continuous mode, the module updates measurements at a programmed rate (0.75Hz to 220Hz). Some users have reported more reliable operation using single-shot mode to avoid data lock issues with auto-incrementing register reads.

Q: What applications can this module be used for beyond compassing?

The accelerometer alone enables step counting (pedometer), free-fall detection, shock monitoring, vibration analysis, and 6D orientation detection (portrait/landscape flip). The combination of accelerometer and magnetometer enables full 3D orientation tracking (Euler angles or quaternions), robotics pose estimation, and motion-based user interfaces.

Q: Is the GY-511 suitable for industrial or business use?

Yes. The LSM303DLHC is rated for operation from -40°C to +85°C with stable performance over its lifetime. The GY-511 module is commonly used in product prototyping due to its small size, I²C interface, and comprehensive features. For high-volume production, the bare LSM303DLHC IC is available for surface-mount assembly.