The calibration method is really important.
If you use the 1g numbers for min and max, the only range you will get is 1g.
Any readings out of that range will not display properly.
Finding the range of +/- 1g is important. Add them and divide by two.
That will give you the analogRead() value of 0g, assuming the accelerometer is perfectly level.
The difference between 0g and the min or max is your resolution. How many units read/g.
For an example, on my sensor I get 401 & 611 on the X axis. (I am using external voltage reference @ 3.6v)
Zero g would be at 506. The resolution would be 105.
Multiply the difference of analog reading from 0g by .0095 (1/105 or 1/resolution) and there is your g reading.
Or (analogRead(analog pin) - 506) * .0095
Here is the code I used for calculating g forces while driving.
The orientation of the Adafruit accelerometer: X points left, Y points to the rear.
Arduino orientated natural (USB on left) and accelerometer header pins mounted next to analog pins on protoshield.
WARNING - please do not use alone while driving. Ask a friend to be your Co-pilot or Navigator - WARNING
/*
Designed by AB9VH James Douglas July 2012
Unified Microsystem's ATS-1 LCD Terminal Display Shield
with adafruit 3 axis accelerometer, external 3.3v reference
Shows g forces while driving
*/
int Xaxis = 0; // fresh data from accelerometer
int Yaxis = 0;
int Xcal = 505; // calibration data, zero g
int Ycal = 505;
int key = -1;
void setup() {
analogReference(EXTERNAL); // uses 3.3v from accelerometer for reference voltage
Serial.begin(4800); // opens serial port for LCD shield
Serial.write(1); // clears display and homes cursor
Serial.println(" Automobile ");
Serial.print(" Accelerometer ");
delay(2000);
Serial.write(1);
Serial.println(" Prototype 2012");
Serial.print(" J. Douglas III");
delay(2000);
Serial.write(1); // clear display & home cursor
Serial.println(" Press any Key");
Serial.print(" to start ");
while (key<0) key = Serial.read();
Serial.write(1);
}
void loop() {
Xaxis = analogRead(2);
Yaxis = analogRead(1);
if (Xaxis<Xcal) { // calculate Left & right
Serial.print("Right ");
Serial.print((Xcal-Xaxis)*.0095);
Serial.println("g ");
}
else if (Xaxis>Xcal) { // always display left and right
Serial.print("Left "); // g force as positive value
Serial.print((Xaxis-Xcal)*.0095);
Serial.println("g ");
}
else Serial.println("L/R 0.00g "); // display forward as positive g
Serial.print("Front "); // display rearward as negative g
Serial.print((Ycal-Yaxis)*.0095);
Serial.println("g ");
delay(50);
LCDpos(1,1); // home cursor ATS-1
}
void LCDpos(char x, char y) {
Serial.write(20);
Serial.write(x);
Serial.write(y);
}