Hi, I'm fairly new to Arduino and I'm working on a project with an accelerometer, and I'm having some problems with the readings.
I'm using the ADXL337.
My Z value reads at 0 g when the accelerometer is still, yet my X and Y values read at -1.
Unless this is how it is supposed to be, I'd like them all to start at zero.
Here is my code. I would appreciate any help! Thanks.
float scale = 3;
void setup()
{
Serial.begin(115200);
}
void loop()
{
int rawX = analogRead(A0);
int rawY = analogRead(A1);
int rawZ = analogRead(A2);
float scaledX = map(rawX, 0, 675, -scale, scale);
float scaledY = map(rawY, 0, 675, -scale, scale);
float scaledZ = map(rawZ, 0, 675, -scale, scale);
Serial.print("X: "); Serial.print(scaledX); Serial.println(" g");
delay(140);
Serial.print("Y: "); Serial.print(scaledY); Serial.println(" g");
delay(140);
Serial.print("Z: "); Serial.print(scaledZ); Serial.println(" g");
delay(140);