The MPU-6050 is a 6-axis motion tracking device that integrates a 3-axis gyroscope and a 3-axis accelerometer into a single chip. This compact and versatile sensor is widely used in applications requiring motion sensing and orientation detection. Its ability to measure angular velocity and linear acceleration makes it ideal for robotics, drones, smartphones, gaming devices, and wearable technology.
The MPU-6050 also features a Digital Motion Processor (DMP) that can process complex motion algorithms internally, reducing the computational load on the host microcontroller. It communicates via the I2C protocol, making it easy to interface with microcontrollers like the Arduino UNO.
The MPU-6050 has 8 pins. Below is the pinout and description:
Pin | Name | Description |
---|---|---|
1 | VCC | Power supply input (2.375V to 3.46V). Typically connected to 3.3V. |
2 | GND | Ground connection. |
3 | SCL | I2C clock line. Connect to the microcontroller's SCL pin. |
4 | SDA | I2C data line. Connect to the microcontroller's SDA pin. |
5 | XDA | Auxiliary I2C data line (used for connecting additional sensors). |
6 | XCL | Auxiliary I2C clock line (used for connecting additional sensors). |
7 | AD0 | I2C address select. Connect to GND for address 0x68 or VCC for address 0x69. |
8 | INT | Interrupt output. Used to signal the host microcontroller of data availability. |
Below is an example of how to interface the MPU-6050 with an Arduino UNO using the I2C protocol:
#include <Wire.h>
// MPU-6050 I2C address (default is 0x68 when AD0 is connected to GND)
const int MPU_ADDR = 0x68;
// Variables to store raw accelerometer and gyroscope data
int16_t accelX, accelY, accelZ;
int16_t gyroX, gyroY, gyroZ;
void setup() {
Wire.begin(); // Initialize I2C communication
Serial.begin(9600); // Start serial communication for debugging
// Wake up the MPU-6050 (it starts in sleep mode)
Wire.beginTransmission(MPU_ADDR);
Wire.write(0x6B); // Access the power management register
Wire.write(0); // Set to 0 to wake up the sensor
Wire.endTransmission();
}
void loop() {
// Request accelerometer and gyroscope data
Wire.beginTransmission(MPU_ADDR);
Wire.write(0x3B); // Starting register for accelerometer data
Wire.endTransmission(false);
Wire.requestFrom(MPU_ADDR, 14, true); // Request 14 bytes of data
// Read accelerometer data
accelX = Wire.read() << 8 | Wire.read();
accelY = Wire.read() << 8 | Wire.read();
accelZ = Wire.read() << 8 | Wire.read();
// Read gyroscope data
gyroX = Wire.read() << 8 | Wire.read();
gyroY = Wire.read() << 8 | Wire.read();
gyroZ = Wire.read() << 8 | Wire.read();
// Print the data to the Serial Monitor
Serial.print("Accel X: "); Serial.print(accelX);
Serial.print(" | Accel Y: "); Serial.print(accelY);
Serial.print(" | Accel Z: "); Serial.println(accelZ);
Serial.print("Gyro X: "); Serial.print(gyroX);
Serial.print(" | Gyro Y: "); Serial.print(gyroY);
Serial.print(" | Gyro Z: "); Serial.println(gyroZ);
delay(500); // Delay for readability
}
No Data or Incorrect Readings:
Sensor Not Responding:
Inaccurate Measurements:
Interrupt Pin Not Working:
Can the MPU-6050 operate at 5V? No, the MPU-6050 operates at 3.3V. Use a level shifter if interfacing with a 5V microcontroller.
How do I calibrate the MPU-6050? Calibration involves reading the raw sensor data and calculating offsets for each axis. These offsets can then be subtracted from subsequent readings.
What is the maximum sampling rate of the MPU-6050? The MPU-6050 supports a maximum sampling rate of 1kHz for both the accelerometer and gyroscope.
Can I connect multiple MPU-6050 sensors to the same I2C bus? Yes, but you must configure each sensor with a unique I2C address by setting the AD0 pin appropriately.