MPU6050: Arduino 6 Axis Accelerometer + Gyro - GY 521 Test & 3D Simulation





Introduction: MPU6050: Arduino 6 Axis Accelerometer + Gyro - GY 521 Test & 3D Simulation

Are you looking to make your own quadcopter drone or RC plane with Arduino but don't know how to get the gyro working? Perhaps you already bought some 6 axis MPU6050 modules (on the GY-521 breakout boards) only to find out they weren't as simple to use as you thought? Try this out!

You'll learn to wire a simple circuit to test your MPU6050 with an Arduino and simulate the YAW, PITCH and ROLL on a 3D model plane on the screen. This is intended as a learning tool to get you familiar with gyro modules, breakout boards and installing the necessary libraries to your Arduino IDE to allow you to make the best use of your MEMS gyro and save time instead of writing complex code from scratch.

What you need can be found on eBay (links below):

Step 1: Wire Circuit As Shown Below:

***NOTE: all red cables are VCC (+5V) and black cables are GND, check carefully when wiring up your circuit. The breakout board comes with pins but requires soldering.***

For your own learning:

  • the gyro module communicates with the Arduino through I2C serial communication via the serial clock (SCL) and data (SDA)
  • the MPU6050 chip needs 3.3V but a voltage regulator on the GY-521 board allows you to give it up to 5V
  • For more information on the module there is a great resource on this page in the Arduino Playground

Step 2: Install I2Cdev & MPU6050 Libraries

If we were to write the code from scratch, it would take ages and there would be a lot of reverse engineering required to make good use of the module's proprietary Digital Motion Processing (DMP) engine because Invensense intentionally released minimal data on its MPU6050. Good thing someone has already done the hard work for us; Jeff Rowberg wrote some Arduino libraries to obtain the accelerometer / gyro data and handle all the calculations. They are available as a zip file from here:

Once unzipped, find the Arduino folder within it and copy the two folders "I2Cdev" and "MPU6050" over to your Arduino "libraries" folder in the following directory:

C:\Program Files (x86)\Arduino\libraries

Then open the Arduino IDE and in the examples section, you should find MPU6050_DMP6 within MPU6050. Open it, plug your arduino in, select the appropriate COM Port and upload the sketch. In the Serial Window, select a baud rate of 115200. You should be prompted that the MPU6050 connection was successful. You can test the data collection by typing anything in the text bar and pressing enter, the data should start showing up.

Now we want to set the code to run the teapot demo to show the 3D simulation. Close the serial window, then find and comment out the line #define OUTPUT_READABLE_YAWPITCHROLL and uncomment the line //#define OUTPUT_TEAPOT. Select "save as" and choose where you want to save the modified code. Upload again but don't open the serial window this time.

Step 3: Download & Install Latest Version of Processing & ToxicLibs Library

To run a 3D simulation of the yaw / pitch / roll values on an airplane on the screen, we'll be running the teapot demo from the MPU6050_DMP6 example from Jeff Rowberg's MPU6050 libary. However the Arduino IDE will only be acquiring the data, to display the 3D simulation we'll need additional software: Processing. Download Processing from here, then unzip to wherever you like:

We'll need one final library to get things running: ToxicLib. This library will be going into Processing's libraries folder instead of Arduino's. The latest version of the ToxicLibs library is here:

The "libraries" folder of Processing can be found by following (starting from within the processing folder): modes -> java -> libraries. Unzip ToxicLibs and place ALL the contents there.

Step 4: Run the Simulation

Last of all, open the Processing application file and then

File -> Open -> follow this directory C:\Program Files (x86)\Arduino\libraries\MPU6050\Examples\MPU6050_DMP6\Processing\MPUTeapot

and open the MPUTeapot file.

Click the play button and the system should calibrate for about 20-30 seconds, leave the gyro stationary during that period.

Now pick up the gyro and test out the yaw / pitch / roll. Once you're happy that it all works properly you can begin experimenting with it for your own projects. If you want to make full use of the I2Cdev or MPU6050 libraries and their functions, consult their header files.

I hope to do an instructable on making a DIY drone shortly, so if you found this one useful, why not stay tuned for future projects by following me on Instructables and on Facebook / Twitter / Google+.

If you enjoyed this instructable and would like to see more like this, please consider supporting me by purchasing your materials for this project through the affiliate links in the materials section or donating below:


Bitcoin: 1Mqe7et24Lz4DY1RUN4iAQVHkvJsdFArKR

Ethereum: 0x6d8248db1cdea6a783cb6b41ae67bb8e6144f479

Litecoin: LW6PWESqsr8xHw6EJ9WLbsQsAyTvPnwnxJ

Dash: Xemv7jud697v8tQmKfNFoMxfkd17ZayH2t

Your support is greatly appreciated! Happy DIY'ing!

14 People Made This Project!


  • Remote Control Contest 2017

    Remote Control Contest 2017
  • Arduino Contest 2017

    Arduino Contest 2017
  • LED Contest 2017

    LED Contest 2017

We have a be nice policy.
Please be positive and constructive.


Questions & Answers


Thanks a lot . I made it successfully. I was wondering if we could display 3D model on 3.2 inch TFT LCD using Arduino which has exactly same output as that of in processing IDE.

Is it possible to run the initialization phase once, and store all the offsets for further program starts?

I don't want to wait about 10 sec. for calubration each time I start up the controller.

Hi Julian, stationary calibration is important because it is the only way for the system to know in what orientation, position and speed it is at any given point later. If you run the initialization phase once and store the offsets for later and skip calibration on each start up, you need to guarantee your setup always begins in that exact same state of motion and orientation for the IMU motion data to be at least approximately accurate.

It might be possible to the skip calibration part in the code, have you taken a look at the code (i.e. both the included arduino sketch and the MPU6050 library header files)? Can you tell me what part of the code relates to calibration? Then I can help you out.

It is possible to setup the code and the offset for the DMP in this way, that after the controller is start up, the DMP generates valid sensor values?

Now its the following behaviour: After controller starting the DMP generates unstable values, just after ca. 10 sec. the values becoming stable.

I can't help you until you answer my question: "have you taken a look at the code (i.e. both the included arduino sketch and the MPU6050 library header files)? Can you tell me what part of the code relates to calibration?" Then I can help you out. Please stop repeating your question, I already understand what you are asking.

Sorry for disturbing.
I already had a look in the necessary MPU6050 *.cpp and *.h files.
The ino sketch receives the actual sensor values from this functions:
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);

Hi Julian, I think what you are looking for could be the line:

delay(30); // wait after reset

in the function MPU6050::dmpInitialize() in one of the following files: MPU6050_6Axis_MotionApps20.h and MPU6050_6Axis_MotionApps41.h, which file you have to edit depends on which one is #included in your MPU6050_DMP6.ino file. Maybe you can set the delay to something smaller or even 0 and see what happens. I'm only speculating from looking at the code, I haven't tested any of this, so I'll leave that up to you.

Hi, i followed your tutorial but my mpu6050 is not connecting successfully. I have this result:

IniInitializing I2C devices...

Testing device connections...

MPU6050 connection failed

Send any character to begin DMP programming and demo:

Does anyone here knows how to solve this?

i have the same problem,anyone plz recommend the solution