Arduino UNO full image

Arduino UNO + MPU-6050

Arduino UNO + MPU-6050 (GY-521)

I recently bought a GY-521 MPU-6050 sensor. The InvenSense MPU-6050 sensor contains a MEMS (Microelectromechanical systems) accelerometer and a MEMS gyro in a single chip. This sensor contains both a 3-Axis Gyroscope and a 3-Axis Accelerometer allowing measurements of both independently, but all based around the same axes. This simple module contains everything required to interface to the Arduino and other controllers via I2C and give motion sensing information for 3 axes (X, Y and Z). I’m going to show you how I can use the GY-521 with the Arduino Uno to get the readings from the sensor in order to rotate an F-15 3d model.

First I have to say that, I have over 7 years experience with building PCs but I am new to Arduino and I have a limited knowledge in working with the electronic parts and the microcontrollers. My main intention of this is to control the attributes of objects in Maya with an Arduino Uno and some sensors.

arduino project screenshot

Parts required to do this project:

MPU-6050 Accelerometer + Gyro (GY-521)
Arduino Uno
Male Header Pins
6 PCS Jumper Wires

GY-521 Features:

Chip: MPU-6050
GY-521 operating voltage: 3V ~ 5V
Communication: I2C-bus
Built-in 16bit AD converter, 16bit data output
Gyroscopes ranges: ± 250 500 1000 2000 degree/sec
Acceleration ranges: ± 2g, ± 4g, ± 8g, ± 16g

First step: The wiring and connections

Arduino Uno GY-521
3.3V VCC
Analog pin 4 SDA
Analog pin 5 SCL
Digital pin 2 INT

Note: Only two pins were needed to transmit data on the I2C bus:

SDA (data) <=> Analog pin 4
SCL (clock) <=> Analog pin 5

The MPU-6050 is connected to Arduino as shown in the following diagram:

arduino mpu 6050

Second step: I2C Scanner

This sketch scans the I2C-bus for devices. If a device is found, it is reported to the Arduino serial monitor, so try to find whether GY-521 is connected with the Arduino. For that, you can use the I2C Scanner version 6 to verify the connected I2C devices to Arduino. Upload the code to Arduino and then open the serial monitor and sets the data rate in bits per second to 9600 baud for serial data transmission. It should find your GY-521 at the hexadecimal address 0x68. The output below shows the GY-521 is connected with the Arduino.

I2C device found at address 0x68 !

[Get I2C Scanner]

The third step is to download and install Jeff Rowberg's i2cdevlib libraries, see the latest code on github. Go to the root folder and download the zipped files. Unzip the "" file and find the Arduino folder. Copy the "MPU6050" and "I2Cdev" folder to the Arduino "libraries" folder. Arduino stores all the add-on libraries within the "My Documents" folder. Here you see the location of the Arduino "libraries" folder. Libraries will usually contain a .cpp file and a few .h files. Most will also contain an examples folder. To verify the library has been installed correctly, open up the File>Examples folder under the Arduino IDE and you should see "MPU6050_DMP6" and "MPU6050_raw" in MPU6050>examples folder. Now open up "MPU6050_DMP6" example and upload it to the Arduino. Open the serial monitor and sets the data rate in bits per second to 115200 baud. The output below shows the MPU-6050 is connected successfully.

Initializing DMP...
Initializing I2C devices...
Testing device connections...
MPU6050 connection successful
Send any character to begin DMP programming and demo:

Now you have to do changes in the "MPU6050_DMP" code:

Comment out #define OUTPUT_TEAPOT
Upload the modified code to the Arduino and then close the serial monitor.

[Get MPU6050_DMP_Modified]

The fourth step is to download and install Processing and toxiclibs libraries, see the latest toxiclibs libraries on bitbucket. Unzip the "" file and copy all folders to the Processing "libraries" in "My Documents" folder. Download "F-15 3D Model" and "MPUF15" files from the links below and unzip them in the same folder. Run the Processing IDE and open MPUF15.pde (a modified version of MPUTeapot). Finally, run it by pressing the play button.

[Get F-15 3D Model]

[Get MPUF15 Code]

Check out this video

Here are some references I used to learn more about the MPU-6050:

DIY Hacking
Geek Mom Projects
Dummys Codes