Back to Sensors & Actuators Series

IMU: MPU-6050

July 21, 2025 Wasil Zafar 10 min read

MPU-6050 deep dive — 6-axis MEMS sensing, I2C interfacing, complementary filter, calibration, complete code, and real-world applications.

Contents

  1. Working Principle
  2. Electrical Characteristics
  3. Interfacing with MCU
  4. Calibration
  5. Code Example
  6. Real-World Applications
  7. MPU-9250: 9-Axis
  8. ICM-20948: Modern Successor
  9. IMU Family Comparison
  10. Limitations

Working Principle

The InvenSense MPU-6050 is a 6-axis inertial measurement unit combining a 3-axis MEMS accelerometer and a 3-axis MEMS gyroscope on one chip. The accelerometer measures linear acceleration (including gravity), while the gyroscope measures angular velocity. Together they provide complete motion sensing.

Analogy: The accelerometer is like a marble-on-a-plate that slides when tilted. The gyroscope is like a spinning top that resists changes in orientation. Combining both gives you a full picture of how an object moves and rotates.

Electrical Characteristics

ParameterValue
Supply Voltage2.375 V – 3.46 V
Accelerometer Range±2g, ±4g, ±8g, ±16g
Gyroscope Range±250, ±500, ±1000, ±2000 °/s
ADC Resolution16-bit
InterfaceI2C (400 kHz) at 0x68/0x69
On-chip DMPDigital Motion Processor for sensor fusion

Interfacing

I2C Wiring: VCC → 3.3 V, GND → GND, SCL → A5, SDA → A4, AD0 → GND (addr 0x68). Most breakout boards include a 3.3 V regulator accepting 5 V input.

Calibration

  • Accelerometer offset: Place sensor flat; X and Y should read 0 g, Z should read +1 g. Record offsets.
  • Gyroscope offset: Keep sensor stationary for 5 seconds; average readings are the zero-rate offset.
  • Complementary filter: Combine accelerometer (stable, noisy) with gyroscope (smooth, drifts) using α = 0.98 to get drift-free tilt angles.

Code Example

/*
 * MPU-6050 Tilt Angle via Complementary Filter — Arduino
 * Requires: Wire.h (built-in)
 * Wiring: I2C — SCL→A5, SDA→A4, VCC→3.3V
 */
#include <Wire.h>

#define MPU_ADDR 0x68

float accelAngleX, gyroAngleX, compAngleX;
unsigned long prevTime;

void setup() {
    Serial.begin(115200);
    Wire.begin();

    /* Wake up MPU-6050 */
    Wire.beginTransmission(MPU_ADDR);
    Wire.write(0x6B);  /* PWR_MGMT_1 register */
    Wire.write(0x00);  /* Wake up (clear sleep bit) */
    Wire.endTransmission(true);

    prevTime = millis();
    compAngleX = 0;
}

void loop() {
    int16_t ax, ay, az, gx;

    /* Read accelerometer (0x3B-0x40) and gyro X (0x43-0x44) */
    Wire.beginTransmission(MPU_ADDR);
    Wire.write(0x3B);
    Wire.endTransmission(false);
    Wire.requestFrom(MPU_ADDR, 8, true);

    ax = Wire.read() << 8 | Wire.read();
    ay = Wire.read() << 8 | Wire.read();
    az = Wire.read() << 8 | Wire.read();
    /* Skip temp (2 bytes) — read gyro X */
    Wire.read(); Wire.read();

    Wire.beginTransmission(MPU_ADDR);
    Wire.write(0x43);
    Wire.endTransmission(false);
    Wire.requestFrom(MPU_ADDR, 2, true);
    gx = Wire.read() << 8 | Wire.read();

    /* Convert to physical units */
    float accelX = atan2(ay, az) * 180.0 / PI;
    float gyroRateX = gx / 131.0;  /* ±250°/s range */

    /* Complementary filter */
    unsigned long now = millis();
    float dt = (now - prevTime) / 1000.0;
    prevTime = now;

    compAngleX = 0.98 * (compAngleX + gyroRateX * dt) + 0.02 * accelX;

    Serial.print("Tilt X: ");
    Serial.print(compAngleX, 1);
    Serial.println("°");
    delay(10);
}

Real-World Applications

Consumer

Smartphone Screen Rotation

Every modern smartphone contains an accelerometer that detects gravitational pull direction. When you rotate the phone from portrait to landscape, the gravity vector shifts from the Y-axis to the X-axis, triggering the UI to rotate.

Consumer ElectronicsMotionMEMS

MPU-9250: 9-Axis with Magnetometer

The MPU-9250 integrates the MPU-6050’s 6-axis accelerometer/gyroscope with an AK8963 3-axis magnetometer, providing full 9-DoF orientation sensing in one package. The magnetometer adds absolute heading (compass), solving the MPU-6050’s yaw drift problem. Use a Madgwick or Mahony sensor fusion filter combining all 9 axes for drift-free 3D orientation.

ICM-20948: The Modern Successor

TDK InvenSense’s ICM-20948 is the recommended replacement for the discontinued MPU-9250. It offers 9-axis sensing (accel + gyro + AKM magnetometer) with lower noise, improved temperature stability, and an on-chip DMP (Digital Motion Processor) that outputs quaternions directly. It supports both I²C and SPI interfaces.

IMU Family Comparison

FeatureMPU-6050MPU-9250ICM-20948BNO055
Axes6 (A+G)9 (A+G+M)9 (A+G+M)9 (A+G+M)
Magnetometer✓ (AK8963)✓ (AK09916)✓ (BMM150)
On-Chip FusionDMP (basic)DMP (basic)DMP (quaternion)Full AHRS (quaternion, Euler, gravity)
InterfaceI²C/SPII²C/SPII²C/SPII²C
Gyro Noise0.005 °/s/√Hz0.01 °/s/√Hz0.015 °/s/√Hz0.014 °/s/√Hz
StatusActiveDiscontinuedActiveActive
Best ForBasic tiltLegacy 9-axisNew 9-axis projectsPlug-and-play AHRS

Limitations

  • Gyro drift: Without magnetometer correction, yaw angle drifts continuously. Use MPU-9250, ICM-20948, or BNO055 for drift-free heading.
  • Vibration sensitivity: Engine vibration corrupts accelerometer data; apply low-pass filtering.
  • No absolute heading: The MPU-6050 alone has no compass; pair with HMC5883L or upgrade to a 9-axis IMU.
  • MPU-9250 discontinued: InvenSense no longer manufactures the MPU-9250; use ICM-20948 for new designs.