Question about MPU6050

Is it possible to use that sensor to measure distance?
Suppose that the board with the sensor moves 20 cm ,I want to calculate that distance from te data obtained from the MPU6050
Thanks
directions

MPU can tell you what direction you are moving and if you know the velocity, it is easy to calculate distance.

  1. Take the 1000 values of the acceleration with MPU rest in a stable position.
  2. Calculate the standard deviation of the acceleration readings.
  3. Stick the MPU to a moving body.
  4. Record the acceleration value with a time (print millis()).
  5. Calculate the change in acceleration (Acc(current)-Acc(previous)) or all points.
  6. Filter the acceleration value using standard deviation (step 2). The change in acceleration is greater than the standard deviation is true acceleration.
  7. The MPU acceleration output unit is g, where 1g=9.8 m/s^2. Multiply the change in acceleration value with 9.8.
  8. Now calculate the displacement d=0.5at^2; a= acceleration (step 7), t=time in sec.
  9. Finally calculate the cummulative displacement c(n)=c(n-1)+d(n).
    hope this can help

Thanks a lot
any example code??

As marounalkattar indicated, an accelerometer measures linear acceleration, so to get distance, you need to integrate over time (twice). The issue is that it’s highly unlikely that the time iteration is in small enough increments to know what happened at every point in time, and the acceleration was unlikely to be linear, which is why integrating once to get velocity is generally “ok”, but a second to get position is far from accurate, and that inaccuracy builds over time.

1 Like