lamaPLC: MPU-6050 (HW-123, GY-521) 6-axis MotionTracking device

MPU-6050 6-axis MotionTracking device The MPU-6050 (HW-123, GY-521) is a popular 6-axis motion-tracking sensor that combines a 3-axis gyroscope and a 3-axis accelerometer on a single chip. It is a MEMS device created to measure acceleration, rotational velocity, and orientation.

Key Technical Specifications

  • Sensor Type: 6-axis Inertial Measurement Unit (IMU) with an integrated temperature sensor.
  • Resolution: 16-bit analog-to-digital converters (ADCs) for all six channels, providing high-precision raw data.
  • Programmable Ranges:
    • Gyroscope: ±250, ±500, ±1000, and ±2000 °/sec.
    • Accelerometer: ±2g, ±4g, ±8g, and ±16g.
  • Communication: Primary interface is I²C (up to 400 kHz).
  • Operating Voltage: 2.375V to 3.46V for the raw chip; common breakout modules like the GY-521 include a 3.3V regulator for 5V compatibility.
  • I²C Addresses: 0x68 (default) or 0x69 (selectable via the AD0 pin).

Notable Features

  • Digital Motion Processor (DMP): An on-chip co-processor that offloads complex sensor fusion calculations (like converting raw data into quaternions or Euler angles) from the main microcontroller.
  • FIFO Buffer: A 1024-byte buffer that allows the system processor to read data in bursts, reducing power consumption by letting the host stay in sleep mode longer.
  • Auxiliary I²C Bus: Allows the MPU-6050 to act as a master to external sensors, such as a 3rd-party magnetometer, to provide full 9-axis “MotionFusion” output.

Pinout Table (HW-123, GY-521)

Pin NameDescriptionNote
VCCPower SupplyTypically 3V to 5V (due to onboard regulator).
GNDGroundCommon ground for the system.
SCLI²C Serial ClockConnect to MCU clock line (e.g., A5 on Uno).
SDAI²C Serial DataConnect to MCU data line (e.g., A4 on Uno).
XDAAux Serial DataFor connecting external I²C sensors (optional).
XCLAux Serial ClockFor connecting external I²C sensors (optional).
AD0Address SelectLow (default) = 0x68; High = 0x69.
INTInterrupt OutputSignals the MCU when new data is available.

Pin Functions & Wiring Tips

  • I²C Communication: The module acts as a slave. SCL and SDA pins are essential for all basic operations.
  • Multi-Sensor Setup: Use the AD0 pin to change the I²C address if you need to use two MPU-6050s on the same bus.
  • External Master: The XDA and XCL pins allow the MPU-6050 to act as a master to a secondary sensor, such as a magnetometer, to create a 9-axis fusion system.
  • Interrupts: The INT pin can be programmed to trigger on specific events, such as “Data Ready” or “Motion Detected,” allowing the MCU to perform other tasks until needed.

Arduino example code

To connect the MPU-6050 to an Arduino, the simplest method is to use the Adafruit MPU6050 library, which handles I²C communication and converts raw data to standard units (mls² for acceleration and rad/s for rotation).

This code initializes the sensor and prints real-time movement data to the Serial Monitor at 115200 baud.

#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
 
Adafruit_MPU6050 mpu;
 
void setup(void) {
  Serial.begin(115200);
  if (!mpu.begin()) {
    while (1) { delay(10); } // Loop if sensor not found
  }
  // Optional: Set ranges
  mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
  mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
}
 
void loop() {
  sensors_event_t a, g, temp;
  mpu.getEvent(&a, &g, &temp);
 
  // Print accel and gyro data to Serial Monitor
  Serial.print(a.acceleration.x); Serial.print(", ");
  Serial.print(g.gyro.x); Serial.println();
  delay(500);
}

Tips for Better Results

  • Calibration: For precise motion tracking, calculate offsets (the average reading when the sensor is perfectly still) and subtract them from your raw data.
  • Filtering: If your readings are “noisy,” a Complementary Filter can help combine accelerometer and gyroscope data to produce a smoother orientation (tilt) estimate.

I2C topics on lamaPLC

PageDateTags
2025/05/31 21:56, , , , , , ,
2025/09/23 19:25, , , , , ,
2026/03/21 19:20, , , , , , ,
2026/02/15 20:33, , , , , , , , ,
2026/02/14 22:24, , , , , , , , , , , , ,
2026/02/15 20:40, , , , , , , , , , , , , ,
2026/02/14 23:37, , , , , , , , , , ,
2026/02/14 22:40, , , , , , , , , ,
2026/03/21 22:25, , , , , , , , , , ,
2026/02/14 18:19, , , , , , , , , , ,
2026/02/14 18:11, , , , , , , ,
2025/05/31 21:32, , , , , , , ,
2026/02/14 19:29, , , , , , , , , , , , , ,
2025/11/21 23:07, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
2023/07/01 15:29, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
2026/03/22 00:26, , , , , , , , ,
2026/02/14 22:45, , , , , , , , ,
2026/02/14 22:09, , , , , , , , , , , , , , , ,
2026/02/14 17:26, , , ,
2026/02/14 21:54, , , , , , , , , , , , , , , , , , , , , , , , ,
2026/02/14 23:58, , , , , , , , , , ,
2026/02/14 17:27, , , , , , , , , ,
2026/02/14 23:38, , , , , , ,
2026/02/14 22:52, , , , , , , ,
2026/02/14 22:23, , , , , , , ,
2026/02/14 22:53, , , , , , , , , , , , ,
2026/02/15 20:27, , , , , , , , , , , , , , , ,
2026/02/15 20:29, , , , , , , , , , , , , ,
2026/02/14 22:47, , , ,
2026/02/14 22:51, , , , , ,
2026/02/14 17:26, , , ,
2026/02/14 22:22, , , , , , , , , , , , ,
2026/02/14 22:21, , , , , , , , , , ,
2026/02/14 22:22, , , , , , , ,
2026/03/05 20:19, , , , , , , , , , , , , , , , ,
2026/02/14 17:27, , , , , , ,

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