Accelerometer without the forces of gravity

Hello

im using an accelerometer (adadruit MMA8451 ) with an arduino uno and am trying to monitor acceleration of a surface that will move axis its not a fixed location.

essentially i need the sensor to read as if its in free fall with out the effects of gravity on it. as when i have it on my table it reads

x = 0m/s^2 y= 0 m/s^2 z = 9.81m/s^2

the code im using includes references to adafruit MMA8541 EXTERNAL Folder (code shwn below

does anyone know how to get the accelerometer to read m/s^2 without the effects of gravity ie free fall

Thanks very much
heres an image f the serial monitor output

Preformatted text
#include <Wire.h>
#include <Adafruit_MMA8451.h>
#include <Adafruit_Sensor.h>

Adafruit_MMA8451 mma = Adafruit_MMA8451();

void setup(void) {
Serial.begin(9600);

Serial.println("Adafruit MMA8451 test!");

if (! mma.begin()) {
Serial.println("Couldnt start");
while (1);
}
Serial.println("MMA8451 found!");

mma.setRange(MMA8451_RANGE_2_G);

Serial.print("Range = "); Serial.print(2 << mma.getRange());
Serial.println("G");

}

void loop() {
// Read the 'raw' data in 14-bit counts
mma.read();
Serial.print("X:\t"); Serial.print(mma.x);
Serial.print("\tY:\t"); Serial.print(mma.y);
Serial.print("\tZ:\t"); Serial.print(mma.z);
Serial.println();

/* Get a new sensor event */
sensors_event_t event;
mma.getEvent(&event);

/* Display the results (acceleration is measured in m/s^2) */
Serial.print("X: \t"); Serial.print(event.acceleration.x); Serial.print("\t");
Serial.print("Y: \t"); Serial.print(event.acceleration.y); Serial.print("\t");
Serial.print("Z: \t"); Serial.print(event.acceleration.z); Serial.print("\t");
Serial.println("m/s^2 ");

/* Get the orientation of the sensor */
uint8_t o = mma.getOrientation();

switch (o) {
case MMA8451_PL_PUF:
Serial.println("Portrait Up Front");
break;
case MMA8451_PL_PUB:
Serial.println("Portrait Up Back");
break;
case MMA8451_PL_PDF:
Serial.println("Portrait Down Front");
break;
case MMA8451_PL_PDB:
Serial.println("Portrait Down Back");
break;
case MMA8451_PL_LRF:
Serial.println("Landscape Right Front");
break;
case MMA8451_PL_LRB:
Serial.println("Landscape Right Back");
break;
case MMA8451_PL_LLF:
Serial.println("Landscape Left Front");
break;
case MMA8451_PL_LLB:
Serial.println("Landscape Left Back");
break;
}
Serial.println();
delay(500);

}

Welcome to the forum! Your question shows up frequently.

Since the accelerometer cannot distinguish the acceleration due to gravity from those due to other forces, you need to subtract the (calculated) gravity vector from the total.

To do that accurately requires you to know the 3D orientation of the accelerometer to within about 0.1 degree, which is not practical in most cases.

Please edit your post to add code tags.

Thanks for your reply !
could you link one of those threads i cant seem to find them, do they get deleted ?

im unsure to how to link the code tags how do i so that ?

Before you even consider starting to write code, you must first solve the two vector math problem.

I'm not sure you have enough information to solve the problem but let me state it first. Then I suggest you find a math forum to ask the "experts" in this sort of problem.

The Information you have:

  1. Total vector definition of the current state of the accelerometer.
  2. Amplitude / length of the gravity vector.

You need:

  1. Coordinates of the non-gravity vector.

I think you may have too many unknowns for the information you have. If I'm correct there may not be a unique solution. So as I said you should post the question (in a non related to Arduino way) in a math forum. Perhaps StackExchange.

Just thinking out loud:
Assume gravity = 1040 (its best to stay with integers until you have to go to floats)

Measurement x = 41, y = 24, z = 1027
Gravity x1 = ?, y1 = ? , z1 = ?
But we know; 1040 = √(x1²+ y1² + z1²) therefore 1040² = x1² + y1² + z1²

Its been too long ago since I had to try to solve the above, but its at least a start.

John

1 Like

Hi John
thanks for your reply

would it be possible for the Accelerometer to give me an angle of orientation reading which i plug into another part of the code where theres a formula that would give me a number to subtract from the x y or z number depending on the orientation of the accelerometer so when its not moving it would be x = o m/s^2 , y = o m/s^2 , z = = o m/s^2. or would this take to long for the Arduino to complete and cause it to be inaccurate?

many thanks
Rian

Yes and no. You can read about the problem here: Using Accelerometers to Estimate Position and Velocity | CH Robotics

But in short, it is not practical to do what you want with consumer grade accelerometers. They are too inaccurate and noisy.

To learn about code tags and for hints on posting, please read and follow the instructions in the "How to get the best out of the forum" post, linked at the head of every forum category.

oh i see, do you have any possible solutions to get around this issue ? or a different way of measuring without gravity?

What do you actually want to do? This sentence is gibberish:

am trying to monitor acceleration of a surface that will move axis its not a fixed location.

It helps a lot if you also have a 3 axis magnetometer. Then you do know the absolute orientation.

Yes it is possible, however the " another part of the code where theres a formula" is what is unknown at least to you and I. This is the part you must ask of a math forum.

If you are worrying about coding the resulting formula, that we/I can help you with. But the mathematical process needs to be defined.

Its been said it he above is not possible with consumer grade accelerometers. I have not project experience with this type of device. However if you are not in a dynamic situation then you should collect some data and see how stable your sensor is.

sorry yea i am trying to monitor vibration at the hand so its not fixed in any orientation.

i think this may be incorporated into the accelerometor already but im not 100% sure

yea the formula is (square root( AX * AX + AY * AY + AZ * AZ ) - 9.8)
AX = Angle of x plane
AY = angle of y plane
AZ = Angle of z plane
what command would i use to get the angle of the planes in degrees ?

Handy tutorial on measuring the two tilt angles: How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing-DFRobot

I'm not sure here but perhaps you could look for the change in X,Y,Z.

This website might be of some use. 3D Vectors

spherical trigonometry

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.