MPU6050: reading data from a widely used 6-axis IMU
Atlasbot · 18/8/2026 · 11 min read
Among the plethora of IMUs on the market, MPU6050 is the name most familiar to beginner DIY — low cost robotics, simple I2C interfacing, and an Arduino/ESP32 library available for nearly every use.
Key concepts
MPU6050 is IMU6-axis(6-DOF): 3 axes accelerometer + 3 gyroscope axes in the same chip, without magnetometer (as opposed to MPU9250— 9-axis version with additional digital compass, learned at what IMU is?).
| Parameters | Value |
|---|---|
| Accelerometer | ±2/±4/±8/±16g (adjustable) |
| Gyroscope | ±250/±500/±1000/±2000°/second (adjustable) |
| Communication | I2C (default address 0x68, or 0x69 if AD0 pins are attached) |
| Voltage | 3.3–5V (module usually with LDO transducer available) |
How it works
#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
void setup() {
Serial.begin(115200);
Wire.begin();
mpu.initialize();
if (!mpu.testConnection()) {
Serial.println("Không kết nối được MPU6050 — kiểm tra dây I2C (SDA/SCL)");
}
}
void loop() {
int16_t ax, ay, az, gx, gy, gz;
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
Serial.print("Accel: "); Serial.print(ax); Serial.print(",");
Serial.print(ay); Serial.print(","); Serial.println(az);
Serial.print("Gyro: "); Serial.print(gx); Serial.print(",");
Serial.print(gy); Serial.print(","); Serial.println(gz);
delay(100);
}
The readout is a raw (raw) — that needs to be divided by the sensitivity coefficient corresponding to the selected measurement range for real units (m/s² or degrees/sec, learned in the previous 2 articles), this information is included in the MPU6050 datasheet.
Technical details
Formulas
Convert raw values to real units, using the coefficient of sensitivity in the chosen measurement range:
Actual_value = Raw_value / Sensitivity_scale_factor
Accelerometer example, ±8g range, sensitivity 4096 LSB/g:
raw = 8192 → actual_value = 8192/4096 = 2g = 2 × 9.8 ≈ 19.6 m/s²
Gyroscope example, ±500°/s range, sensitivity 65.5 LSB/(°/s):
raw = 3275 → actual_value = 3275/65.5 = 50°/s
Parameters
| Thanh ghi I2C | Function |
|---|---|
0x75 (WHO_AM_I) | Read to confirm the MPU6050 chip (expected value 0x68) |
0x6B (PWR_MGMT_1) | Sleep mode toggle |
0x1C (ACCEL_CONFIG) | Select the accelerometer range |
0x1B (GYRO_CONFIG) | Select gyroscope gauge range |
Practical applications
The MPU6050 is a reasonable starting choice for learning and testing IMU data thanks to its low cost and large community of support — which is the underlying chip for the learning of the accelerometer/gyroscope concepts presented in the previous two articles before its application to real-world problems such as the IMU problem in AMR. For real-world applications that require higher precision or need a magnetometer, consideration should be given to higher-end models such as the MPU9250 or BNO055 (which has a sensor fusion filter on board). BNO055 is particularly noteworthy for robots that need higher stability than MPU6050 but do not yet need investments in expensive industrial IMUs — it runs its own internal fusion sensor algorithm, returns directly calculated quaternion direction, reducing the portion of code that has to be self-written at the application layer.
Practical example
#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
const float ACCEL_SENSITIVITY = 4096.0; // LSB/g, dai +-8g
const float GYRO_SENSITIVITY = 65.5; // LSB/(deg/s), dai +-500deg/s
void setup() {
Serial.begin(115200);
Wire.begin();
mpu.initialize();
mpu.setFullScaleAccelRange(MPU6050_ACCEL_FS_8);
mpu.setFullScaleGyroRange(MPU6050_GYRO_FS_500);
}
void loop() {
int16_t ax, ay, az, gx, gy, gz;
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
float ax_g = ax / ACCEL_SENSITIVITY;
float gz_dps = gz / GYRO_SENSITIVITY;
Serial.print("Accel X: "); Serial.print(ax_g, 2); Serial.println(" g");
Serial.print("Gyro Z: "); Serial.print(gz_dps, 2); Serial.println(" deg/s");
delay(100);
}
Typical output:
Accel X: 0.02 g
Gyro Z: 1.15 deg/s
The correct conversion of the sensitivity coefficient (matching the measured range configured with setFullScaleAccelRange/setFullScaleGyroRange) is the required step — misusing the coefficient of another measured range yields a completely wrong value even though the code does not report any errors.
Common mistakes
testConnection()returns false— usually due to SDA/SCL pin mismatch, lack of resistor pull-up (some modules are not available), or wrong voltage coupling (some modules are only 3.3V tolerant despite recording 5V support).- Misused sensitivity coefficient mismatch configurational strip— as calculated in Formula section, each strip has its own coefficient, configurational
setFullScaleAccelRangewithout changing the corresponding coefficient when the calculation causes complete miscalculation. - Gyro data drift despite not moving — this is the normal drift phenomenon of all low-cost MEMS gyroscopes (What is Gyroscope?), not connection errors.
- Do not check
WHO_AM_Iwhen false chip or I2C connection errors are suspected— skipping this basic confirmation step makes it difficult to diagnose when there are multiple other I2C devices on the same bus causing address conflicts.
Conclusion
MPU6050 is a reasonable starting choice for learning and testing with IMU data thanks to its low cost and large support community — correctly converting the sensitivity coefficient to the configured measurement range is a key step that is often overlooked. The last of the column, IMU Calibration, goes into how to eliminate system errors (bias) before using data for real-world applications.
Get new articles and lessons by email
When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.
Unsubscribe any time with the link in each email. See our Privacy policy.