How to remove the gravity from accelerometer

First calibrate the offsets by measuing the outputs in all 6 othogonal directions and averaging the +g and -g readings - for instance you see 0.99 above, if with the board inverted you saw -1.01, you'd know that the z offset is -0.01. Repeat for x and y being vertical.

Then you can calibrate the gains (my example above has a nice 1.00 for the z-gain, if the x and y are different you need to scale them to match).

Now you have nice calibrated readings. So you know gravity should be a 3D unit vector whenever the sensor is stationary on the earth's surface. If its going to be at different orientations you need to determine the orientation to remap that vector before subtracting it off. If the sensor is accelerating too, that acceleration will be the remainder after subtracting gravity.

When coding this stuff you always need to be careful to know which frame of reference you mean, as there is the global frame and the sensor frame, and converting between the two is commonly needed in this kind of code. The sensor only knows about sensor frame of reference of course...

1 Like