ADXL335 accelerometer troubles

Hi, I have an Arduino Duemilanove and a ADXL335 accelerometer with a Spark fun breakout board. Im having a fair bit of trouble getting any meaningful data out of the chip. It seems to be telling me things that defy the laws of physics as well as constantly fluctuating up and down randomly. I want to get the value in g's so i can use it as a tilt sensor. it will not have to ever deal with moving around or anything so it can take as long as it likes to output an accurate reading.

Im connecting the x.y,z pins to analog inputs 0,1 and 2. also vcc to 3.3v and Gnd to Gnd.

here is the code im using:

const int xpin = 0;
const int ypin = 1;
const int zpin = 2;// analog: Z axis output from accelerometer
 
const float arduino_power_supply = 5;
const float sensor_power_supply = 3.3;
const float zero_g_bias = sensor_power_supply / 2;
  
void setup() {
  Serial.begin   (9600);
  Serial.print ("x axis g's");
  Serial.print ("\t");
  Serial.print ("y axis g's");
  Serial.print ("\t");
  Serial.print ("z axis g's");
  Serial.println();
  delay(1000);
}
void loop() {
  float voltage_x = (analogRead(xpin)) * arduino_power_supply / 1024;
  float x = (voltage_x - zero_g_bias) * 1000 / 330;
  Serial.print(x);
  Serial.print ("\t");
  
  float voltage_y = (analogRead(ypin)) * arduino_power_supply / 1024;
  float y = (voltage_y - zero_g_bias) * 1000 / 330;
  Serial.print(y);
  Serial.print ("\t");
  
  float voltage_z = (analogRead(zpin)) * arduino_power_supply / 1024;
  float z = (voltage_z - zero_g_bias) * 1000 / 330;
  Serial.print(z);
  
  Serial.println();
  delay(200);
}

When i run that code on a perfectly vertical surface i get the following output(which makes no sense)

x axis g's      y axis g's      z axis g's
3.53      3.45      4.04
3.61      3.06      2.98
1.95      1.68      0.80
0.60      1.21      1.08
0.62      0.85      1.50
1.47      0.86      1.03
1.91      1.61      0.86
0.88      1.09      0.62
0.33      0.55      1.03
0.25      0.16      0.67
0.85      0.44      0.21
1.09      0.93      0.25
0.62      1.09      0.78
0.18      0.39      1.11
0.51      0.08      0.44
1.01      0.70      0.10
0.96      1.08      0.59
0.36      0.62      1.01
0.25      0.20      0.73
0.44      0.96      0.90
0.12      0.33      0.96
0.82      0.16      0.31
1.14      0.83      0.13
0.47      1.03      0.75
0.13      0.34      1.06
0.59      0.08      0.38
1.04      0.73      0.07
0.88      1.12      0.68
-0.03      0.20      0.55
-0.44      -0.42      0.12
0.39      -0.05      0.12
0.07      -0.16      -0.58
0.85      0.72      0.23
0.65      1.03      0.93
0.05      0.16      0.57
-1.81      -2.29      -1.98
-0.55      -1.01      -0.86
0.23      0.00      -0.50

I have been searching the internet for the last 6 hours and come up empty. the turial on this website for the 3xx's series of accelerometers has the same problems.

Any help would be hugely appreciated.

thanks in advance,

Matt:)

Hi buddy i am also facing same problem, searched alot on the net but didn't get any thing supportive, i decided to try these tacts
1.It would be good idea to take an average reading (say 100) of output, by putting for loop. in the skech.

  1. by putting 100nf capacitor, to avoid flucuation in out put voltage,

plz let me know if you get any other idea.

Hey, I found that i was using some dodgy soldering which was causing the chip to not really be connected to my board when i thought it was which was causing all the confusion.

As i need mine to be pretty accurate im now focusing on how to get 3v(not 3.3V) out of my arduino board. while 3.3v will get it working fine(not 5V!) the data sheet lists no scaling factor for that voltage.

using a average is defiantly a good idea. let me know how you go with using a cap, what advantage would that have over software averaging? I can imagine that in some circumstances it would not be good (detecting sudden quick movements) but as i am trying to make a static tilt sensor it doesnt sound like a bad idea.

Matt:)

while 3.3v will get it working fine(not 5V!) the data sheet lists no scaling factor for that voltage

Scaling for what?
The device is ratiometric, is't it?

Yes but the ratio changes for different voltages non linearly and is only 300mV/g at 3V. at 3.7V it is 330mV/g. but no relationship to indicate the relationship is linear is given.

From the datasheet.

The ADXL335 output is ratiometric, therefore, the output sensitivity (or scale factor) varies proportionally to the supply voltage. At VS = 3.6 V, the output sensitivity is typi- cally 360 mV/g. At VS = 2 V, the output sensitivity is typically 195 mV/g.

BTW, the bandwidth-limiting capacitors are very important.

yea i understand that it is ratiometric but how can you work out what the ratio is at 3.3V when the data sheet only tells you the ratio the output follows at 3.6V(and 2V). while the output follows a linear relationship with input(ratiometric) we don't know what that ratio is at any other voltage other then those it lists in the data sheet. no relationship between the ratio and input voltage is given(as far as i can tell).

Sorry i got my values mixed up but it doesn't change what im trying to say.

Im new to all this but i think im reading this right.

Also i think he was talking about caps to 'smooth' out the voltage output from the chip. Im not sure how exactly that would work but i don't think he was talking about the bandwidth setting ones(which are soldered straight on the breakout board i have anyway)

