The MPU-6050 is a 6-axis motion tracking device manufactured by MPU, with the part ID 6050. It integrates a 3-axis gyroscope and a 3-axis accelerometer into a single chip, making it a compact and versatile solution for motion sensing and orientation detection. The device is widely used in applications such as robotics, drones, smartphones, gaming devices, and wearable technology. Its ability to measure angular velocity and linear acceleration makes it ideal for projects requiring precise motion tracking and stabilization.
The following are the key technical details of the MPU-6050:
The MPU-6050 has 24 pins, but the most commonly used pins for basic operation are listed below:
Pin Name | Pin Number | Description |
---|---|---|
VDD | 1 | Power supply input (2.375V to 3.46V). |
GND | 2 | Ground connection. |
SCL | 6 | I2C clock line. Used for communication with the microcontroller. |
SDA | 7 | I2C data line. Used for communication with the microcontroller. |
AD0 | 9 | I2C address select. Connect to GND for address 0x68 or VDD for address 0x69. |
INT | 12 | Interrupt output. Signals when data is ready or an event occurs. |
FSYNC | 10 | Frame synchronization input. Optional for advanced synchronization features. |
For a complete pinout, refer to the MPU-6050 datasheet.
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); // Initialize 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 MPU-6050
Wire.endTransmission();
}
void loop() {
// Request 14 bytes of data from the MPU-6050
Wire.beginTransmission(MPU_ADDR);
Wire.write(0x3B); // Starting register for accelerometer data
Wire.endTransmission(false);
Wire.requestFrom(MPU_ADDR, 14, true);
// 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 from MPU-6050:
Erratic or Noisy Readings:
I2C Communication Failure:
Q: Can the MPU-6050 operate at 5V?
A: No, the MPU-6050 requires a supply voltage between 2.375V and 3.46V. Use a voltage regulator if your system operates at 5V.
Q: How do I calibrate the MPU-6050?
A: Calibration involves reading the raw sensor data when the device is stationary and calculating offsets for the gyroscope and accelerometer. These offsets can then be subtracted from subsequent readings.
Q: What is the maximum sampling rate of the MPU-6050?
A: The maximum sampling rate is 1kHz for both the gyroscope and accelerometer.
By following this documentation, you can effectively integrate the MPU-6050 into your projects and troubleshoot common issues.