Table of Contents

lamaPLC: GY-511 6DOF sensor module

GY-511 6DOF sensor module The GY-511 is a 6-degree-of-freedom (6DOF) sensor module that combines a 3-axis digital accelerometer and a 3-axis digital magnetometer into a single breakout board. It is primarily based on the STMicroelectronics LSM303DLHC chip and is widely used for creating electronic compasses and motion-tracking systems.

Key Specifications

Pinout Configuration

The module typically features 8 pins, though only 4 are essential for basic operation with controllers like Arduino Uno:

PinFunctionDescription
VINPower Supply3.3V to 5V input.
3VOutput3.3V regulated output (up to 100mA).
GNDGroundSystem ground.
SCLI²C ClockClock signal for serial communication.
SDAI²C DataData signal for serial communication.
INT1/2InterruptsProgrammable for motion or free-fall detection.
DRDYData ReadyIndicator for new measured values.

Common Applications

Arduino example code

To connect the GY-511 (LSM303DLHC) to an Arduino, the most reliable method is to use the Pololu LSM303 Library.

GY-511 PinArduino Uno / NanoArduino Mega
VIN5V5V
GNDGNDGND
SCLA5Pin 21
SDAA4Pin 20

First, install the LSM303 library from the Arduino Library Manager. This basic code reads raw accelerometer and magnetometer data and prints it to the Serial Monitor.

#include <Wire.h>
#include <LSM303.h>
 
LSM303 compass;
 
void setup() {
  Serial.begin(9600);
  Wire.begin();
 
  // Initialize the sensor
  if (!compass.init()) {
    Serial.println("Failed to detect GY-511!");
    while (1);
  }
 
  compass.enableDefault();
  Serial.println("GY-511 Initialized.");
}
 
void loop() {
  // Read all sensor data
  compass.read();
 
  // Accelerometer data (X, Y, Z)
  Serial.print("Accel X: "); Serial.print(compass.a.x);
  Serial.print(" Y: ");      Serial.print(compass.a.y);
  Serial.print(" Z: ");      Serial.print(compass.a.z);
 
  // Magnetometer data (X, Y, Z)
  Serial.print(" | Mag X: "); Serial.print(compass.m.x);
  Serial.print(" Y: ");       Serial.print(compass.m.y);
  Serial.print(" Z: ");       Serial.println(compass.m.z);
 
  delay(500); // Wait half a second
}

Key Functions in the Library

Calibration Note

For accurate compass readings, you must calibrate the magnetometer. Use the Calibrate example included with the library to find your sensor's specific m_min and m_max values and update them in your setup().

I2C topics on lamaPLC

PageDateTags
2026/04/23 21:51, , , , , , ,
2025/09/23 21:25, , , , , ,
2026/03/22 03:14, , , , , , ,
2026/04/23 21:52, , , , , , , , ,
2026/04/23 21:52, , , , , , , , , , , , ,
2026/03/28 23:50, , , , , , ,
2026/04/12 00:34, , , ,
2026/04/23 21:52, , , , , , , , , , , , , ,
2026/04/23 21:52, , , , , , , , , , ,
2026/04/23 21:52, , , , , , , , , ,
2026/03/22 00:08, , , , , , , , , , ,
2026/04/23 21:52, , , , , , , , , , ,
2026/04/23 21:52, , , , , , , ,
2025/05/31 23:32, , , , , , , ,
2026/04/23 21:52, , , , , , , , , , , , , ,
2025/11/22 00:07, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
2023/07/01 17:29, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
2026/03/22 01:44, , , , , , , , ,
2026/04/23 21:52, , , , , , , , ,
2026/04/23 21:52, , , , , , , , , , , , , , , ,
2026/04/23 21:51, , , ,
2026/04/23 21:52, , , , , , , , , , , , , , , , , , , , , , , , ,
2026/04/11 19:54, , , , , , , , , , , , , , , , , , ,
2026/04/23 21:52, , , , , , , , , , ,
2026/02/14 18:27, , , , , , , , , ,
2026/04/23 21:52, , , , , , ,
2026/04/23 21:52, , , , , , , ,
2026/04/23 21:52, , , , , , , ,
2026/04/23 21:52, , , , , , , , , , , , ,
2026/04/15 19:41, , , , , , , , , , , , , , , ,
2026/04/23 21:52, , , , , , , , , , , , , ,
2026/02/14 23:47, , , ,
2026/02/14 23:51, , , , , ,
2026/02/14 18:26, , , ,
2026/04/23 21:52, , , , , , , , , , , , ,
2026/04/23 21:52, , , , , , , , , , ,
2026/04/23 21:52, , , , , , , ,
2026/03/05 21:19, , , , , , , , , , , , , , , , ,
2026/02/14 18:27, , , , , , ,

This page has been accessed for: Today: 2, Until now: 4