:)Yea sure idea of using a cap is for smoothing the surge; it has nothing to do with band width. congrates you got finally what you wanted,

how can you work out what the ratio is at 3.3V when the data sheet only tells you the ratio the output follows at 3.6V(and 2V)

I would start with a typical value of 330mV/g (supply voltage /10).

from the datasheet

2 Sensitivity is essentially ratiometric to VS.

My accelerometer is still giving inconsistent reading, implemented this codes to filter the reading, it takes 20 readings > sortes them in ascending order > takes 10 readings from sample[5] to sample[15].

anybody with some good idea ???? :cry:

for(i=0; i < 20; i++) // take 20 sample readings
{

sensorValue = analogRead(analogInPin); // read the analog in value:

sample = 0.75*( 220 - sensorValue); // considering 220 is value at Horizantal position

}

*for(i=0; i < 20; i++) // BUBBLE SORTINHG *

  • for(j=0; j < 20; j++)*

  • {*

  • if( sample[j] > sample[j+1])*

  • { temp = sample[j];*

  • sample[j] = sample[j+1];*

  • sample[j+1] = temp; *

  • }*

  • } *

  • for ( i=5; i <= 15; i++) // sum of angle values from*
    _ angle = angle + sample*;*_

* angle = angle/10; // Average[/code]*

i also have the same problem with you guys. i am using 2 axis accelerometer that is memsic 2125. the output is in PWM.

as for now, my problem is the accelerometer keep changing output data. inconsistent whilst the accelerometer is static. after ive researched some in the internet, i manage got some clues that are

  1. using op-amp to filter the noise - but i didnt really sure
  2. using capacitor and resistor to filter the noise.
  3. using averages. same as above, i also thinked about that. because it didnt need any hardware, just programming.

so friends, how we can tackle this problem?

If it's PWM output from the accelerometer, 1) and 2) aren't going to help.

Make sure your supplies are decoupled.

ooh i see. so can i go for the third option? but i rally confused on how the coding is.. :cry:

Easy buddy........here is the complete code. . . . . . . :sunglasses:

sombody plz let me know hot to insert an image in a Post/Reply :-[

/*
  Analog input, measures angle 
  created 16 may 2010
  by Ehkrap Tnahsarp

*/


const int analogInPin = 0;  // Analog input pin that the potentiometer is attached to
float sensorValue = 0;      
int angle = 0;
int sample[20]; 
int i, j, temp;


void setup() {
  
  Serial.begin(9600);       // initialize serial communications at 9600 bps:
  
  }


void loop() {
        
  for(i=0; i < 20; i++)                   // take 20 sample readings
{  

  sensorValue = analogRead(analogInPin);  // read the analog in value:    
  
  sample[i] = 0.75*( 220 - sensorValue);     //  considering 220 is value at Horizantal position
  
}


                                            
 for(i=0; i < 20; i++)            // BUBBLE SORTINHG puts readings in ascending order     
      for(j=0; j < 20; j++)
      {
        
        if( sample[j] > sample[j+1])
         {   temp = sample[j];
            sample[j] = sample[j+1];
            sample[j+1] = temp;            
         }

      }   
      

 for ( i=5; i <= 15; i++)      // sum of angle values eleminating first five and last five

 angle = angle + sample[i];    // inconsistance readings
 angle = angle/10;            // Average of angle
      
  
  Serial.print("\t angle = ");      // Print the output
  Serial.print(angle);  
  
  
} // end of loop

Instead of looking at the output after averaging the samples try printing just the ADC value (0-1023) and see if that number is stable, if not then the problem maybe in your calculations. If that number is not stable then just connect a volt meter directly to the output of the ADXL335 and verify if the voltage is steady.

Heres what i did which i think is simpler,

  • put your accelerometer on a breadboard and align it so that the x axis reads 1g and look at the count number.

  • flip it 180º (to read -1g) and again look at the count number being outputted. Now you have two numbers to give you a range, in my case 404 and 269.

  • the difference here between -1g and 1g is 135 counts.

  • divide this by 2 and you get 67.5 counts/g .

  • Analog AD count = 5v/1024 = 4.883mV (assuming the arduino is being supplied 5v exactly).

  • Multiply 65.5 counts/g by 4.883mV to get resolution. Here we get 329.6mV/g for 3.3V!!

  • Repeat this for each axis to get more accurate results. I got 329.6mv/g for the x axis, 329.6mv/g for the y axis, and 327.161 mv/g for the z axis.

*To double check this we know the data sheet gives us:

Vs Resolution Slope(Resolution/Vs)
3.6V 360mV/g 100
3.0V 300mV/g 100
2.0V 195mV/g 97.5

3.3V 329.6mV/g 99.879

if we were to plot this Resolution vs Vs we could see that the slope is constant therefore giving us a linear relationship between different values for Vs and proving our method to be right.

I looked everywhere to figure out how to get g value to output from the sensor at 3.3v and found nothing so i hope this helps.

-Alan

*also, for the guy having trouble with the memsic 2125, that accelerometer is a bit different, it works with heat and thermistors and is a digital accelerometer. what you have to do is measure the pulses it outputs using "pulsein" i think, there is an example sketch on the memsic 2125 in the arduino IDE under "sensors" take a look at that.

I am experimenting with this sensor too (the adxl335) and I never understood how to read the values correctly. I have done this, for now, with the map() function...