AnsweredAssumed Answered

Using the MMA7361 accelerometer in a RC plane.

Question asked by Rigel Sales on Apr 20, 2015

I am an electrical engineering student and this is my first project without the supervision of a professor. I want to use the accelerometer MMA7361 connected to an Arduino in a RC plane in order to know the angle of the three axes of the aircraft, the acceleration that each axle suffers or the total acceleration of the plane. Initially I used this code for the measurement of angles of only two axes:


int maxi = 0,mini = 1023;

void setup() {





void loop() {

  int sensorX= analogRead(A0);

  sensorX = map(sensorX, 180, 530, 90, -90);

  Serial.print(" Angulo X = ");



  int sensorY= analogRead(A1);

  sensorY = map(sensorY, 205, 585, 90, -90);

  Serial.print(" Angulo Y = ");






When I was testing this code I realized that if the angle remained the same but the accelerometer suffer any abrupt deceleration, the angle value indicated would change. Then I began to think of a solution to my problem. When reading the accelerometer library, I realized that there was a function called getXAccel that returns the acceleration of the X-axis as a int (1 G = 100.00). The code bellow uses that function and I found it in the library.


#include <AcceleroMMA7361.h>



AcceleroMMA7361 accelero;

int x;

int y;

int z;



void setup()



  accelero.begin(13, 12, 11, 10, A0, A1, A2);







void loop()


  x = accelero.getXAccel();

  y = accelero.getYAccel();

  z = accelero.getZAccel();

  Serial.print("\nx: ");


  Serial.print(" \ty: ");


  Serial.print(" \tz: ");






Testing that code, initially everything seemed to be correct. In X and Y-axis the acceleration practically had not existed and in the Z-axis the acceleration was approximately 1G. But, when I leaned the accelerometer 90 in x, the acceleration was about to 4G, but actually I expected it to be 1G.


Can someone tell me what is going on? I also saw in the library the function getTotalVector that returns the magnitude of the total acceleration vector as an integer but I don't know how to use it. Anyone have a better ideia to find the angle, the total acceleration of the plane or the acceleration of each axis?


Thanks a lot.