Introduction: Motion Tracking Using MPU-6000 and Arduino Nano

About: We are a group of makers. We work in IoT, IOS app, android app, embedded design, sensor design, raspberry pi, arduino, beaglebone, particle electron, particle photon, Bluetooth.

MPU-6000 is a 6-Axis Motion Tracking Sensor which has 3-Axis accelerometer and 3-Axis gyroscope embedded in it. This sensor is capable of efficient tracking of exact position and location of an object in the 3-dimensional plane. It can be employed in the systems which require position analysis to the highest precision.

In this tutorial the interfacing of the MPU-6000 sensor module with arduino nano has been illustrated. To read the values of acceleration and rotational angle, we have used arduino nano with an I2c adapter.This I2C adapter makes the connection to the sensor module easy and more reliable.

Step 1: Hardware Required:

The materials that we need for accomplishing our goal includes the following hardware components:

1. MPU-6000

2. Arduino Nano

3. I2C Cable

4. I2C Shield for arduino nano

Step 2: Hardware Hookup:

The hardware hookup section basically explains the wiring connections required between the sensor and the arduino nano. Ensuring correct connections is the basic necessity while working on any system for the desired output. So, the requisite connections are as follows:

The MPU-6000 will work over I2C . Here is the example wiring diagram, demonstrating how to wire up each interface of the sensor.

Out-of-the-box, the board is configured for an I2C interface, as such we recommend using this hookup if you’re otherwise agnostic.

All you need is four wires! Only four connections are required Vcc, Gnd, SCL and SDA pins and these are connected with the help of I2C cable.

These connections are demonstrated in the pictures above.

Step 3: Code for Motion Tracking:

Lets start with the arduino code now.

While using the sensor module with the arduino, we include Wire.h library. "Wire" library contains the functions which facilitate the i2c communication between the sensor and the arduino board.

The entire arduino code is given below for the convenience of the user:

#include<Wire.h>

// MPU-6000 I2C address is 0x68(104)

#define Addr 0x68

void setup()

{

// Initialise I2C communication as Master

Wire.begin();

// Initialise serial communication, set baud rate = 9600

Serial.begin(9600);

// Start I2C transmission

Wire.beginTransmission(Addr);

// Select gyroscope configuration register

Wire.write(0x1B);

// Full scale range = 2000 dps

Wire.write(0x18);

// Stop I2C transmission

Wire.endTransmission();

// Start I2C transmission

Wire.beginTransmission(Addr);

// Select accelerometer configuration register

Wire.write(0x1C);

// Full scale range = +/-16g

Wire.write(0x18);

// Stop I2C transmission

Wire.endTransmission();

// Start I2C transmission

Wire.beginTransmission(Addr);

// Select power management register

Wire.write(0x6B);

// PLL with xGyro reference

Wire.write(0x01);

// Stop I2C transmission

Wire.endTransmission();

delay(300);

} void loop()

{

unsigned int data[6];

// Start I2C transmission

Wire.beginTransmission(Addr);

// Select data register

Wire.write(0x3B);

// Stop I2C transmission

Wire.endTransmission();

// Request 6 bytes of data

Wire.requestFrom(Addr, 6);

// Read 6 byte of data

if(Wire.available() == 6)

{

data[0] = Wire.read();

data[1] = Wire.read();

data[2] = Wire.read();

data[3] = Wire.read();

data[4] = Wire.read();

data[5] = Wire.read();

}

// Convert the data

int xAccl = data[0] * 256 + data[1];

int yAccl = data[2] * 256 + data[3];

int zAccl = data[4] * 256 + data[5];

// Start I2C transmission

Wire.beginTransmission(Addr);

// Select data register

Wire.write(0x43);

// Stop I2C transmission

Wire.endTransmission();

// Request 6 bytes of data

Wire.requestFrom(Addr, 6);

// Read 6 byte of data

if(Wire.available() == 6)

{

data[0] = Wire.read();

data[1] = Wire.read();

data[2] = Wire.read();

data[3] = Wire.read();

data[4] = Wire.read();

data[5] = Wire.read();

}

// Convert the data

int xGyro = data[0] * 256 + data[1];

int yGyro = data[2] * 256 + data[3];

int zGyro = data[4] * 256 + data[5];

// Output data to serial monitor

Serial.print("Acceleration in X-Axis : ");

Serial.println(xAccl);

Serial.print("Acceleration in Y-Axis : ");

Serial.println(yAccl);

Serial.print("Acceleration in Z-Axis : ");

Serial.println(zAccl);

Serial.print("X-Axis of Rotation : ");

Serial.println(xGyro);

Serial.print("Y-Axis of Rotation : ");

Serial.println(yGyro);

Serial.print("Z-Axis of Rotation : ");

Serial.println(zGyro);

delay(500);

}

In wire library Wire.write() and Wire.read() is used to write the commands and read the sensor output.

Serial.print() and Serial.println() is used to display the output of the sensor on the serial monitor of the Arduino IDE.

The output of the sensor is shown in the picture above.

Step 4: Applications:

MPU-6000 is a motion tracking sensor, which finds its application in the motion interface of smartphones and tablets. In smartphones these sensors can be employed in the applications such as gesture commands for applications and phone control, enhanced gaming, augmented reality, panoramic photo capture and viewing, and pedestrian and vehicle navigation. MotionTracking technology can convert handsets and tablets into powerful 3D intelligent devices that can be used in applications ranging from health and fitness monitoring to location-based services.