MPU-6050 Accelerometer Introduction

posted in: Projects | 0


Accelerometers and gyroscopes intrigue me.  The small size, low cost, and ease in interfacing to small processors such as the Arduino make them very impressive.  After looking through several I decided to explore further the MPU6050 and learn as much as I could about this device.  Clearly, I understand there are limitations to the accuracy of such devices but I consider this an excellent education experience.  Our objective for this post will be to utilize the MPU6050 to try and understand a little bit about the device, how it works, and obtain data from the sensor.   In a later post we will add additional software to detect movement and to determine orientation in pitch and roll.  It could be fun as a sensor on my robotic vehicle platform.

Accelerometers measures change in velocity of a body in an instantaneous rest frame.  They will measure the acceleration due to gravity while at rest.  They have applications in navigation systems and motion sensing systems. We are familiar with our tablet computer and smartphones to detect movement for applications such as pedometers or to sense change in the devices rotation to realign the image on the display.  The MPU6050 accelerometer measures velocity change (meters/sec-squared) individually for the x, y, and z axis and is referred to as a 3-axis accelerometer.

A gyroscope measures the angular rate of change (degrees/second) around the x, y, and z axis.  Its principle of operation is based on the conservation of angular momentum.  It can be used to determine the angular rate of change of an aircraft and can also be used to determine the heading of a ship in the absence of a magnetic field.  The MPU6050 gyroscope measures angular rate of change individually for the x, y, and z axis and is referred to as a 3-axis gyroscope.

The MPU6050 includes an embedded temperature sensor for use in calibration and may be read to obtain the current temperature.

You might wonder how can all this be done in such a small package.  I guess that is what makes this technology so interesting.  The MPU6050 is a Micro Electro-Mechanical Systems (MEMS) sensor.   A detailed explanation of how accelerometers and gyroscopes operate as a MEMS sensor is beyond the scope of this article.  Multiple explanations can be found across the internet.  Provided below are a few links which discuss this interesting technology further.  





The MPU6050 is installed on a convenient breakout board and uses an Inter-Integrated Circuit (I2C) communication interface (SDA and SCL).  The breakout board is approximately 5/8 x 13/16 inches.  It operates with VCC between 2.375 – 3.46 volts and has a logic level between 1.71 to VCC volts.   It includes an interrupt output to notify the host when data is ready and could support applications such as tap and shake detection.  The chip supports two preprogrammed I2C addresses (7 bit) which are selectable by an external ADO pinout.  Two additional pins are available to support I2C bus passthrough to a magnetometer sensor.  A Ground pin along with the former mentioned pins are provided on the Breakout Board and allow direct connection to the Arduino UNO without any further intermediate circuits or voltage level shifting.



Invensense is the manufacturer of the MPU6050 and has several good documents worth review. Product Specification revision 3.4 was published August 19, 2013.  A very detailed explanation of the registers is included in the Register Map and Descriptions document also published by Invensense on August 19, 2013.  A short discussion on the calibration offsets is included in the MPU Hardware Offset Register Application Note, published February 21, 2014.

Internet is full of various type of explanations and tutorials on I2C.  This is an explanation by Texas Instruments for the I2C protocol.

Arduino code and other important project files are is included in a .ZIP file here.


Hooking it Up and Getting Started

To easily understand and troubleshoot the system, I constructed a “gyroscope mount” which will allow me to easily move and place the MPU6050 at various angles.  It was quickly built from ½” PVC piping, some screws and spacers.  The platform itself is constructed of plexiglass held on by some plastic brackets.  A small solderless breadboard is attached to allow mounting the MPU6050 Breakout Board.  I included a small surface area at the corner of the “gyroscope mount” for attaching the Arduino UNO.

Only 5 wires are needed to connect the MPU6050 with the Arduino UNO.  The table below shows how the wires are connected.

Note that on the Arduino UNO pins A4 and A5 are SDA and SCL respectfully.   I carefully attached the wires, including the USB cable for the computer.  When completed I had both the Arduino UNO and MPU6050 installed on a platform that could be easily moved around to demonstrate how the system is working and to allow for easy calibration as I will discuss later.  After connecting the setup as show, the first thing we will want to do is complete a quick checkout to make sure all components are working and the wiring has been completed correctly.   The Arduino UNO uses the Wire library to communicate with I2C devices. 















The following can be uploaded to the Arduino UNO and motion and temperature data can be obtained from the MPU6050 by reading the registers (3B – 48) from the MPU6050. 





Final Results

I used the Arduino IDE Serial Monitor to obtain the data.  I selected 9600 baud and included a 500 ms delay after retrieval of each data item from the sensor.  In practice you can select a higher data rate.  While the program is running and the display is operational, move the gyro mount in various manners first slowly and then abruptly.   The numbers will change in varying levels.  If you are able to obtain similar results and the representative data as shown below then your setup is working.


Where to Next

The results you have obtained only represent raw data coming from the sensor.  As stated in our objective, we would like to use the sensor to detect Pitch and Roll or even to use it in an alarm circuit that could detect movement.  To do this we need to removing any biases in the data and calibrate it the best we can.   We will then also need to explore the equations needed to determine the tilt of the MPU6050 breakout board.

Leave a Reply

Your email address will not be published. Required fields are marked *