Go Down

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

cystavros

Hi,
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()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.print("ACC");
  Serial.print("X"); Serial.print(analogRead(xpin));
  Serial.print("Y"); Serial.print(analogRead(ypin));
  Serial.print("Z"); Serial.print(analogRead(zpin));
  Serial.println();
  delay(50);
}


I get the following results to the serial output
ACCX340Y369Z413
ACCX341Y370Z415
ACCX342Y370Z414
ACCX342Y370Z413
ACCX341Y370Z414

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.

Thanks

cyclegadget

#1
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,
Mark
 
Good links: Eagle tutorial= http://www.youtube.com/playlist?list=PLDE1858BD83D19C70
General Arduion tutorials = http://tronixstuff.wordpress.com
http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=123


cystavros

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

AWOL

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.

jraskell

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.
Or:
(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.

AWOL

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

... but is ratiometric to the supply voltage.

Quote
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