Accelerometer

hi! i'm trying to run arduino (with atmega328) with Accelerometer freescale MMA7260, i bought the accelerometer with sureelectronics pcb board i've connected the gnd to gnd, vdd to 3v3, X to analog 00, Z to analog 01, and y to analog 02.

here is the code of the program:

void setup() {

Serial.begin(9600); } void loop() { static int Xaxis = 0 ; static int Yaxis = 0 ; static int Zaxis = 0 ; static int Xaxisold = 0 ; static int Yaxisold = 0 ; static int Zaxisold = 0 ; static int Xaxisold1 = 0 ; static int Yaxisold1 = 0 ; static int Zaxisold1 = 0 ; Xaxis = analogRead(0); if(Xaxisold != Xaxis) { Xaxisold1 = Xaxis; Xaxis -= Xaxisold; Serial.println("X ="); Serial.println(Xaxis); } Xaxisold = Xaxisold1;

//Serial.print(Xaxis, BYTE); delay(10); Zaxis = analogRead(1); if(Zaxisold != Zaxis) { Zaxisold1 = Zaxis; Zaxis -= Zaxisold; Serial.println("Z ="); Serial.println(Zaxis); } Zaxisold = Zaxisold1; delay(10); Yaxis = analogRead(2); if(Yaxisold != Yaxis) { Yaxisold1 = Yaxis; Yaxis -= Yaxisold; Serial.println("Y ="); Serial.println(Yaxis); } Yaxisold = Yaxisold1; delay(100); }

here is the output:

X = 191 Z = 24 Y = 23 X = -1 Y = -1 Y = 1 X = 1 X = -1 Y = -1 Z = 1 X = 1 Y = 1 X = -1 Y = -1

no matter how i move it , it seems like it doesn't responds and there's just noise, does any one know's what im i doing wrong?

http://www.sure-electronics.net/DC,IC%20chips/DC-SS009_1_b.jpg - here is t he picture of the board

How is the sleep mode pin connected?

the sleep pin is not connected, do i have to connect it? right now i have no need in sleep mode

You need to make sure there's a HIGH on the sleep mode pin, otherwise the device will be in sleep whether you want a sleep mode or not.

ok, thanks! i'll give it a try, so i just need to connect it to digital pin and set it to high?

According to the datasheet, yes, that should do the trick.

ok, it looks like it works, but i get a lot of noise with random peaks sometimes to about 50, is there anyway to handle the noise?

is there anyway to handle the noise?

Wear ear-plugs?

You could take several readings, and average the readings. This way, the noise only minimally affects the overall average.