I am programming LIS2DE12 and IIM-42352 accelerometers in C and want to register movement of an object, for this I need to take values and compare them with pre set threshold values. But the problem is with 1G force that is always showing on Z axis, I could just subtract 1G, but this is not a good solution, because object can be rotated in any angle, so this 1G could be seen on any axis.

Is there some easy way, how to get acceleration without constant 1G ?

  • \$\begingroup\$ The simple approximation the human brain uses is to low pass filter the accelerometer (otolith organ) signal. \$\endgroup\$ Aug 10, 2023 at 13:06
  • 2
    \$\begingroup\$ You cannot solve it using simplistic ideas. First off unless you have a unique situation where the accelerometer is perfectly aligned, which i very much doubt, you will need to maintain an understanding of the gravity vector itself. Also, doing that while also using techniques that are not overly sensitive to small angle transcendentals. What papers have you already studied? Moving objects may be moving through various inclinations. \$\endgroup\$ Aug 10, 2023 at 13:13
  • \$\begingroup\$ Do you know whether the object is often at rest? If so, "been like this for a long time" might be the algorithm you need. Alternatively, can you average over a long time? \$\endgroup\$
    – jonathanjo
    Aug 10, 2023 at 13:43
  • \$\begingroup\$ To answer your core question: no. But there's a lot of approximations out there, and some really nice, fuller solutions that require more sensors. If you edit your question to tell us your whole problem then someone may be able to suggest a solution or two that fits. Relevant information to include are things like how often and how fast your gizmo moves, with how much acceleration, and exactly what you want to detect. \$\endgroup\$
    – TimWescott
    Aug 10, 2023 at 14:44
  • 1
    \$\begingroup\$ Dom, I have a Garmin dog collar (TT 15X) that is able to handle situations where two dogs are wrestling with each other in different areas over many acres of land. They may be tumbling on the ground, getting up and running for a bit, then playing more. The darned thing just works. This is not an easy problem. In fact, Garmin took their time in working out the details before creating a product. This is NOT EASY. Just FYI. \$\endgroup\$ Aug 14, 2023 at 15:22

2 Answers 2


You have to remove it through calibration. Build in a calibration mode in your software where the accelerometer is placed still in a certain way. Then save all readings on the 3 axis in non-volatile memory and then later use those as offsets to subtract before further calculations.

It is also good to keep in mind that in case the sum of all 3 axis are different than 1G, then that means that the object is moving in some manner (with the exception of a free fall straight downwards).

  • \$\begingroup\$ the problem is that 1G could also become -1G when object is flipped, so I could also try calculating magnitude of a vector sqrt(a^2+b^2+c^2) and if it is larger than 1, movement is present, of course my sensor has noise, so by default I get around 0.2-0.3 on X and Y axis and 1.03 on Z axis. But your idea is worth trying out \$\endgroup\$
    – Dominykas
    Aug 10, 2023 at 13:22
  • 1
    \$\begingroup\$ @Dominykas Hmm actually, you always have to subtract the calibrated 1G. What if the object is moving upwards but also in an angle to one side? You could get a sum of 1G in this case. But if it's 1G in a different direction than the calibrated one, then you can detect the movement still. \$\endgroup\$
    – Lundin
    Aug 10, 2023 at 13:57
  • \$\begingroup\$ @Dominykas Gravity changes with geographical location which is another reason for calibration. \$\endgroup\$
    – qrk
    Aug 10, 2023 at 20:36

Algorithms for IMUs (aka "sensor fusion") that deduce orientation are not trivial. The usual open source algorithms are Mahony and Madgwick, and those were PhD-level projects.

The complexity grows because in a usual chip-based IMU, the accelerometers are short-term noise-makers, the gyros drift at crazy rates, and there's temperature compensation to consider as well (which is a non-trivial factor). The chip-based MEMS sensors are really driven by the cell phone market, yet their cost leads many to try to bring them into scientific or drone use.

For this question, it will get muddy because I highly doubt that the OP's chassis will remain entirely static in the plane perpendicular to gravity. Even minor roll/pitch will pull that axis into the math.

As such my answer is that the OP is going to have to pursue a more rigorous sensor fusion algorithm. The output of that will expose the gravitational vector, which can then be deducted.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.