Skip to content
My Account

Reference

MPU6050 Accelerometer + Gyroscope Complete Guide

The MPU6050 packs a 3-axis accelerometer and 3-axis gyroscope on one die with an onboard motion-fusion processor, for around the price of a single sensor. This guide covers its real I2C addressing, pinout, and wiring one to an ESP32.

2 min read

No ratings yet, be the first.

The MPU6050 (usually sold on a small “GY-521” breakout) is a 6-axis motion-tracking IC from InvenSense: a 3-axis accelerometer and 3-axis gyroscope combined on one chip, with an onboard Digital Motion Processor (DMP) that can fuse both into a stable orientation estimate in hardware, offloading that math from your microcontroller.

Pinout and I2C Address

PinFunction
VCCPower, typically 3.3V–5V (breakout-regulated)
GNDGround
SCLI2C clock
SDAI2C data
XDAAuxiliary I2C data, for chaining a magnetometer directly to the MPU6050
XCLAuxiliary I2C clock
AD0I2C address select
INTInterrupt output (e.g. new-data-ready, or DMP events)

Default I2C address is 0x68 with AD0 left floating or tied to GND. Pull AD0 HIGH (3.3V) for address 0x69, useful when running two MPU6050s on the same bus.

Wiring to an ESP32

MPU6050 PinESP32 Pin
VCC3.3V
GNDGND
SCLGPIO22
SDAGPIO21

Arduino code (Adafruit MPU6050 library)

#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>

Adafruit_MPU6050 mpu;

void setup() {
  Serial.begin(115200);
  Wire.begin(21, 22);
  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050");
    while (1) delay(10);
  }
  mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
  mpu.setGyroRange(MPU6050_RANGE_500_DEG);
}

void loop() {
  sensors_event_t a, g, temp;
  mpu.getEvent(&a, &g, &temp);

  Serial.print("Accel (m/s^2): ");
  Serial.print(a.acceleration.x); Serial.print(", ");
  Serial.print(a.acceleration.y); Serial.print(", ");
  Serial.println(a.acceleration.z);

  Serial.print("Gyro (rad/s): ");
  Serial.print(g.gyro.x); Serial.print(", ");
  Serial.print(g.gyro.y); Serial.print(", ");
  Serial.println(g.gyro.z);

  delay(200);
}

Install “Adafruit MPU6050” via the Arduino Library Manager (it uses Adafruit’s shared sensor-abstraction library, giving values in standard m/s² and rad/s units). For onboard DMP-based orientation fusion instead of raw values, the older i2cdevlib MPU6050 library exposes it directly, at the cost of a less beginner-friendly API.

Practical Tips

  • Calibrate at rest: the gyroscope has a real zero-rate offset that drifts between units, read and subtract a baseline while the sensor sits still before using its output.
  • Gyro drifts over time: pure gyro integration for orientation drifts, this is exactly what the onboard DMP’s sensor fusion (or a software complementary/Kalman filter combining accel + gyro) is for.
  • Mount rigidly: any flex or vibration in the mount reads as false acceleration/rotation.
  • XDA/XCL are optional: leave them unconnected unless you’re chaining an external magnetometer (e.g. an HMC5883L) directly to the MPU6050’s auxiliary bus.

Practical Applications

  • Tilt/orientation sensing: self-balancing robots, gimbals.
  • Step counting / activity detection: wearable projects.
  • Vibration/impact detection: accelerometer-only use cases.
  • Drone/RC flight controllers: a common low-cost IMU choice for hobby builds.

Conclusion

The MPU6050 is a well-documented, inexpensive way to add 6-axis motion sensing to a project, over the same I2C bus an ESP32 already uses for other sensors on this site.

Advertisement

Related

All guides

More guides

Keep building.

From ESP32 HomeKit accessories to Arduino and ATtiny reference guides, there’s more where this came from.

All guides