# Speed calculation using Accelerometer

I am using ST manufacture Accelerometer(LIS2DE12) and i making a small hobbyist project for me. For this I am using ST-Microcontroller and developing the C code i am using KEIL V5 IDE. Configured the Accelerometer with normal modes, having the Data rate frequency of 200Hz and +-2g as the measurement range. (If some one needs to get the full details or configuration then let me know i will share, to solve these issue) For calculating the speed i am using the velocity formula v = u + at. After developing this equation code i am getting wrong and continuously increasing velocity without moving the accelerometer. I don't know why this issue is for.

Waiting for the positive replies ....

Thanks Sachin

• Look at "Related" to the right of the screen. They should've popped up when you were making this question. – Harry Svensson May 30 '18 at 8:43
• I have checked on the right side of the screen with similar queries, but I didn't found the query related to my question ... – SACHIN RAJPUT May 31 '18 at 5:24
• The second link shows that it gives a lot of errors. Here's some more questions very related to yours. Among them this one exists where yet again, the problem is always the errors. Also known as drift. Time and time again it will be proven that using an accelerometer for acquiring the speed and/or displacement won't work that good. – Harry Svensson May 31 '18 at 6:10

You really can't calculate speed from accelerometers, in practice.

The accelerometer is actually just a gravity-tilt sensor when used on earth.

Any error is a tilt error.

Now imagine you have an absolutely flat, horizontal formica table with a ball bearing sitting on it. Your error is just like putting a couple of coins under the legs at one end, and tilting it ever so slightly.

After a couple of seconds the ball bearing is shooting off the edge of the table at speed.

This is exactly what is happening to you.

• "You really can't calculate speed from accelerometers.", that's only true for long periods of time. You can use them to calculate speed for short bursts. Such as slamming the accelerometer on the table, then you can calculate the speed it was moving at just prior to the slam. – Harry Svensson May 30 '18 at 8:47
• @HarrySvensson While I would theoretically agree, I struggle to think of any practical case where the OP's acc can give a useful speed over some useful time frame, without significant help from other sensors. Well there is one excellent scenario where they do work. If you throw your phone up it the air, they can calculate the speed it hits the ground at quite well. But thats not a speed sensor application really. (one of my customers uses them to measure how far equipment falls during air-freight. The answer is all the way from the cargo door to the tarmac) – Henry Crun May 30 '18 at 9:03
• "I struggle to think of any practical case where the OP's acc can give a useful speed over some useful time frame", me too. - I fully agree with you except for the top paragraph in your answer. – Harry Svensson May 30 '18 at 9:08
• I kind of agree with you (that it is a too-strong assertion of a not-strictly-true fact), but as I can't really think of a working practical case, the sentence seems to be true. (for the OP's level) – Henry Crun May 30 '18 at 9:14

This is most likely because the accelerometer is not perfectly accurate. Means a static accelerometer will still give you some small output. Print out the raw values of the accelerometer to get a rough estimate of the error. Further you have to consider that gravity will always be measured, so you have to compensate for that. Can the accelerometer be rotated around the axes so that gravity will not always affect the same axis?

To calculate the speed, the initial speed is quiet important (if not, the error will be present the whole time), because (as you said) the accelerometer provides the speed variation.

Another problem is the integration, to calculate the speed you have to integrate the acceleration (and estimate the constant), so the error in your system will be added continuously, hence the error will grow up.

To reduce these problems, I would add more information to your system, such as gyroscope, gps(obviously), magnetometer... and a proper algorithm to mix all the information (Kalman filter is well known for these purposes). It doesn't mean that your system will work without failures, but it may work so much better.

• Yes @Jose Felipe you are right ... after some search it's show that we can use(as per suggestion) such as gyroscope, gps & all .... I am trying and exploring it .... Thanks – SACHIN RAJPUT Jul 6 '18 at 8:42

The constant increasing velocity is due an acceleration offset, most likely the sensor is not precise aligned with the Z axis and a small g acceleration goes to X or Y axis.

You could sample all axis to detect the misalignment but unfortunately the 8 bit resolution is to low for that, you can have up to 22 units on the horizontal axis without any change on Z axis. simulate this circuit – Schematic created using CircuitLab

The sensor is not suited for such application

I'm sorry, I cannot give a positive reply.

• "The constant increasing velocity is due an acceleration offset, most likely the sensor is not precise aligned with the Z axis and a small g acceleration goes to X or Y axis" Yes you right here i am not getting constant values from sensor, also it was of 8 bit sensor for these question 8 bit will not sufficient, these thing I come know from your reply ... – SACHIN RAJPUT Jul 6 '18 at 8:38