3
$\begingroup$

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?

$\endgroup$
3
  • $\begingroup$ I copy your code inline to combat link rot. Also, I notice on the Amazon postings that there is Arduino code available for this device. Have you tried it? $\endgroup$ Dec 8, 2012 at 6:52
  • $\begingroup$ I didn't find any... Could you possibly link me to it? $\endgroup$
    – Dylan Katz
    Dec 8, 2012 at 6:56
  • $\begingroup$ A quick Google seems to bring up a number of examples: Google Code Project, Arduino Forum, DFRobot Example, GE Tech Wiki. $\endgroup$ Dec 8, 2012 at 7:04

1 Answer 1

3
$\begingroup$

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
}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.