Go Down

Topic: Accelerometer Displacement (Read 1 time) previous topic - next topic

bebo_stunner

Hi

I have a Tinker-kit accelerometer connected to my arduino, I am able to read a value for acceleration in both the X and Y axis as i move the sensor.

I need to find the value of displacement which requires the acceleration to be integrated twice, does anybody have any information on a method to do this?

PeterH

You would do this by numerical integration.

The change in speed over a time interval is the average acceleration multiplied by the duration. This is very convenient to evaluate iteratively:

Code: [Select]

currentAcceleration = readAcceleration();
averageAcceleration = (currentAcceleration + previousAcceleration) / 2;

currentSpeed = previousSpeed + (averageAcceleration * duration);
averageSpeed = (currentSpeed  + previousSpeed) / 2;

currentDisplacement = previousDisplacement + (averageSpeed * duration);

previousAcceleration = currentAcceleration;
previousSpeed = currentSpeed ;
previousDisplacement = currentDisplacement;


You would need to execute that code periodically. The blink without delay example shows how to do that.

You will need to deal with scaling according to the units that you're using for acceleration, speed, distance and time.

Go Up