# Offset value for calibrate MPU-6050

**URL:** <https://forum.arduino.cc/t/offset-value-for-calibrate-mpu-6050/1364581>\
**Category:** Programming\
**Created:** [March 17, 2025, 4:28pm UTC](https://forum.arduino.cc/t/offset-value-for-calibrate-mpu-6050/1364581 "2025-03-17T16:28:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sinus\_20](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sinus_20/32/1203124_2.png) [@sinus\_20](https://forum.arduino.cc/u/sinus_20)\
**Post date:** [March 17, 2025, 4:28pm UTC](https://forum.arduino.cc/t/offset-value-for-calibrate-mpu-6050/1364581/1 "2025-03-17T16:28:54Z")

</div>

i already saw other post with same topic: [How to implement MPU6050 offsets into code? - Projects / Programming - Arduino Forum](https://forum.arduino.cc/t/how-to-implement-mpu6050-offsets-into-code/1102961)

i also looking for tutorial in youtube and some codes in github but my head start to dizzy. i get my offset value for calibrating MPU-6050 using program by Jeff Rowberg

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/6/e/d/6edfb94f57c87913e43ee1663df4230981a26d77.png)

please how to add this value in program? since the example library already display the data in m/s^2 unit, so when I substract it directly it become unvalid value, i also dunno what unit is this offset? and i need to calibrate it because my Z-axis accelero display ~11 m/s^2 which not valid cause it must be aroun 9.8 due to gravity.

i know this website from other post: [Tutorial: How to calibrate a compass (and accelerometer) with Arduino | Underwater Arduino Data Loggers](https://thecavepearlproject.org/2015/05/22/calibrating-any-compass-or-accelerometer-for-arduino/)  
it said:  
 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/b/7/5/b752cd7aaf16baaf6e61ce0b9e6803ac8fbcd00f.png)  
since uncalibrated data is (a.acceleration.x), offset is a fixed value, how about the scalling factor should I use?  
note: i only need the accelerometer, cause many posts mostly about calibrate the gyro for balance like this ino.file [MPU6050\_Latest\_code.ino](https://forum.arduino.cc/uploads/short-url/aPKy4cur5knUrgHbPjpPyJMKjM6.ino) (7.4 KB)

here i drop my unvalid data code

```arduino
#include <Arduino.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>

Adafruit_MPU6050 mpu;

float ax_offset = -1686;
float ay_offset = -4053;
float az_offset = 955;
float gx_offset = 49;
float gy_offset = 42;
float gz_offset = -9;

void setup() {
  Serial.begin(115200);
  mpu.begin();
  mpu.setAccelerometerRange(MPU6050_RANGE_2_G);
  mpu.setGyroRange(MPU6050_RANGE_500_DEG);
  mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
  delay(1000);
}

void loop() {
  /* Get new sensor events with the readings */
  sensors_event_t a, g, temp;
  mpu.getEvent(&a, &g, &temp);
    
  // Apply offset correction
  float ax = a.acceleration.x - ax_offset; //scaling factor ??
  float ay = a.acceleration.y - ay_offset;
  float az = a.acceleration.z - az_offset;

  float gx = g.gyro.x - gx_offset;
  float gy = g.gyro.y - gy_offset;
  float gz = g.gyro.z - gz_offset;

  /* Print out the values */
  Serial.print("Acceleration X: "); Serial.print(ax); Serial.print(" m/s², ");
  Serial.print("Y: "); Serial.print(ay); Serial.print(" m/s², ");
  Serial.print("Z: "); Serial.print(az); Serial.println(" m/s²");

  Serial.print("Rotation X: "); Serial.print(gx); Serial.print(" rad/s, ");
  Serial.print("Y: "); Serial.print(gy); Serial.print(" rad/s, ");
  Serial.print("Z: "); Serial.print(gz); Serial.println(" rad/s");

  Serial.println("");
  delay(500);
}

```

and this the display of serial monitor

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/b/f/0/bf06ab156a0a3689e2a60ffb82b5f7536df13dce.png)

---

<div class="post-metadata">

**Author:** ![iamaryang](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/iamaryang/32/1204481_2.png) [@iamaryang](https://forum.arduino.cc/u/iamaryang)\
**Post date:** [March 17, 2025, 7:51pm UTC](https://forum.arduino.cc/t/offset-value-for-calibrate-mpu-6050/1364581/2 "2025-03-17T19:51:13Z")

</div>

Hey @sinus_20 , have you tried using the example code in the library of jeff rowberg, MPU6050 - IMU\_Zero.ino,

> <https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/MPU6050/examples/IMU_Zero/IMU_Zero.ino>

If you read from line number 44 to 73 in this link you will find what jrowberg mean by offsets and how you should use them, hope this helps. Thank you!

---

<div class="post-metadata">

**Author:** ![sinus\_20](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sinus_20/32/1203124_2.png) [@sinus\_20](https://forum.arduino.cc/u/sinus_20)\
**Post date:** [March 18, 2025, 4:42pm UTC](https://forum.arduino.cc/t/offset-value-for-calibrate-mpu-6050/1364581/3 "2025-03-18T16:42:34Z")

</div>

thank u @iamaryang, i read those library example for mpu6050\_raw data and imu\_zero, so this far i understand that offset is only apply in raw data, right? i try to upload the example mpu6050\_raw data with some modification from line 94

```arduino
// use the code below to change accel/gyro offset values (line 95-115)
    Serial.println("Updating internal sensor offsets...");
    // -1686, -4053, 955, 49, 42, -9
    accelgyro.setXAccelOffset(-1686);
    accelgyro.setYAccelOffset(-4053);
    accelgyro.setZAccelOffset(955);
    accelgyro.setXGyroOffset(49);
    accelgyro.setYGyroOffset(42);
    accelgyro.setZGyroOffset(-9);
    Serial.print(accelgyro.getXAccelOffset()); Serial.print("\t"); 
    Serial.print(accelgyro.getYAccelOffset()); Serial.print("\t"); 
    Serial.print(accelgyro.getZAccelOffset()); Serial.print("\t"); 
    Serial.print(accelgyro.getXGyroOffset()); Serial.print("\t"); 
    Serial.print(accelgyro.getYGyroOffset()); Serial.print("\t"); 
    Serial.print(accelgyro.getZGyroOffset()); Serial.print("\t"); 
    Serial.print("\n");

```

the result is

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/6/1/7/617f3c9ef74976f0374eb88d38d5cc4b98754622.png)

but i still don't understand the correlation with m/s^2 unit cause in adafruit\_mpu6050 there's no such thing as function to get calibrate value.

then i try IMU\_zero, but it turns out error in line 255 ('SetAveraging' was not declared in this scope), i thought i should declare it first since I use [platform.io](http://platform.io) instead of arduino.ide, other void function can be executed since all of them are outside the void loop, so i still can't upload it to my esp32 microcontroller, please help me, i really saw many post about this mpu-6050 calibration issue but still can't figure out the solutions.

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/b/3/b/b3b02ffd16337049eb2a96cb815541f36fabab97.png)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 14, 2025, 4:43pm UTC](https://forum.arduino.cc/t/offset-value-for-calibrate-mpu-6050/1364581/4 "2025-09-14T16:43:04Z")

</div>

Closed on September 14, 2025, 4:43pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
