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
}