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
| Parameter | Value |
|---|---|
| Supply Voltage | 2.375 V – 3.46 V |
| Accelerometer Range | ±2g, ±4g, ±8g, ±16g |
| Gyroscope Range | ±250, ±500, ±1000, ±2000 °/s |
| ADC Resolution | 16-bit |
| Interface | I2C (400 kHz) at 0x68/0x69 |
| On-chip DMP | Digital Motion Processor for sensor fusion |
Interfacing
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
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.
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
| Feature | MPU-6050 | MPU-9250 | ICM-20948 | BNO055 |
|---|---|---|---|---|
| Axes | 6 (A+G) | 9 (A+G+M) | 9 (A+G+M) | 9 (A+G+M) |
| Magnetometer | ✗ | ✓ (AK8963) | ✓ (AK09916) | ✓ (BMM150) |
| On-Chip Fusion | DMP (basic) | DMP (basic) | DMP (quaternion) | Full AHRS (quaternion, Euler, gravity) |
| Interface | I²C/SPI | I²C/SPI | I²C/SPI | I²C |
| Gyro Noise | 0.005 °/s/√Hz | 0.01 °/s/√Hz | 0.015 °/s/√Hz | 0.014 °/s/√Hz |
| Status | Active | Discontinued | Active | Active |
| Best For | Basic tilt | Legacy 9-axis | New 9-axis projects | Plug-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.