Linear Acceleretion Measurement

Hello guys! I am trying to use the linear acceleration data to calculate the velocity. However, as far as I know, when I review the linear acceleration data, it doesnt seem correct.

I am using Esp8266 and Mpu6050 sensors.

Please find my code enclosed below in the attachment.

Here is the results(Yaw data you see blow is actually acceleration of x axis.(I modified the code)It supposed to be around 16000-17000 when the sensor is held parallel to the ground.(The sensor is fixed and parallel to the ground, however, these values come.))

YAW: -2982 PITCH: -44.59 ROLL: -15.80 AX: 19045 AY: 8543 AZ: -20649
YAW: -814 PITCH: -4.19 ROLL: -9.88 AX: -216 AY: 1404 AZ: -8047
YAW: -4929 PITCH: -23.58 ROLL: 66.06 AX: 7040 AY: -27342 AZ: -2010
YAW: 648 PITCH: -79.63 ROLL: -10.37 AX: -5713 AY: 10829 AZ: -35
YAW: -19862 PITCH: 0.00 ROLL: 0.22 AX: -19862 AY: 0 AZ: -8
YAW: -19646 PITCH: -20.81 ROLL: 7.21 AX: -16098 AY: -1252 AZ: 9252
YAW: 0 PITCH: 34.74 ROLL: -54.92 AX: -22613 AY: 32469 AZ: 2961
YAW: -15441 PITCH: -11.88 ROLL: -10.80 AX: -15038 AY: 366 AZ: -1877
YAW: 16304 PITCH: -10.31 ROLL: -48.17 AX: 21931 AY: 23431 AZ: -20203
YAW: -757 PITCH: -34.03 ROLL: -43.63 AX: -712 AY: 54 AZ: -36

As I mention above, these values are achieved when the sensor is fixed. How can I solve this problem? I also changed the offset values, using another programme which detects the offsets but it didnt work.

Thank you very much for your helps!

ArduinoIMU.ino (10.6 KB)

Is there anyone who can help me? Actually I am trying to remove earth gravity from the accelerometer data so I can calculate the velocity. Can someone please show me a way to do it?

If the accelerometer X (or Y) axis is always parallel to the Earth's surface, then you have a small chance that your efforts will work.

If not, you will need quite sophisticated software to remove the estimated gravity vector from the total acceleration, and this blog article explains why that will not work with consumer grade IMUs.

X and Y they are both parallel to the ground. I've managed to calculate linear acceleration using Rowberg's library and I removed the gravitiy vector from the linear acceleration. Is my process true?

If X and Y are perfectly parallel to the ground, the acceleration due to gravity should not affect the X and Y acceleration values.

In that case, there is nothing to remove, and you can integrate the X or Y acceleration to estimate the change in X or Y velocity during the integration period.

But, when I tilt the sensor up or down, raw data of acceleration Y changes. So I needed to remove it. Can you please send me an article that includes how to integrate acceleration to get velocity?

Google "numerical integration" for overviews.

Did you read the link in reply #2, explaining why your approach won't work?

Yes I’ve read it. If you can show me an idea how to detect forward movement, using mpu6050, I appreciate. The problem is the sensor wont be fixed. Its going to be put on a sheep’s neck and we would like to detect that the sheep is walking/running or not. How can I detect it with mpu6050?(As you can imagine, when the sheep starts moving, its gonna start moving its neck towards up and down as well, while its running or walking.) Hopefully, you understand what we want to do.

To detect motion is easy. Just read out the three acceleration variables ax, ay and az, and calculate the magnitude of the total acceleration = sqrt(axax + ayay + az*az).

When that value is significantly different from the static value (the acceleration due to gravity), then the sensor is accelerating.

According to your calculation, if the sheep moves its neck, we would calculate and determine that sheep is walking. Whereas, the sheep only moved its neck. Its not walking or running. In sum, even if the sheep moves its neck, we are going to say that the sheep is walking or running, regarding your calculation. We are just trying to understand whether it is a neck movement or a sheep walking. This is what we need to detect.(Estimating only forward-backward motion not up-down or left-right)

In addition to that, what do you mean saying significantly? Can you please give me a pratical sample? What is the meaning of "significantly different" for this system? between which values? How much far away from the acceleration data? If its possible to give me a real example, I'll have these all questions answers.

According to my calculation, you can determine whether the sensor is accelerating. How you relate that to a sheep is entirely up to you.

To determine what sensor readings might be significant, collect sensor data under a number of circumstances and calculate the magnitude of the acceleration as described in reply #8.

There will be some variations in the acceleration magnitude due to noise, and some due to "significant" accelerations (other than gravity).

Again, it is up to you to decide the difference. It will be helpful to use the Arduino serial plotter to view the data.

Thank you for your reply.

So how can I detect only forward-backward motion?

Thank you!

You need set up an accelerometer with an Arduino, and learn how it actually works.

Forget printing out yaw, pitch and roll and just look at the acceleration values, as well as the magnitude from reply #8.

Am I going to do this linear acceleration data or normal acceleration data? What do we except exactly? I calculated the magnitude and acceleration Y data and printed out them on plotter, however, I dont know what needs to be or what the expectation is.

Here is the results... Blue->Acceleration of Y axis, Red->Magnitude

or what the expectation is.

You need to understand what the sensor is actually measuring. Forget the invented term "linear acceleration".

When held still, the sensor measures the acceleration due to gravity. When not still, other accelerations add to or subtract from the acceleration due to gravity.

If the sensor is held still with Y is pointing down or up, what do you get?

What happens if Y is horizontal?

If you accelerate the unit (by hand) along the Y axis, what do you get?

I am so sorry that I can not understand. I am new with Arduino and I have no idea what I get. You please need to explain me.

Thank you!

Sorry, this project appears to be too advanced for your present skills. You will need to do a lot more background reading.