The MPU6050 is a 6-axis motion tracking device that combines a 3-axis accelerometer and a 3-axis gyroscope on a single chip. This compact and versatile sensor is widely used for applications requiring precise motion tracking and orientation detection. It communicates via the I2C protocol, making it easy to interface with microcontrollers like Arduino, Raspberry Pi, and other embedded systems.
Pin | Name | Description |
---|---|---|
1 | VCC | Power supply input (2.375V to 3.46V, typically 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, optional). |
6 | XCL | Auxiliary I2C clock line (used for connecting additional sensors, optional). |
7 | AD0 | I2C address select pin (connect to GND for 0x68, or VCC for 0x69). |
8 | INT | Interrupt pin (used for signaling data availability or events, optional). |
Below is an example of how to interface the MPU6050 with an Arduino UNO to read accelerometer and gyroscope data.
#include <Wire.h>
#include <MPU6050.h>
// Create an MPU6050 object
MPU6050 mpu;
// Variables to store sensor data
int16_t ax, ay, az; // Accelerometer data
int16_t gx, gy, gz; // Gyroscope data
void setup() {
Wire.begin(); // Initialize I2C communication
Serial.begin(9600); // Start serial communication for debugging
// Initialize the MPU6050
Serial.println("Initializing MPU6050...");
if (!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G)) {
Serial.println("Could not find a valid MPU6050 sensor. Check connections.");
while (1); // Halt the program if initialization fails
}
Serial.println("MPU6050 initialized successfully!");
}
void loop() {
// Read accelerometer and gyroscope data
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
// Print the data to the Serial Monitor
Serial.print("Accel: ");
Serial.print("X="); Serial.print(ax);
Serial.print(" Y="); Serial.print(ay);
Serial.print(" Z="); Serial.print(az);
Serial.print(" | Gyro: ");
Serial.print("X="); Serial.print(gx);
Serial.print(" Y="); Serial.print(gy);
Serial.print(" Z="); Serial.println(gz);
delay(500); // Delay for readability
}
MPU6050 Not Detected:
Inaccurate Readings:
No Data Output:
I2C Communication Errors:
Q: Can the MPU6050 be powered with 5V?
A: No, the MPU6050 operates at 3.3V. Use a voltage regulator or level shifter for 5V systems.
Q: How do I reduce drift in gyroscope readings?
A: Use sensor fusion algorithms (e.g., complementary filter or Kalman filter) to combine accelerometer and gyroscope data.
Q: Can I connect multiple MPU6050 sensors to the same I2C bus?
A: Yes, but you must configure each sensor with a unique I2C address by setting the AD0 pin differently.
Q: What is the maximum I2C clock speed supported?
A: The MPU6050 supports I2C clock speeds up to 400kHz (Fast Mode).