Pages: [1]   Go Down
Author Topic: Acclerometer readings to G readings  (Read 802 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 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
  
« Last Edit: July 16, 2011, 11:30:38 pm by cyclegadget » Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This article might help http://didier.longueville.free.fr/arduinoos/?p=1389
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 308
Posts: 26452
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

New Hampshire
Offline Offline
God Member
*****
Karma: 17
Posts: 781
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 308
Posts: 26452
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: July 18, 2011, 03:10:28 pm by AWOL » Logged

"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.

Torino, Italy
Offline Offline
Sr. Member
****
Karma: 2
Posts: 309
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: