The MPU6050 is a 6-axis motion tracking module that combines:
- 3-axis gyroscope (measures rotation)
- 3-axis accelerometer (measures linear acceleration)
- Plus a Digital Motion Processor (DMP) for sensor fusion!
It’s a compact, powerful IMU (Inertial Measurement Unit) for Arduino and other microcontrollers.
โ๏ธ Key Specs
Feature | Value |
---|---|
Voltage | 3.3V logic (but 5V-tolerant via some boards) |
Communication | I2C (SCL, SDA) |
Gyroscope range | ยฑ250 to ยฑ2000 ยฐ/s |
Accelerometer range | ยฑ2g to ยฑ16g |
Sensor fusion | Onboard DMP (Digital Motion Processor) ๐ง |
๐ Pinout (Typical Module)
Pin | Function |
---|---|
VCC | Power (3.3V or 5V) |
GND | Ground |
SDA | I2C Data |
SCL | I2C Clock |
INT | Interrupt (optional) |
๐ On most breakout boards, you can safely connect VCC to 5V (they have a regulator & logic shifter built in).
๐งญ What Can It Measure?
โ
Tilt (pitch, roll)
โ
Rotation (yaw, angular velocity)
โ
Acceleration (e.g., walking, shaking)
โ
Orientation (with sensor fusion!)
๐งฐ Arduino Code Example (Using Wire + Adafruit Library)
First, install:
- Adafruit_MPU6050
- Adafruit_Sensor
- Wire
#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
Adafruit_MPU6050 mpu;
void setup() {
Serial.begin(115200);
while (!Serial)
delay(10);
if (!mpu.begin()) {
Serial.println("MPU6050 not found!");
while (1) yield();
}
Serial.println("MPU6050 ready!");
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
}
void loop() {
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
Serial.print("Accel X: "); Serial.print(a.acceleration.x); Serial.print(" m/s^2, ");
Serial.print("Y: "); Serial.print(a.acceleration.y); Serial.print(", ");
Serial.print("Z: "); Serial.print(a.acceleration.z); Serial.println();
Serial.print("Gyro X: "); Serial.print(g.gyro.x); Serial.print(" rad/s, ");
Serial.print("Y: "); Serial.print(g.gyro.y); Serial.print(", ");
Serial.print("Z: "); Serial.print(g.gyro.z); Serial.println();
Serial.println("----");
delay(500);
}
๐งช Use Cases
- ๐ค Self-balancing robots (like mini Segways!)
- ๐ฎ Motion-controlled joysticks
- ๐ Quadcopters and drones
- ๐ง Fall detection or human motion tracking
- ๐ Robotics education kits
โ ๏ธ Tips & Gotchas
โ ๏ธ Needs calibration for accurate data
โ ๏ธ Sensitive to vibrations โ mount with foam or dampening
โ ๏ธ Raw gyro data drifts over time โ use sensor fusion (e.g., Madgwick or Mahony filters)
๐ง Want More?
- How to combine it with servos for balancing bots ๐ค๐งโโ๏ธ
- 3D visualization of motion in Processing or Unity ๐ฎ
- How to fuse it with magnetometers (MPU9250 style!)