# MMA7361L accelerometer - Problem with the z-axis

Discussion in 'General Electronics Chat' started by krow, Mar 20, 2012.

1. ### krow Thread Starter Member

May 25, 2010
49
0
Hello,

Not sure this has been discussed before as I couldn't find anything, but I've been having a frustrating issue with the sensor's z-axis. I've tried everything but no success. I'm basically interested in the g values, so when the sensor is upside down instead of giving me -1 it gives me a value of around -1.34g, the corresponding value in volts is 0.58V. I think those value are not an acceptable? correct me if I'm wrong. Then when the sensor is facing up, the z-axis outputs 0.6g and 2.15V. Normally it would be 1g, 2.45V.

I guess this is a pretty straightforward calculation, it took me a while to actually make the decision to ask for help, it would be embarrassing to find this is all about a careless mistake.

The setup I'm using is simple, I'm using an Arduino Uno, the accelerometer is being powered by the 3.3V pin connected to Vin. I'm using the capacitors on the outputs as shown in the datasheet. Here's the code I wrote to get the values, again, pretty straightforward:

Code ( (Unknown Language)):
1.
2. //void setup(){};
3. //void loop(){};
4.
5. int myArray[]={A0,A1,A2};
6. float volts[3];
7. float g[] = {volts[0],volts[1],volts[2]};
8. int xVal, yVal, zVal;
9.
10. void setup(){
11.
12.   Serial.begin(9600);
13.   analogReference(EXTERNAL);
14.
15. }
16. void loop(){
20.
21.   volts[0] = xVal*3.3/1024; //Vref = 3.3
22.   volts[1] = yVal*3.3/1024;
23.   volts[2] = zVal*3.3/1024;
24.
25.   g[0]= (volts[0]-1.65)/0.8; // Voff = 1.65, Sensitivity = 0.8
26.   g[1]= (volts[1]-1.65)/0.8;
27.   g[2]= (volts[2]-1.65)/0.8;
28.
29.   Serial.print(volts[0]);
30.   Serial.print("\t");
31.   Serial.print(volts[1]);
32.   Serial.print("\t");
33.   Serial.print(volts[2]);
34.   Serial.print("\t");
35.   Serial.print(g[0]);
36.   Serial.print("\t");
37.   Serial.print(g[1]);
38.   Serial.print("\t");
39.   Serial.println(g[2]);
40.
41.   delay(100);
42. }
43.
Any help on this issue will be much appreciated, thanks.