MPU-6050 Gyroscope Introduction & Teapot 3D simulation

What is MPU-6050 ?

MPU-6050 is Digital Motion Processor (DMP) Sensor

This sensor have 6 DOF sensing capability, which means it gives 6-axis output like acceleration output for 3 axis as well as Gyroscope value of 3 axis.

This sensor is widely used in where balancing are required like Self balancing robots, drone, quadcopter, 3D simulation


In this tutorial, I will give you a basic introduction to the MPU 6050, demonstrate how it can be interfaced to an Arduino, and show you how to make a 3D simulation model using the data from your Arduino MPU 6050.

Required material


  1. MPU-6050 Sensor
  2. Arduino board (i used Arduino UNO)
  3. Jumper wires


  1. Arduio IDE
  2. Processing IDE


  1. I2CDevlib & MPU6050 for Arduino
  2. Toxiclib for Processing
  3. Teapot Code for Processing



How Does it Work?

IMU sensors usually consist of two or more parts. Listing them by priority, they are the accelerometer, gyroscope, magnetometer, and altimeter. The MPU 6050 is a 6 DOF (Degrees of Freedom) or a six-axis IMU sensor, which means that it gives six values as output. Three values from the accelerometer and three from the gyroscope. The MPU 6050 is a sensor based on MEMS (Micro Electro Mechanical Systems) technology. Both the accelerometer and the gyroscope are embedded inside a single chip. This chip uses I2C (Inter-Integrated Circuit) protocol for communication.



Connecting the Arduino & MPU 6050

The MPU 6050 communicates with the Arduino through the I2C protocol. The MPU 6050 is connected to Arduino as shown in the following diagram. If your MPU 6050 module has a 5V pin, then you can connect it to your Arduino’s 5V pin. If not, you will have to connect it to the 3.3V pin. Next, the GND of the Arduino is connected to the GND of the MPU 6050.

The program we will be running here, also takes advantage of the Arduino’s interrupt pin. Connect your Arduino’s digital pin 2 (interrupt pin 0) to the pin labeled as INT on the MPU 6050. Next, we need to set up the I2C lines. To do this, connect the pin labeled SDA on the MPU 6050 to the Arduino’s analog pin 4 (SDA) and the pin labeled as SCL on the MPU 6050 to the Arduino’s analog pin 5 (SCL). That’s it, you have finished wiring up the Arduino MPU 6050!


Uploading the Code to Arduino and taking RAW Data from MPU-6050

First of all download MPU-6050 supporting library & code 

To add library in Arduino

  1. Launch Arduino IDE software
  2. Go to sketch tab > Include library > Add .Zip library
  3. Locate the zip file of library and click on Open
  4. It’s done library are added

To load code go to

File > Example > MPU6050 > MPU6050_DMP6


Before uploading the code must check the right COM PORT & Board is selected from.

Tools > Board

Tools > Port

Click on Upload so code get upload to arduino now open Serial monitor (CTRL+SHIFT+M)

Set baud rate at 115200

Video demonstration


Teapot 3D Simulation Demo using Processing platform

For 3D simulation we need a software called Processing, Code Teapot & library Toxiclib

To visualize the 3D model in processing, first, you have to upload the Arduino code for MPU 6050 (MPU6050_DMP6). Before doing that, you need to comment the line in the Arduino MPU6050_DMP6 code which says:


And uncomment the line which says:

//#define OUTPUT_TEAPOT  by  #define OUTPUT_TEAPOT.

then upload the code to Arduino

You can now close Arduino software (not compulsory)

As you download  Toxiclib library unzip it copy that two folders and past at


now the libraries are installed

open the TeaPot code in processing Click on RUN now you can see a 3D plan in screen

The Pitch, yaw & roll can control by moving the sensor in different axis.


For windows users, you need to comment the line that says:

String portName = “/dev/ttyUSB1”;  by  //String portName = “/dev/ttyUSB1”;.

And uncomment the line that says:

//String portName = “COM4”;  by  String portName = “COM4”;.

And replace “COM4” with the COM port where your Arduino is connected (check this by going intoArduinoo and Tools –> Serial Port).


Video demonstration



Low cost PCB on PCBWay - only $5 for 10 PCBs and FREE first order for new members

PCB Assembly service starts from $88 with Free shipping all around world + Free stencil 

PCBWay 2nd PCB Design Contest



Hobbiest Electrical DIY project passionate

4 Responses

  1. It works in Arduino IDE but when I run the PDE in processing I get:

    The field PConstants.OPENGL is deprecated line 60 &

    Type string of the last argument to method println(object) doesn’t exactly match the vararg parameter type. Cast to object[] to confirm the non-vararg invocation, or pass the individual arguments of type objects for vararg invocations in line 68:

    where line 68 is println(Serial.list());

  2. ok I changed 68 to printArray(Serial.list()); and got the plane drawn in the java window, but it doesnt move at all. The line 60 error remains. Oh wait, it needed time to start sending I guess…I can see garbage in the processing console below and now I can control the plane in the java window.

Leave a Reply

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

Enter Captcha Here : *

Reload Image

Post comment