The MPU 6050 is a 6-axis motion tracking device that combines a 3-axis gyroscope and a 3-axis accelerometer. This versatile sensor is widely used in applications requiring motion sensing and orientation detection, such as:
Parameter | Value |
---|---|
Supply Voltage | 2.3V - 3.4V |
Operating Current | 3.9mA |
Gyroscope Range | ±250, ±500, ±1000, ±2000 °/s |
Accelerometer Range | ±2g, ±4g, ±8g, ±16g |
Communication | I2C |
I2C Address | 0x68 (default), 0x69 |
Operating Temperature | -40°C to +85°C |
Pin | Name | Description |
---|---|---|
1 | VCC | Power supply (2.3V - 3.4V) |
2 | GND | Ground |
3 | SCL | I2C Clock |
4 | SDA | I2C Data |
5 | XDA | Auxiliary I2C Data (optional, not commonly used) |
6 | XCL | Auxiliary I2C Clock (optional, not commonly used) |
7 | AD0 | I2C Address Select (connect to GND for 0x68, VCC for 0x69) |
8 | INT | Interrupt (optional, used for motion detection) |
#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
void setup() {
Wire.begin();
Serial.begin(9600);
// Initialize MPU6050
Serial.println("Initializing MPU6050...");
if (!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G)) {
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
while (1);
}
// Calibrate gyroscope. The calibration must be at rest.
Serial.println("Calibrating gyroscope...");
mpu.calibrateGyro();
// Set threshold sensibility. Default 3.
mpu.setThreshold(3);
}
void loop() {
Vector rawAccel = mpu.readRawAccel();
Vector normAccel = mpu.readNormalizeAccel();
Serial.print(" Xraw = ");
Serial.print(rawAccel.XAxis);
Serial.print(" Yraw = ");
Serial.print(rawAccel.YAxis);
Serial.print(" Zraw = ");
Serial.print(rawAccel.ZAxis);
Serial.print(" Xnorm = ");
Serial.print(normAccel.XAxis);
Serial.print(" Ynorm = ");
Serial.print(normAccel.YAxis);
Serial.print(" Znorm = ");
Serial.println(normAccel.ZAxis);
delay(500);
}
No Communication with MPU 6050:
Inaccurate Readings:
Sensor Not Detected:
Q: Can I use the MPU 6050 with a 5V microcontroller? A: Yes, but you will need to use level shifters for the I2C lines to match the 3.3V logic level of the MPU 6050.
Q: How do I change the I2C address of the MPU 6050? A: Connect the AD0 pin to GND for the default address (0x68) or to VCC for the alternate address (0x69).
Q: What is the maximum sampling rate of the MPU 6050? A: The MPU 6050 can sample data at a maximum rate of 1kHz.
Q: Can I use the MPU 6050 for tilt sensing? A: Yes, the accelerometer in the MPU 6050 can be used to measure tilt angles.
By following this documentation, you should be able to effectively integrate the MPU 6050 into your projects and troubleshoot common issues. Happy building!