Go Down

Topic: Acclerometer readings to G readings (Read 996 times) previous topic - next topic


i have a question about the accelerometer sensor.
I am using the ADLX335 3 axis accelerometer.

When i connect it to the Arduino UNO using the following code
Code: [Select]
const int xpin = 0;
const int ypin = 1;
const int zpin = 2;

void setup()

void loop()
  Serial.print("X"); Serial.print(analogRead(xpin));
  Serial.print("Y"); Serial.print(analogRead(ypin));
  Serial.print("Z"); Serial.print(analogRead(zpin));

I get the following results to the serial output

my question is how to convert the analog reading of for example X: 340 Y: 369 Z: 413 to G force readings
I don't want to do the calculation on the arduino but on the computer.

I am new to this and i was searching all day but i couldn't find any clue.



Jul 17, 2011, 05:39 am Last Edit: Jul 17, 2011, 06:30 am by cyclegadget Reason: 1
I have that sensor but, I am still working on getting correct "G" readings. The way I have it figured is that the max analog value at 3.3v would equal 676.5 and the min. would equal 0.

So the scaling should be:
3G = 676.5
0G = 338.25
-3G = 0

I was able to get analog readings that looked to be correct. However, when I was trying to use the Map function and I must have been doing something wrong because my readings were all zero.

I hope this is at least some help,
Good links: Eagle tutorial= http://www.youtube.com/playlist?list=PLDE1858BD83D19C70
General Arduion tutorials = http://tronixstuff.wordpress.com


I tried but at some point i have readings up to 707 for all the axis


Have you verified that gravity is working correctly where you are?

0g should correspond to half the supply voltage.
So, assuming a 3.3V supply, 3.3 / 2 = 1.65V
If 5V is full scale, 1.65 / 5 * 1023 = 337.
So, 340 and 369 are not too far away for x and y, assuming the device is roughly horizontal.
Now, somewhere on the device's datasheet there is a figure for sensitivity, expressed in "mV / g" probably.
Apply that to your z (gravity, acting downwards) value, and you have your conversion.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.


Per the adxl335 datasheet, typical sensitivity is 300mV/G.

The Arduino uses a 10bit A/D, which is 1024 values.  If you're using a 3.3V reference, that's 3.3/1024 = 3.22mV per LSB (as in,3.22mV change in voltage per increment of the A/D output).

So, to convert Arduino output value into G values...

Val * 3.22 = input voltage.
(Input voltage - offset)/.3 = G force.
(Val * 3.22 - offset)/.3 = G force.

Now, there's a couple things you need to understand about these low cost accelerometers.  They are neither accurate or precise.  You'll need to perform some sort of calibration to increase accuracy, and some form of averaging/filtering to increase precision.  What sort of calibration/averaging/filtering you need to do depends on how accurate and precise you need your measurement to be.


Jul 18, 2011, 09:36 pm Last Edit: Jul 18, 2011, 10:10 pm by AWOL Reason: 1
Per the adxl335 datasheet, typical sensitivity is 300mV/G

... but is ratiometric to the supply voltage.

If you're using a 3.3V reference

There's nothing in the code posted above to suggest that this is the case.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Fabio Varesano

You can have a look at my thesis, section 5.4.3 Reading data from the ADXL330 (which is just as the 335). You can also find there many good info on orientation sensing and sensor fusion with tones of references.. so you may find it useful.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131