 # Accelerometer Data

Hello.

Me again! :)

I have been playing around with an acclerometer (ADXL335). The program is below

``````//----------------------------------------------------//
const int x = 0;
const int y = 1;
const int z = 2;

//Variables for holding values for each axis
int accelx, accely, accelz;

void setup()
{
Serial.begin(9600);
pinMode(x, INPUT);
pinMode(y, INPUT);
pinMode(z, INPUT);
}

void loop()
{
//Read the analog values from the accelerometer

//Print out values
Serial.print(accelx);
Serial.print("\t");
Serial.print(accely);
Serial.print("\t");
Serial.print(accelz);
Serial.println();

delay(2000);
}
``````

And, the data I get while it is sitting on my desk is

x y z 403 332 343 403 332 343 402 332 343 403 331 343

And so on.

But what does this data mean, and how do I change it to acceleration? I have been told, since my accelerometer is a 3g accelerometer, when I move it in, say, the x direction, the numbers should go one to about a third of 1023. I this correct? And, when I do move it in that direction, it goes to 339. So that theory holds.

Seán

You should be able to find a configuration by tilting / rotating the sensor so that when it sits still on your desk it only gives output on one channel (the other two reading zero, or very nearly zero). The channel with non-zero output is now measuring the gravitational acceleration due to the earth which is 9.8 m/s/s (or 1g, depending on the units you want to use), so now you have your calibration constant.

It’s likely that each channel will have the same calibration constant, but you can rotate it to zero out different channels to verify the calibration for each.

EDIT: on closer inspection of the data sheet, it appears there is a bias voltage at 0g, so looking for a 0V output as I suggested would not work. You’ll have to use the orientation diagram in the datasheet to align an axis with vertical, then record the non-vertical axes output as the offsets for those axes. Then rotate the device so a new axis is vertical, get that reading, subtract the offset you just measured, and now you can calibrate. (disclaimer: I haven’t actually worked with these devices so there may be a gap in my understanding, but I’m sure someone more knowledgeable will jump in if I’m wrong.)

tedcook: You should be able to find a configuration by tilting / rotating the sensor so that when it sits still on your desk it only gives output on one channel (the other two reading zero, or very nearly zero).

But when I have it sitting still on my desk, it is reading the figures I listed in the original post.

i.e. x y z 403 332 343 403 332 343 402 332 343 403 331 343

Seán

Did you see the edit to my original response?

Ha, sorry, my bad …I did kinda gloss over the first line.

I’ll try and figure it out. Thanks.

So, when I remove the offset, is that the acceleration? Or is there still more work needed?

Seán

If you properly subtract the offsets, what's left is proportional to the acceleration. As a check to know if you subtracted your offsets correctly, calculate the magnitude of the acceleration [ sqrt(x^2 + y^2 + z^2) ]. It should be the same despite any arbitrary orientation whenever the device is at rest.