Arduino

MMA8451 Accelerometer on the Arduino UNO

Note: This article is a blurb. Help expand it.

Tags

Tutorial

The following procedure will show you how to set up your Arduino UNO with the MMA8451 Accelerometer.

=======

Where to Get Parts

The parts in this tutorial can be acquired:



Advertisement


Hardware

I will be using the Triple-axis 14-bit MMA8451 Accelerometer - from Adafruit.

Breakout-Board Assembly

Assemble the board, by soldering the connector pins:

Circuit

Connect the Arduino and the accelerometer breakout board according to the following diagram:

The accelerometer is powered by the 5 volt line. The A pin is not connected in this tutorial, but can be used to change the I2C address to 0x1D if connected to 3.3 Volt. The SDA and the SCA pins are connected to the analog A4 and A5 pins, respectively.

Software

Arduino Software Installation

  1. Download and install the latest Arduino Development Environment version for your operating system from here.

Accelerometer Library Installation

Adafruit supplies all the necessary libraries for their board. You will have to install the MMA8451 specific library and the Adafruit Sensor library. You can find the location of your Arduino libraries-folder by clicking File->Preferences and then checking the Sketchbook Location.

  1. Download the Adafruit Sensor library from github.
    1. Extract the zip file into your Arduino libraries folder (most likely for windows: <current user>\Documents\Arduino\libraries)
    2. Rename the folder to Adafruit_Sensor
  2. Download the Adafruit MMA8451 library from github.
    1. Extract the zip file into your Arduino libraries folder (most likely for windows: <current user>\Documents\Arduino\libraries\)
    2. Rename the folder to Adafruit_MMA8451_Library
  3. Restart the Arduino software to make sure that the libraries have been loaded. You can check if the libraries are properly installed, by checking the entries in Sketch->Import Library..->.

Sketch Creation

  1. The following example is included with your library and prints the raw accelerometers readings and the readings converted to m/s^2 in the x,y,an z direction.
  2. Load the sketch by clicking File->Examples->Adafruit_MMA8451_Library->MMA8451demo

Uploading Sketch

First select the appropriate board (here Arduino UNO) and the appropriate COM port. Click upload and the sketch should compile without problems. The Serial Monitor output can be accessed by pressing [Ctrl]+[Shift]+[M] and should show something like this:

The line readings are:

  • The first line shows the "Range" mode that the accelerometer readings are in +/-2g, +/-4g, or +/-8g.
  • The second line shows the raw readings in the x ,y ,and z direction.
  • The third line shows the readings converted into units of m/s^2.
  • The fourth line describes the orientation of the board.

Conclusion

In this tutorial you were shown how to interface the MMA8451 Accelerometer with the Arduino UNO board. The example shows you how to communicate with the sensor and how to read the acceleration values from the accelerometer.



Advertisement