Trouble with acclerometer MMA7361L

Hello !

I’ve bought a movement sensor (Acclerometer MMA7361L) and am having trouble interfacing Arduino to it. In fact, it gives me junk values. When I shake it, the values do not change (or they show weak variations). So I am looking for how making it detecting values, or not, in a more binary way. My sketch (code) is well-written, no problem about it.

I think it is a connexion problem. I am a beginner, and currently work on my first project with Arduino.

I have previously looked for solving this problem, on various forums, and asked my teachers, in vain. If somebody could help me, it would be great ! Thanks !

Here are my code and photographies of the assembly :

int ledPin1 = 12;
int ledPin2 = 11;
int ledPin3 = 10;
int ledPin4 = 9;


int XPin = A0;
int YPin = A1;
int ZPin = A2;

int valX = 0;
int valY = 0;
int valZ = 0;

int accPin = 8;
int valAcc;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin1, OUTPUT);  
    pinMode(ledPin2, OUTPUT);  
      pinMode(ledPin3, OUTPUT);  
        pinMode(ledPin4, OUTPUT);  
  pinMode(accPin, INPUT);  
}

void loop() {
  valX = analogRead(XPin);
  valY = analogRead(YPin);
  valZ = analogRead(ZPin);
  valAcc = digitalRead(accPin);
  
  Serial.print("  X ->");
  Serial.print(valX);
  Serial.print("  Y ->");
  Serial.print(valY);
  Serial.print("  Z ->");
  Serial.println(valZ); 

  Serial.print("########");
  Serial.println(valAcc);   
  
  if (valX > 150 or valY > 150 or valZ > 150) {
    digitalWrite(ledPin1, HIGH);  
     digitalWrite(ledPin2, HIGH);  
      digitalWrite(ledPin3, HIGH);  
       digitalWrite(ledPin4, HIGH);  
    delay(10);
   }
  
  else {
  digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
        digitalWrite(ledPin4, LOW);
  
  delay(10);
  }
}

Plz, select your code and pres a # button in the reply window bar. What is your readings X, Y, Z? Sensor outputs close to 3.3v/2 = 1.65 V when not moving, and arduino should report about 340. Here is my latest project: http://coolarduino.wordpress.com/2013/12/24/gesture-recognition/ No wiring -);

chery: Hello !

I've bought a movement sensor (Acclerometer MMA7361L) and am having trouble interfacing Arduino to it. In fact, it gives me junk values. When I shake it, the values do not change (or they show weak variations). So I am looking for how making it detecting values, or not, in a more binary way. My sketch (code) is well-written, no problem about it.

I think it is a connexion problem. I am a beginner, and currently work on my first project with Arduino.

I have previously looked for solving this problem, on various forums, and asked my teachers, in vain. If somebody could help me, it would be great ! Thanks !

Here are my code and photographies of the assembly :


int ledPin1 = 12; int ledPin2 = 11; int ledPin3 = 10; int ledPin4 = 9;

int XPin = A0; int YPin = A1; int ZPin = A2;

int valX = 0; int valY = 0; int valZ = 0;

int accPin = 8; int valAcc;

void setup() { Serial.begin(9600); pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); pinMode(ledPin4, OUTPUT); pinMode(accPin, INPUT); }

void loop() { valX = analogRead(XPin); valY = analogRead(YPin); valZ = analogRead(ZPin); valAcc = digitalRead(accPin);

Serial.print(" X ->"); Serial.print(valX); Serial.print(" Y ->"); Serial.print(valY); Serial.print(" Z ->"); Serial.println(valZ);

Serial.print("########"); Serial.println(valAcc);

if (valX > 150 or valY > 150 or valZ > 150) { digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, HIGH); digitalWrite(ledPin3, HIGH); digitalWrite(ledPin4, HIGH); delay(10); }

else { digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, LOW);

delay(10); } }


Can't see anything useful in the photos - perhaps a clear diagram of how you connected it, which breakout board you are using (link to datasheet/website please),

Thanks for those answers and pieces of advice ! My card is supplied with 5v, and all the values turn around 140, whatever the number written in the sketch is… For the moment I can't have the box because I am on holidays, but I try to show a clearer diagram and precisions as soon as possible…

So what happens when you actually run this sketch on your arduino ?

In fact, when I run the sketch, Leds light up, but not in balance with movement. The accelerometer seems to be too perceptible, I brush the box, it lights, I shake it, it lights or not… and the values on the sketch always turn around 140, they take so long time to decrease

Here is a diagram, I hope it understandable…
(It is supplied with Energizer 9V)

  • White squares are places taken by threads
  • White rectangle is the accelerometer
  • Red squares corresponds to places taken by threads
  • White lines are resistors

So on the Arduino card : A0 to 6E; A1 to 5E; A2 to 4D
5V to 28 + ; GND 29 - ; GND to the LEDS

Schéma.pdf (281 KB)

The schema

what are the actual readings that you get ? What are the analog counts, representing analog voltages, being received from the device.

You need to firstly understand how the sensor device is actually responding. Your illogical scheme for turning on and off the LED's is a different problem.

There are several things that you perhaps don't understand about this device.

When there is no acceleration and no gravitational force along a particular axis ( x,y,z), then the device will output about 1.65 V. And this varies, and it not the same for each axis.

In each direction, actual acceleration can be positive or negative, and the force of gravity acting on the sensor element can be positive or negative, depending on the way you hold it. This causes the output analog voltage to vary, upwards or downwards, from the 1.65 V level. At the higher of the two sensitivity settings, the voltage variation is 0.8 V/g , where this variation is a bit different for each axis.

So if you have +1g acceleration in the +ve X direction, you get about 2.45 volts, and if you have -1g acceleration, you get about 0.85 V.

1.65 V will be about 320 A/D counts on a 5V arduino and about 510 A/D counts on a 3.3 V arduino.

If the device is not actually accelerating, you will see 1g of apparent acceleration caused by the action of the gravitational force on the sensor element. If you hold the device straight, this 1g will appear on one axis. If you hold it at an angle, it will be shared between 2 or 3 axes.

Thanks for your help. I am clearly a beginner, and lack technological skills. I will continue to work on it, maybe with another accelerator, if it doesn't work. This is a team project, with students of different schools, so it could take time, but I will update my progress… :)