Accelerometer MMA7455 How-To:

AccelerometerFreescale.jpgThis is an inexpensive module that can measure acceleration in three axes. It can be used to measure the tilt of an object in two axes by sensing the direction of the Earth's gravity.. It is Available HERE:



To Start with, you need only 4 connections to the Accelerometer module:

  • GND - To Arduino / YourDuino GND
  • VCC - To Arduino / YourDuino +5V (Note: this module has onboard 3.3 V regulator)
  • SCL - To Arduino / YourDuino A5 (Or Mega SCL pin)
  • SDA - To Arduino / YourDuino A4 (Or Mega SDA pin)

Arduino Software for this Module:

A nice library that makes this module easy to use was written by Moritz Hemper and it is detailed here Download the library HERE: and install on your Arduino IDE. (See "Arduino Libraries" on the http://Arduino-Info.Info WIKI HERE: ) Close and reopen the IDE to have the library available.

MMA7455-Hold.jpgIn the Arduino IDE, cut and paste the example test sketch below. Upload it and then open the Serial Monitor window (Info) to see the results.
Hold the module level as in the photo on right.
You will see output somewhat like this:

MMA7455 Accelerometer Test.
X = -5   Y = -26   Z = 67
X = -4   Y = -26   Z = 67
Tilting the module left-right is the X axis, away-closer is the Y axis. Straight down is the Z axis, which will read 1 G due to the Earth's gravity. The test sketch will also tell you which way the module is tilted if you tilt it.

/* YourDuinoStarter Example: MMA7455 Accelerometer Test
 This example uses the MMA_7455 library by Moritz Kemper
 Released under Creative Commons Licence
 For use with this module or equivalent:
 +5V and GND to Arduino/Yourduino (Module has 3.3V regulator)
 SCL - To Arduino / YourDuino A5 (Or Mega SCL pin)
 SDA - To Arduino / YourDuino A4 (Or Mega SDA pin)
 - V1.03 11/18/2013
/*-----( Import needed libraries )-----*/
#include <Wire.h> //Include the Wire library
#include <MMA_7455.h> //Include the MMA_7455 library

/*-----( Declare Constants and Pin Numbers )-----*/

/*-----( Declare objects )-----*/
MMA_7455 mySensor = MMA_7455(); //Make an instance of MMA_7455

/*-----( Declare Variables )-----*/
char xVal, yVal, zVal; //Variables for the values from the sensor

void setup()   /****** SETUP: RUNS ONCE ******/
  Serial.println("MMA7455 Accelerometer Test.");
  // Set the sensitivity you want to use
  // 2 = 2g, 4 = 4g, 8 = 8g
  mySensor.initSensitivity(2); // Good for "Tilt" measurements
/* Calibrate the Offset. Calibrate, in Flat position, try to
    get: xVal = 0, yVal = 0, zVal = +63 (1 G)
   !!!Activate this after having the first values read out!!!
   Suggestion: Run this with offsets = 0,0,0 and see needed correction
  // mySensor.calibrateOffset(0,0,0); //Uncomment for first try: find offsets
  // mySensor.calibrateOffset(-5.0, 13.0, -12.0); //Then Uncomment and use this
}//--(end setup )---

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
  xVal = mySensor.readAxis('x'); //Read out the 'x' Axis
  yVal = mySensor.readAxis('y'); //Read out the 'y' Axis
  zVal = mySensor.readAxis('z'); //Read out the 'z' Axis
  Serial.print("X = ");
  Serial.print(xVal, DEC);
  Serial.print("   Y = ");
  Serial.print(yVal, DEC);
  Serial.print("   Z = ");
  Serial.println(zVal, DEC);
/*--( Show tilt [Assumes unit has been calibrated ] )----*/  
  if (xVal < -20) Serial.println("Tilted LEFT");
  if (xVal >  20) Serial.println("Tilted RIGHT");  
  if (yVal < -20) Serial.println("Tilted TOWARDS");  
  if (yVal >  20 ) Serial.println("Tilted AWAY");   
  if (zVal < -45 ) Serial.println("UPSIDE DOWN!");    
}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/

//*********( THE END )***********

Hardware Details of the MMA7455 Chip are HERE:
Other Detailed Software examples are available on the Arduino Playground HERE: