I recently bought me a MMA7260QT 3-Axis Accelerometer, and have not found much documentation on the device. I did find a quick start guide at Liquidware.com, which is a great starting point, but thought something with a little more substance was in order.
So I hooked it all up, the 3.3v pin on the breakout board to the 3.3v on the Arduino and the GND to GND. Now because this is not a digital sensor but an analog sensor I hooked x to analog in 1, y to 2, and z to 3. I also connected GS1 to GND and GS2 went to 5V. This is the basic set up.
When I started coding using the LiquidWare tutorial I realized I needed a way to calibrate the unit, to basically have a resting point for the analog inputs, so I added a momentary button to digital pin 7. When the button is pushed and held for approx. 3 seconds the Arduino reads all three analog inputs and creates a min reference and a max reference. While running the Loop() function and the proper calibration has been completed the arduino compares the high and low with the current analog in state, if it is out of range, the Arduino will send the current value to serial and is viewable with the serial monitor. Otherwise with the current code the Arduino will send “Stable” through the serial comm lines.
Feel free to use the code and have some fun with this cheap and easy to use accelerometer.
Here is the code compatible with Arduino 0018 IDE:
//Accelerometer testing
//Jeff Savaglio <Jeffsavaglio@gmail.com>
// May 31, 2010
//Use of the Pololu acc01a Accelerometer using MMA1260QT 3-axis accelerometer
// set up the x,y,z axis
int x0;
int y0;
int z0;
// these are the x,y,z high points to be used for determing
// the max analog value while the device is at rest.
int xH;
int yH;
int zH;
// these are the x,y,z low points to be used for determing
// the min analog value while the device is at rest.
int xL;
int yL;
int zL;
//this is the calibration button hooked into digital pin 7
const int cal = 7;
int calState = 0;
void setup(){
Serial.begin(9600); // open the Serial port and run it at 9600 baud
pinMode(cal, INPUT); // set the pinMode of the calibration button to INPUT
}
void loop(){
if ( digitalRead(cal)==HIGH){
// read the x,y,z and add them to the calibration values
x0 = analogRead(1);
y0 = analogRead(2);
z0 = analogRead(3);
// set up the x,y,z highs
xH = x0 + 5;
yH = y0 + 5;
zH = z0 + 5;
// set up the x,y,z lows
xL = x0 – 5;
yL = y0 – 5;
zL = z0 – 5;
}else{
// now that we have calibrated the accelerometer we can read
// the inputs and see if there is a change.
x0 = analogRead(1);
y0 = analogRead(2);
z0 = analogRead(3);
if (x0 > xH || x0 < xL){ // if x0 is more or less then our set high
// and low print the value, you can add what
Serial.print(“x= “); // ever you want the program todo in the curly
Serial.print(x0); // brackets
delay(1000);
}else if (y0 > yH || y0 < yL){ // this block is for the Y axis
Serial.print(“y= “);
Serial.print(y0);
delay(1000);
}else if (z0 > zH || z0 < zL){ // and this is the Z axis.
Serial.print(“z= “);
Serial.print(z0);
delay(1000);
}else{
Serial.print(” stable “); // if the accelerometer is at rest it will print
delay(1000); // a stable message.
}
}
}



