3

I recently purchased a 3-axis accelerometer from Amazon, and can't seem to find how it works. I've been looking for quite a while now, and haven't found any real clues. The x, y, and z values always seem to return the same values. They change when I tilt or move the accelerometer, but revert to about 120 for each reading. I am currently using this device with the Arduino Uno, using the following code:

int x=1,y=2,z=3;
void setup() {
  pinMode(x, INPUT);
  pinMode(y, INPUT);
  pinMode(z, INPUT); 
  Serial.begin(9600);
}
void loop() {
 Serial.println();
 Serial.print(analogRead(x));
 Serial.print(", ");
 Serial.print(analogRead(y));
 Serial.print(", ");
 Serial.print(analogRead(z));
}

Also, how would I go about converting this to tilt?

DaemonMaker
  • 3,921
  • 3
  • 21
  • 32
Dylan Katz
  • 441
  • 1
  • 4
  • 13

1 Answers1

3

There is a project on Google Code called MMA7361-library. The GE Tech Wiki has a simple example showing how to use this library. Copied inline below for posterity.

#include <AcceleroMMA7361.h>
AcceleroMMA7361 accelero;
int x;
int y;
int z;
void setup()
{
 Serial.begin(9600);
 accelero.begin(13, 12, 11, 10, A0, A1, A2);
 accelero.setARefVoltage(5); //sets the AREF voltage to 3.3V
 accelero.setSensitivity(LOW); //sets the sensitivity to +/-6G
 accelero.calibrate();
}
void loop()
{
 x = accelero.getXAccel();
 y = accelero.getYAccel();
 z = accelero.getZAccel();
 Serial.print("\nx: ");
 Serial.print(x);
 Serial.print(" \ty: ");
 Serial.print(y);
 Serial.print(" \tz: ");
 Serial.print(z);
 Serial.print("\tG*10^-2");
 delay(500); //make it readable
}
DaemonMaker
  • 3,921
  • 3
  • 21
  • 32