Having problems with accelerometer readings

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);

Hint: what are the raw values?

I think that the raw values represent the raw accelerometer data from each axis?

No, what are their values?
Aka, why don't you print then? That might provide you with a clue of what is going on.

I see, so instead of printing the scaled values should I print the raw ones? Or both?

Just printing the raw values should point you towards your problem .

(You get five minutes between posts - you could have tried it by now)

I suspect the magic value "675" is wrong. :slight_smile:

Is your accelerometer running on 3.3V and the Arduino running on 5V? You can get better resolution if you connect the 3.3V power to the ARef pin and add analogReference(EXTERNAL); to setup(). Then your full-scale reading would be 1023.