ADXL335 accelerometer trouble from sunfounder kit

Hello all,

I have a really simple circuit with an ADXL335 axis accelerometer that's giving me erroneous values. I am trying to troubleshoot but falling short. All inputs are correct as directed A0 is x, A1 is y, A2 is Z, gnd is gnd, and Vcc is 3.3V. I am using the arduino uno.

Here are the values in g that I am getting with the accelerometer is horizontal on its Z axis.

x y z
2.34 6.65 -7.78

The code supplied by sunfounder is attached. Can anyone explain what is wrong with this? When I take away the conversions supplied by the tutorial and plot the raw counts, I get about 280 to 420. And if I measure the voltage between each axis and gnd, it is only about 1.4 volts. Am I missing something here? Thanks for the help!

const int xpin = A0;                  // x-axis of the accelerometer
const int ypin = A1;                  // y-axis
const int zpin = A2;                  // z-axis (only on 3-axis models)
void setup()
{
 // initialize the serial communications:
 Serial.begin(9600);
}
void loop()
{
 int x = analogRead(xpin);  //read from xpin
 delay(1); //
 int y = analogRead(ypin);  //read from ypin
 delay(1); 
 int z = analogRead(zpin);  //read from zpin
  
float zero_G = 512.0; //ADC is 0~1023  the zero g output equal to Vs/2
                      //ADXL335 power supply by Vs 3.3V
float scale = 102.3;  //ADXL335330 Sensitivity is 330mv/g
                       //330 * 1024/3.3/1000 
 
/*Serial.print(x);
Serial.print("\t");
Serial.print(y);
Serial.print("\t");
Serial.print(z); 
Serial.print("\n");*/
Serial.print(((float)x - 331.5)/65*9.8);  //print x value on serial monitor
Serial.print("\t");
Serial.print(((float)y - 329.5)/68.5*9.8);  //print y value on serial monitor
Serial.print("\t");
Serial.print(((float)z - 340)/68*9.8);  //print z value on serial monitor
Serial.print("\n");
delay(1000);  //wait for 1 second
}

They are noisy, very sensitive for vibrations, not calibrated.
You should create an offset for every axis, and perhaps a gain correction for every axis.
Can you forget that code please ? It has specific values for a single chip, and the float values are not used, the delay(1) should be removed, and I don't like it.

Use this tutorial : Overview | Adafruit Analog Accelerometer Breakouts | Adafruit Learning System
Note that the Adafruit modules are for 3.3V and 5V. You can't use 5V to power the chip, so keep using 3.3V.

Try a 0.1uF capacitor from VREF pin to GND and the same from each analog pin to GND.
Also, try taking an average of several readings from each channel.

int x;
int dummy = analogRead(xpin);
for(int i = 0; i < 16;i++) 
  x += analogRead(xpin);  //read from xpin
x /= 16;
 delay(1); //

When I take away the conversions supplied by the tutorial and plot the raw counts, I get about 280 to 420. And if I measure the voltage between each axis and gnd, it is only about 1.4 volts.

That sounds about right.

The code below assumes an offset (about 330) and scale factor (about 68) for each axis. Those values must be determined individually, for each accelerometer.

With the correct values, you should get +/- 9.8 m/s, when the accelerometer is held still with each axis is pointed directly up or down. The tutorial linked by Koepel is very useful.

Serial.print(((float)x - 331.5)/65*9.8);  //print x value on serial monitor
Serial.print("\t");
Serial.print(((float)y - 329.5)/68.5*9.8);  //print y value on serial monitor
Serial.print("\t");
Serial.print(((float)z - 340)/68*9.8);  //print z value on serial monitor
Serial.print("\n");