how to use a mma7361 accelerometer what is wrong?

Hi every body! i bought a mma7361 accelerometer like this:

I guess it could be use through i2c or analog in, and i want to use it via analog in!
I plugged like this:
A0 to X
A1 to Y
A2 to Z
3.3V to 3V3
GND to GND
and i had this code:

#include <SoftwareSerial.h>

int axe_x=0;
int axe_y=0;
int axe_z=0;

void setup()
{
Serial.begin(9600);
}

void loop()
{
axe_x=analogRead(A0);
axe_y=analogRead(A1);
axe_z=analogRead(A2);
Serial.print(axe_x);
Serial.print("\n");
Serial.print(axe_y);
Serial.print("\n");
Serial.print(axe z);
Serial.print("\n");
}

but in the terminal there is only some strange values, all the same for each axis, and wich don't move when shaking the accelerometer!
Any ideas what i m doing wrong?

SL is the SLEEP signal. Connect it to 3.3V or the accelerometer will stay in a low-power sleep mode.

thanks fo your help, now i have new questions :slight_smile:
how can i smooth a little bit the values i get? i guess there is already an RC filter on the pcb.
Thanks for help!!

try this ...

#include <SoftwareSerial.h>

long axe_x=0;
long axe_y=0;
long axe_z=0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  axe_x = (90* axe_x + 10 * analogRead(A0)) / 100;
  axe_y = (90* axe_y + 10 * analogRead(A1)) / 100;
  axe_z = (90* axe_z + 10 * analogRead(A2)) / 100;

  Serial.print(axe_x);
  Serial.print("\n");
  Serial.print(axe_y);
  Serial.print("\n");
  Serial.print(axe z);
 Serial.print("\n");
}

For a little more versatility:

const int STABILITY = 10;

long axe_x=0;
long axe_y=0;
long axe_z=0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  axe_x = ((STABILITY-1)* axe_x + analogRead(A0)) / STABILITY;
  axe_y = ((STABILITY-1)* axe_y + analogRead(A1)) / STABILITY;
  axe_z = ((STABILITY-1)* axe_z + analogRead(A2)) / STABILITY;

  Serial.println(axe_x);
  Serial.println(axe_y);
  Serial.println(axe z);
}

Maybe this can help future readers
https://code.google.com/p/mma7361-library/

Thanks for the link!
(There are several optimizations possible in this lib by the way e.g. using bytes for pin numbers reducing the footprint)

Hello everybody,
i have an MMA7361 accelerometer...
How i can obtain the value of linear acceleration and rotational acceleration?

My idea is to see falling detection..
Can you help me please?

thanks

F.N.

What have you tried? Have you used the library mentioned in #5? I see it has some examples....