Pages: [1]   Go Down
Author Topic: ADXL335 measurements in G's  (Read 1387 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello...

I am working on Arduino mega 2560 (Mega ADK) for my project... and am trying to interface it by ADXL335.
I am getting reading i guess they are in mV...i really want to understand how can i convert them into G's.

For the time being i used the sample code which exists in the arduino software itself...and am going to develop it later to use it in my system.

Thank you in advance for you assistance....and any further information regarding this accelerometer, difficulties you guys faced and things i should take into consideration when am dealing with it....

I would really appreciate if anyone of you provide me with any further information regarding ADXL335

Thank you again
Logged

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

Quote
I am getting reading i guess they are in mV..
Why guess?
Your code should tell you (it doesn't tell us anything, because we can't see it)

Somewhere in the accelerometer's datasheet will be a sensitivity figure, giving the number of counts or mV per g.
That will tell you how to convert mV to ms-2
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.

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

Thank you for your reply smiley

This is the sample code i got from the library, just reading the analog port and display them...
 
Code:
const int xpin = A3;                  // x-axis of the accelerometer
const int ypin = A2;                  // y-axis
const int zpin = A1;                  // z-axis

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

void loop()
{
  // print the sensor values:

  Serial.print(analogRead(xpin));
 
  Serial.print("\t");
  Serial.print(analogRead(ypin));
 
  Serial.print("\t");
  Serial.print(analogRead(zpin));

  Serial.println();
 
  delay(100);
}

I got the clue of how to convert the readings... i will post the reading as soon as i modify the code
Thank you
Logged

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

OK, so the readings are not in mV, they're raw readings.
If you want mV, they you need to multiply the raw readings by 5.0 / 1023.0.
Once you've got that fixed, then you need to plug in the sensitivity value from the datasheet.
There'll also be an offset to be applied, because the accelerations will be +/-, but the accelerometer will only give positive voltages.
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.

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

Regarding the sensitivity values which one should i use (max=330 , min=270 , typical=300) ?
Providing that am using 3.3v to power the accelerometer and the arduino board is powered by I2C cable.

and the offset will be solved by subtracting the zero bias voltage from the voltage i will get in mV , am i right ?
Logged

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

Quote
Regarding the sensitivity values which one should i use (max=330 , min=270 , typical=300) ?
Use the Z axis to calibrate it.
With the accelerometer on a level stable surface, the Z axis should read exactly 1g (or -1g depending on orientation)

Quote
the arduino board is powered by I2C cable
USB, surely?

And yes, the offset is usually half the supply voltage.
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.

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

unfortunately am getting random numbers for all axises (ranging from 197 till 479 )

yes am using USB smiley

I really appreciate your help
Logged

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

Quote
unfortunately am getting random numbers for all axises (ranging from 197 till 479 )
Double check your connections (do your pins match the pins you're reading?) and ensure you've got a solid ground connection between your Arduino and your accelerometer.
Any strong sources of interference nearby?

Maybe concentrate on a single axis.
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.

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

connections are correct...yes you are right the accelerometer is not exactly fixed to a solid ground...i will find solution for that now

if i add capacitors for noise blocking, is that going to affect my readings positively ?
Logged

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

Hey AWOL,

i am getting some steady readings for raw values...and am trying to get the values in G's, but all what i can read are "zeros"

can you please figure out what is the problem:
this programe turn on led if adxl readings in G exceeds 2

Code:
const int xpin = A0;
const int ypin = A1;
const int zpin = A2;
 
int ledpin = 2;
const float power_supply = 5.0;
const float sensor_power_supply = 3.3;
const float zero_bias = sensor_power_supply / 2;

const int threshold_x = 2;
const int threshold_y = 2;
const int threshold_z = 2;


void setup() {
  Serial.begin   (9600);
  pinMode(ledpin, OUTPUT);
  Serial.print ("x axis \t\t");
  Serial.print ("y axis \t\t");
  Serial.print ("z axis \t\t");
  Serial.println();
 
  delay(1000);

void loop() {
 
  Serial.print(analogRead(xpin));
  Serial.print ("\t\t");
  Serial.print(analogRead(ypin));
  Serial.print ("\t\t");
  Serial.print(analogRead(zpin));
  Serial.print("\n\n");
 
  float voltage_x = (analogRead(xpin)) * power_supply / 1023.0;
  float x = (voltage_x - zero_bias) / 320;
  Serial.print(x);
  Serial.print ("\t\t");
 
  float voltage_y = (analogRead(ypin)) * power_supply / 1023.0;
  float y = (voltage_y - zero_bias) / 320;
  Serial.print(y);
  Serial.print ("\t\t");
 
  float voltage_z = (analogRead(zpin)) * power_supply / 1023.0;
  float z = (voltage_z - zero_bias) / 320;
  Serial.print(z);
      Serial.print("\n_________________________________________________________________\n");
  delay(2000);

if ( ( x > threshold_x) ||(y > threshold_y) || (z > threshold_z))
{
  Serial.println();
  digitalWrite(ledpin, HIGH);
  delay(5000);
  digitalWrite(ledpin, LOW);


}
}
Logged

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

Are you saying the raw voltages are zero, or the calculated g values are zero?
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.

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

am getting zeros for G values
Logged

Pages: [1]   Go Up
Jump to: