# Obtain Velocity and displacement from acceleration readings

I'm trying to obtain the velocity and displacement of the sensor over time using the LSM9DS1, the problem is that I do not seem to get the right velocity or any displacement.
Below is the code I am using to try and get the speed and displacement in the x direction with a dt of 0.05 seconds.

Please use code tags to post code, not an image, and post ALL the code. For instructions, read the “How to get the best of the forum” sticky.

I will guess that the first computation was intended to be

``````dv = a*0.05;
``````

but the integration won’t work because the variables dv, v, dx and x are declared anew every time the loop() function runs.

What do you think are the units of the measurements?

Obtaining distance and velocity from acceleration is likely to be very inaccurate .
Eg if you have a constant velocity there is no acceleration, so the velocity can drift or be affected by any transducer noise

jremington:
Please use code tags to post code, not an image, and post ALL the code. For instructions, read the "How to get the best of the forum" sticky.

I will guess that the first computation was intended to be

``````dv = a*0.05;
``````

but the integration won't work because the variables dv, v, dx and x are declared anew every time the loop() function runs.

What do you think are the units of the measurements?

Yes you are correct, for the first computation being dv = a * 0.05.
I created a while loop containing the acceleration readings, velocity and dislacement calculations and displaying so that the variables aren't declared anew at every iteration.
The readings of the accelerometer are in meters per second squared.
The values I now get for velocity and displacement drift from the actual values.

hammy:
Obtaining distance and velocity from acceleration is likely to be very inaccurate .
Eg if you have a constant velocity there is no acceleration, so the velocity can drift or be affected by any transducer noise

Is there any way to reduce this noise/drift to obtain relatively accurate values?

pwvsviper:
Is there any way to reduce this noise/drift to obtain relatively accurate values?

Not really, these MEMS devices are very rough and ready sensors. You pay real money for precision
accelerometers. In particular displacement drifts quadratically and over even moderate periods of time
becomes completely unusable from a MEMS sensor.

Cheap IMU's combine multiple sensor types to get good data, such as accelerometers and GPS, which
together can have the accuracy of GPS but the speed of response of the accelerometer.

In anything in 2D or 3D you need a gyro sensor too to compensate for rotation, only in a 1D situation can
you get away with just an accelerometer to determine position even on a small timescale.

Is there any way to reduce this noise/drift to obtain relatively accurate values?

Yes, but the sensors required to do so cost tens of thousands of \$.