Where to Get Parts
The parts in this tutorial can be acquired:
I will be using the Triple-axis 14-bit MMA8451 Accelerometer – from Adafruit.
Assemble the board, by soldering the connector pins:
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.
Arduino Software Installation
- 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.
- Download the Adafruit Sensor library from github.
- Extract the zip file into your Arduino libraries folder (most likely for windows: <current user>\Documents\Arduino\libraries)
- Rename the folder to Adafruit_Sensor
- Download the Adafruit MMA8451 library from github.
- Extract the zip file into your Arduino libraries folder (most likely for windows: <current user>\Documents\Arduino\libraries\)
- Rename the folder to Adafruit_MMA8451_Library
- 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..->.
- 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.
- Load the sketch by clicking File->Examples->Adafruit_MMA8451_Library->MMA8451demo
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.
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.