Introduction

The MPU6050 is a 6-DoF (degree of freedom) accelerometer and gyroscope that is designed for inexpensive, small-scale, and efficient approximation of motion. Accelerometers and gyroscopes are used in smart phones for orientation detection, vibration analysis in vehicles and machines, and even camera stabilization and motion tracking. There are countless applications for accelerometers and gyroscopes, and with devices as accessible as the MPU6050, we can really test the limits of the technology.

The MPU6050 features three 16-bit analog-to-digital converters (ADCs) for digitizing the gyroscope outputs and three 16-bit ADCs for digitizing the accelerometer outputs. For this specific tutorial, the gyroscope range spans ±250°/sec, and the accelerometer range spans ±2g. The MPU6050 uses the I2C serial communication, which can be interfaced using pins A4/A5 (SDA/SCL) on the Arduino Uno board. The sensor also uses 3.3V as the supply voltage. The gyroscope and accelerometer can be sampled between 1-8kHz, but the limitations of the SD module will restrict the sample rate down to 500 Hz - which suffices for many applications (full datasheet for MPU6050 here).

Arduino Parts List and Wiring

The Arduino Uno board will be used as the controller for acquiring data from the MPU6050 at high speeds. An SD module will also be used to save the data in real time for analysis and post processing. This will more flexibility of the analysis while also allowing for portable applications such as tracking and vibration analysis (which would be very difficult with an Arduino board). The parts needed to replicate the experiments in this tutorial are listed below:

  1. Arduino Uno - $13.00
  2. MPU6050 Accelerometer + Gyroscope - $7.00 
  3. SD Module - $8.00 
  4. 16 GB SD Card + USB Reader - $10.00 
  5. 3.7V LiPo Battery - $18.99 (4 pcs + charger)
  6. 3.7V to 5V Boost Converter - $7.99 (2 pcs) 
  7. Mini Breadboard - $3.00 
  8. Jumper Wires - $5.99 (120 pcs) 
  9. Raspberry Pi 3B+ Kit - $48.99

Arduino Uno
Arduino Uno
MPU6050
MPU6050
SD Module
SD Module
16 GB SD Card
16 GB SD Card
3.7V LiPo Battery
3.7V LiPo Battery
3.7V to 5V Boost Converter
3.7V to 5V Boost Converter

Schematic and Wiring

The wiring for the experiments conducted in this tutorial is very minimal and uses I2C wiring for the accelerometer and gyroscope, and SPI wiring for the SD card module. The wiring diagram is given below:

The wiring table is also given below:

One note regarding the wiring: the Arduino-to-Arduino wiring from 5V to pin D3 is used for letting the program know when to start (HIGH) and stop (LOW) recording. This is important because we will have no other way to notify the program to start and stop. A pullup resistor will be used on pin D3 to limit the power input onto that pin. The rest of the wiring is traditional and expected for the MPU6050 (I2C) and the SD module (SPI). The SD module requires 5V, which is why we’re using a 3.7V to 5V LiPo boost converter. The LED is wired for notifications regarding acquisition of data and processing - this will be discussed in the next section.


Acquiring and Understanding MPU6050 Data

The Arduino Uno will be used to acquire acceleration and gyroscopic data from the MPU6050. An Arduino program is given below which automatically acquires data from the MPU6050 at a sample rate of 500Hz and saves it to the SD card. The data acquisition code is based on the SDFat library and its MPU6050 low-latency logger code, except I have cut out the user interface section, which allows us to use the code in a portable manner. In order to use the code, the SDFat library must be downloaded to the Arduino IDE:


###################################################################################

The full code is given below:

// Arduino code for high-speed MPU6050 data acquisition with SD module
#include <spi.h>
#include "SdFat.h"
#include "FreeStack.h"
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"

#define FILE_BASE_NAME "mpu6050a" // setting the...
Read more »