Arduino MPU 6050 – Best IMU Sensor Tutorial

From: Arvind Sanjeev, Founder DIY Hacking

Arduino MPU 6050 Tutorial DIY Hacking

Arduino MPU 6050 Tutorial

In this post, I will be reviewing a few basic IMU (Inertia Measurement Unit) sensors, compatible with arduino. I shall also give a short tutorial for interfacing arduino with the best IMU sensor available. IMU sensors like the MPU 6050 are used in self balancing robots, UAVs, smartphones, etc.

IMU sensors are one of the most inevitable type of sensors used today in all kinds of electronic gadgets. They are seen in smartphones, wearables, game controllers, etc. IMU sensors help us in getting the attitude of an object, attached to the sensor in three dimensional space. These values usually in angles, thus help us to determine its attitude. Thus, they are used in smartphones to detect its orientation. And also in wearable gadgets like the nike fuel band or fit bit, which use IMU sensors to track movement.

IMU sensors, thus have prolific number of applications. It  is even considered to be an inexorable component in quadrotors. So use this Arduino MPU 6050 tutorial to build a self balancing robot or a hand tracking device . Some of the sensors that I was able to get my hands on were:

  1. ADXL 345 accelerometer.
  2. ITG 3200 gyroscope.
  3. Sparkfun 6 DOF IMU sensor board.
  4. MPU 6050.

I was able to work with both accelerometers and gyroscopes separately. However, they are not as accurate as when they are combined.  And among the lot, I found the Invensense MPU 6050 to be the most reliable and accurate IMU sensor. Apart from being significantly cheap from the other sensors, the MPU 6050 performs much better too.

Arduino MPU 6050 Tutorial DIY Hacking

Arduino MPU 6050 Pin out

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

What are the stuff required to do this project?

Hardware:

  1. Arduino or an arduino clone board (freeduino). Or make your own custom arduino board with this tutorial.
  2. MPU 6050 sensor.
  3. Interconnecting wires.

Software:

  1. Arduino IDE: Arduino
  2. Processing IDE : Processing (optional)

How does it work?

IMU sensors usually consists of two or more parts. Listing them by priority, they are : 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 is embedded inside a single chip. This chip uses I2C (Inter Integrated Circuit) protocol for communication.

How does an accelerometer work?

Arduino MPU 6050 Tutorial DIY Hacking

Piezo Electric Accelerometer

An accelerometer works on the principle of piezo electric effect. Here, imagine a cuboidal box, having a small ball inside it, like in the picture above. The walls of this box are made with piezo electric crystals. Whenever you tilt the box, the ball is forced to move in the direction of the inclination, due to gravity. The wall with which the ball collides, creates tiny piezo electric currents. There are totally, three pairs of opposite walls in a cuboid. Each pair corresponds to an axis in 3D space: X, Y and Z axes. Depending on the current produced from the piezo electric walls, we can determine the direction of inclination and its magnitude. For more information check this.

How does a gyroscope work?

Arduino MPU 6050 Tutorial DIY Hacking

Piezo Electric Gyroscope

Gyroscopes work on the principle of Coriolis acceleration. Imagine that there is a fork like structure, that is in constant back and forth motion. It is held in place using piezo electric crystals. Whenever, you try to tilt this arrangement, the crystals experience a force in the direction of inclination. This is caused as a result of the inertia of the moving fork. The crystals thus produce a current in consensus with the piezo electric effect, and this current is amplified. The values are then refined by the host microcontroller. Now check this short video that explains, how a MEMS gyroscope works.

Step 1: Interfacing 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. Here, if your MPU 6050 module has a 5V pin, then you can connect it to your arduino’s 5V pin. Else, 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.

Arduino MPU 6050 Tutorial DIY Hacking

Arduino MPU 6050 connections

The program we will be running here, also takes advantage of the arduino’s interrupt pin. Therefore, connect arduino’s digital pin 2 (interrupt pin 0) to the pin labelled as INT on the MPU 6050. Next, we need to set up the I2C lines. For this connect the pin labelled as SDA on the MPU 6050 to the arduino’s analog pin 4 (SDA). And the pin labelled as SCL on the MPU 6050 to the arduino’s analog pin 5 (SCL). And that’s it, you have finished wiring up the Arduino MPU 6050.

Step 2: Uploading the code and testing the Arduino MPU 6050

To test the Arduino MPU 6050, first download the arduino library for MPU 6050, developed by Jeff Rowberg. You can find the library here. Next you have to unzip/extract this library. And then take the folder named “MPU6050” and paste it inside the arduino’s “library” folder. That is, go to the location where you have installed arduino (Arduino –> libraries) and paste it inside the libraries folder. You might also have to do the same thing to install the I2Cdev library as well, if you don’t already have it for your arduino. Do the same procedure as above for installing it, you can find the file here: I2Cdev library.

If you have done this correctly, then when you open the arduino IDE, you can see “MPU6050” in File –> Examples. Next, open the example program from: File –> Examples –> MPU6050 –> Examples –> MPU6050_DMP6.

Arduino MPU 6050 Tutorial DIY Hacking

Arduino MPU 6050 DMP code

Now, you have to upload this code to arduino. After uploading the code, open up the serial monitor and set the baud rate as 115200. Next, check if you see stuff like “Initializing I2C devices…” on the serial monitor. If you don’t, just press the reset button. Now, you’ll see a line saying  “Send any character to begin DMP programming and demo: “. So just type in any character on the serial monitor and send it. And you will start seeing the yaw, pitch and roll values coming in from the MPU 6050. Like so:

Arduino MPU 6050 Tutorial DIY Hacking

Arduino MPU 6050 Serial Monitor

DMP stands for Digital Motion Processing. Here, the Invense’s MPU 6050 has an inbuilt motion processor. It processes the values from the accelerometer and gyroscope to give us accurate 3D values.

Also, you will need to wait about 10 secs before you get accurate values from the Arduino MPU 6050. After which, the values will begin to stabilize. Just check out the video, if you have any doubts:

Step 3: Modelling the values from Arduino MPU 6050 in 3D using processing (Optional)

If you want to see the 3D model of the sensor, continue reading. For viewing the 3D representation of the data from the MPU 6050, you need to install the “processing” software, you can do that from here: processing IDE. Processing is almost similar to arduino, except for a couple of functions. Processing is mainly used for visualizing data and rendering it in 2D/3D models.

Arduino MPU 6050 Tutorial DIY Hacking

Arduino MPU 6050 with Processing

After installing the processing IDE, next you will need to download a library called “Toxi”. This library is necessary for our Arduino MPU 6050 processing example. Download the latest zip file for the library from here. Next, you need to extract this file and paste the folder named “toxiclibs-complete-0020” in the libraries directory of processing. You can find the “libraries” folder inside the Sketchbook folder of processing. If you don’t, then you will have to create a new folder called “libraries” there, and paste the toxiclibs inside it.

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:

#define OUTPUT_READABLE_YAWPITCHROLL  by  //#define OUTPUT_READABLE_YAWPITCHROLL.

And uncomment the line which says:

//#define OUTPUT_TEAPOT  by  #define OUTPUT_TEAPOT.

Next, you have to open the processing example for the MPU 6050. Open processing, then: File –> Open. And then navigate to the folder where you had installed the MPU6050 library for arduino. You can find the processing example in: MPU6050 –> Examples –> MPU6050_DMP6 –> Processing –> MPUTeapot.

In this code, you have to then check the serial port which is defined in it. By default the line that defines it for linux/mac users is like:

String portName = “/dev/ttyUSB1”;.

You need to change ttyUSB1 to the port on which your arduino is connected.

Arduino MPU 6050 Tutorial DIY Hacking

Editing the Processing file for MPU 6050

And for windows users, you need to comment the line which says:

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

And uncomment the line which says:

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

And replace “COM4” with the COM port on which your arduino is connected (check this by going into arduino and Tools –> Serial Port).

Now we can test the whole setup. First upload the arduino code (MPU6050_DMP6) through arduino. And please remember NOT to open the serial monitor. Next run the processing code (MPUTeapot) by pressing the button with the “play” symbol. You will see a small plane like object. Wait for about 10 secs for the MPU 6050 values to get stabilized. After, which you can see the 3D model of your MPU 6050, which moves accordingly with the sensor. Now, check out the demo for the Arduino MPU 6050 3D model:

 

 

Recommended Posts
Showing 296 comments
  • Ibrahim
    Reply

    Hi Arvind
    I am also getting the same problem as below
    //———————error—————————
    No library found for toxi.geom
    No library found for toxi.processing
    Libraries must be installed in a folder named ‘libraries’ inside the ‘sketchbook’ folder.
    //——————————————————————————————-
    I unzip and pasted the folder “toxiclibs-complete-0020″ in processing Library folder but still getting this error
    please let me know on this

    regards
    Ibrahim

    • sang
      Reply

      Try to Import directly from Sketch-> import Library -> all libraries-> ToxicLib

  • eduardo cunha
    Reply

    Hi, I’m trying to make obtain the values of ypr on my arduino micro. I set up the same way as you did on the arduino uno but its not working. It just says “Initializing I2C devices”. So what do I have to adjust so I can have the readings of ypr from the mpu6050 on the arduino micro. The code works just find on my arduino uno but not the micro. Can you please help so I can get the same results from the mpu6050 on my arduino micro. Thanks!

    • sang
      Reply

      Try to Import directly from Sketch-> import Library -> all libraries-> ToxicLib

  • Tk
    Reply

    This tutorial help me heaps. Thank you.
    I had a bit of a struggle to get it to work because I did not know that “Sketchbook” is just a location and not a folder name.
    One just paste the “toxi” download there(look at preferences from within the processing application)and not within a folder called sketchbook.

    I am sure I am not the only one out here on the net that would pay for a course/detailed explanation of both the arduino and processing codes.

    Good work mate

    • Bryan
      Reply

      You helped me.I had the same problem finding the sketchbook folder.

  • Geanne
    Reply

    Hi, just one doubt. Are this values in the serial on degrees? Since now, thank you.

  • Alice Tayllor
    Reply

    Great tutorial, thanks for that! I really got interested in trying out this kind of a project on my own, but didn’t even have a clue what will I need to get started and end up with a functional quadcopter built by my own hands. So, I asked google :) and among numerous texts, I found this interesting one, offering information on how to get started and what to have before getting started. Hope it helps http://mydronelab.com/blog/arduino-quadcopter.html

  • Adravil
    Reply

    Pin-map for connecting MPU 6050 to Mega 2560 (pins in that order): VCC to 5V, GND to GND (PWM section, near pin #13), SCL to SCL 21, SDA to SDA 20, INT to pin #2 (PWM section, near pins TX0->1 & RX0<-0). The contact must be good! The light on the gyro should light brightly!

  • spongebob
    Reply

    Hi,

    The test code works great. But the UNO needs to be connected to the computer as Serial Monitor is required to start DMP processing.

    What are the ways to use the MPU6050 without having to stay connected to a computer ?

    Thank you

  • Zeeshan
    Reply

    Hi, i need some urgent help using this gyro. i am getting frustrated by moving from here to there. tried many examples and codes but no help.
    i am making a quadcopter from scratch which means building my own code. i want to use gyro GY521 to stablise the flight. can you please help me?
    i need stable x,y,z values so that i can adjust the thrust of my motors. all codes i see give me unstable values and once i am changing x, it changes others as well even though i am moving the sensor against one plane only

  • Chris W
    Reply

    Ok.. Currently the Bitbucket link for Toxiclibs is nonexistent. I found the “toxiclibs-complete-0020” file elsewhere, and it didn’t work. Also, the Processing “Libraries” directory has changed.

    So, as of Aug 1st, 2016, go to https://github.com/postspectacular/toxiclibs and click on the BLUE “Clone or Download” button at the top of the file list, then choose Download ZIP from the box that pops up. You’ll get a file called ‘toxiclibs-master.zip’.

    The new Libraries folder for Processing 3.1.2 (see date in previous paragraph) for Windows is MyDocuments/Processing/libraries. When you open the zip file, you’ll see only one folder – toxiclibs-master. Copy or Move this folder into the ‘libraries’ folder, and you should have a working ‘teapot’.

    No, I have no idea why its called teapot when its a plane… :-)

  • jason
    Reply

    there is no folder called sketchbook in processing. do i have to create a new folder and named it processing? because when i run the code, it says package “toxi” not found

  • Robert
    Reply

    Guys,
    The link for TOXIClibs is broken. The correct one is:

    https://bitbucket.org/postspectacular/toxiclibs/downloads/

  • John Mathews
    Reply

    Hi, I just watched the tutorial from EEEnthusiast (Arduino MPU-6050 Tutorial) and was wondering if you could help me with it. I’m working on a quadcopter and wanted to use the MPU to balance the unit. Do I need to use both accelerometer and gyroscope data to do that? Do you have an example I could use for it?

    Thanks,
    John

    • Zeeshan
      Reply

      hi,
      i am doing the same but getting frustrated. are u succeeded in this?

  • Sriraman S
    Reply

    Hi,

    I want to build a quadcopter using Arduino nano and MOSFET as motor driver (nano PWM to control the speed)
    Can you please provide a code.
    Thanks,
    Sriraman S

  • akshay
    Reply

    i have done all process to interface mpu6050 but at serial monitor it says “Initializing I2C devices…
    Testing device connections…
    MPU6050 connection failed

    Send any character to begin DMP programming and demo:
    Initializing DMP…
    DMP Initialization failed (code 1)”
    now i don’t know how to fix this, so please guide me.

  • Utsav Vakil
    Reply

    Hey I am trying to use the MPU 6050 sensor for gesture tracking. I was going through the code for calibrating the sensor, but wasn’t able to fully understand it. Is there any place I can refer to, to know the theory behind the calibration and how it is coded?

  • Anujkumar Prajapati
    Reply

    Hello, I am making a self balancing vehicle for my final year project using an MPU 6050, a Genuino board (might be a counterfeit), and a Cytron duo motor driver.

    However I am encountering a problem. The gyro sometimes starts giving out random absurd values and at times stops communicating. Do you think a problem with the MPU or the Arduino?

    • Ionut Banu
      Reply

      I have the same problem. Does anyone have a solution?

  • Deepesh Patidar
    Reply

    It is awesome using arduino, MPU6050 and processing. I noted one thing the toxiclib needs to paste into the processing but if one want to find the “libraries” folder he want. You need to paste toxiclib to “processing-3.0.2\modes\java\libraries”, then it will work.

  • Kyo
    Reply

    I already connect the arduino with mpu 6050 as shown above. But it still show this thing.

    Initializing I2C devices…
    Testing device connections…
    MPU6050 connection failed

    Send any character to begin DMP programming and demo:

    someone help me pls… i need help.

    • Anujkumar Prajapati
      Reply

      make sure you made the connections properly. I also faced this properly and later I realised I goofed up in the connections. By the way are you using UNO or sometyhing else?

      • Iacopo
        Reply

        Hi, with Arduino Uno it Works (can i know the three values what they represent?). With Arduino Mega it doesn’t work (this is what it says on the serial monitor: “DMP Initialization failed (code 1)”). Why?

  • Rahat
    Reply

    Hi,
    Am new to Arduino and programming. Can anyone please tell me as to why the SCL and SDA pins only respond to 5 and 4 alanlog pins respectively of Arduino Uno? How do i use a filter to reduce the interruptions and errors, also how do i calibrate the MPU 6050 to give the readings without much variations.

  • Midhat
    Reply

    Hello! I am using MPU-6050 module on a robot to align it. The bot runs perfectly well and also aligns it properly. But the problem arises when gyro stops working (at the moment we are only using gyro) at variable times. I have tried everything including wiring and programming. But still, it stops working while the bot is running in the arena. If anyone can please tell me the possible reason? Moreover, when we reset the arduino or turn it on and off, it starts working again.

  • harry
    Reply

    i can’;t find toxi lib tried a lot of sites but no toxi.geom or toxi processing can you help

  • SherpaDoug
    Reply

    I am getting garbage ypr values even after a few minutes and I get frequent “FIFO overflow! messages:
    ypr -44.74 51.51 -7.03
    ypr 180.00 -0.01 77.42
    ypr 32.44 37.25 -42.70
    ypr -45.39 -13.32 48.57
    FIFO overflow!
    ypr 20.18 21.63 49.50
    ypr -173.14 12.50 68.97
    ypr -46.04 -32.86 -33.99

    • SherpaDoug
      Reply

      The raw values look plausible and reasonably quiet. I am using a genuine Arduino Uno.

      • SherpaDoug
        Reply

        The first sensor I got was defective. It had one bad accelerometer. I bought two more and they both give one good ypr reading, but successive readings are random numbers. There are still buffer overflows and after a few minutes the program hangs.

        • surya
          Reply

          You have to connect INT pin in MPU6050 to digitalPin2 of arduino UNO.
          I think it should helpful to you

    • Anujkumar Prajapati
      Reply

      Its most probably the serial baudrate. FIFO is likely to overflow at a baudrate of 9600, keep it 115200

  • Rclub
    Reply

    i have MPU-9255/9250/6555/6055 board brought from ebay(http://www.ebay.in/itm/131707198141?aff_source=Sok-Goog). i connected it arduino as explained above. i ran MPU6050_DMP6 program and opened the serial monitor i getting error as “MPU6050 connection failed”.. i connected AD0 pin to GND and modified as “MPU6050 mpu(0x68);” in the program. so what might be the problem?

  • Jason
    Reply

    Hi, great tutorial. I am looking to create a simple 2 axis circuit, like a spirit level. Can this code be modified easily to acheive this? Also i would like to be able to zero/calibrate it before each use?
    Any help would be greatly appreciated.
    J

  • Owen
    Reply

    I have the error “MPUTeapot” program in processing.
    on line 60 : size(300, 300, OPENGL); “The field PConstants.OPENGL is deprecated”
    on line 68 : println(Serial.list()); “Type string [] of the last argument to method println(Object…)

    someone can help me pls !!

  • Abhishek
    Reply

    Hi Aravind,

    I’m working on “AIR MOUSE”(B.E final year project).
    I have a MPU6050 gyro/accelerometer/temperature sensor for mouse control. And “how can I make use of yaw, pitch, raw values from your code to position mouse cursor on computer”. I want real co-ordinates of mouse on PC from the tilt of the MPU6050 IMU sensor. How to do that? I am using Arduino UNO R3. Sorry for my bad English.

    All help is appreciated!
    Thanks,

    • Owen
      Reply

      Hey Abhishek, i also doing air mouse as my final year project. can u gv me some guiding or programming code for me for my final year project. thx. u can email to my email owenchoong96@gmail.com

      • Cally Nnaemeka
        Reply

        I do get the same error.<<"MPUTeapot” program in processing.
        on line 60 : size(300, 300, OPENGL); “The field PConstants.OPENGL is deprecated”
        on line 68 : println(Serial.list()); “Type string [] of the last argument to method println(Object…) Do you have solution to this?

    • surya
      Reply

      Hi Abhishek,
      Firstly i want to suggest you that you should use Arduino Leonardo for making this project.
      It will be simplest way to making this project.you have to studied about Leonardo otherwise send me a mail 1998sveer@gmail.com
      I can can give you full details about that.
      Thanks

  • najeeb
    Reply

    Arduino: 1.6.7 (Windows 7), Board: “Arduino/Genuino Uno”

    C:\Dell\Drivers\J67GBH\download\arduino-1.6.7-windows\arduino-1.6.7\examples\MPU6050\MPU6050\Examples\MPU6050_DMP6\MPU6050_DMP6.ino:46:20: fatal error: I2Cdev.h: No such file or directory

    #include “I2Cdev.h”

    ^

    compilation terminated.

    exit status 1
    Error compiling.

    This report would have more information with
    “Show verbose output during compilation”
    enabled in File > Preferences.

    i am getting this error and i did every thing you said to do in above comments.
    can you give me a single combined file so that i can directly compile anbd upload to the arduino.

  • venkatt
    Reply

    can i use the same processing IDE for Triple Axis – ADXL335

  • Ronen
    Reply

    On Arduino nano, iv’e soldered
    D2->INT
    5V->VCC
    GND->GND
    A5->SDA
    A2->SCL

    and the program fails:

    Initializing I2C devices…
    Testing device connections…
    MPU6050 connection failed
    Initializing DMP…
    DMP Initialization failed (code 1)

    Is it because of the different wiring? Is it possible to fix the program with the current wiring, or should I fix the wiring?

    Thanks,
    Ronen

    • Alain
      Reply

      Ronen,

      The wiring is wrong:
      SCL ==> A5
      SDA ==> A4

      • Ahmed
        Reply

        Please I am facing the same issue and I made sure of all the connections but nothing changes. what could be the issue here ?

  • niek
    Reply

    for windows (7, 8 , 9,10)the key is the user IDE libraries dir is in your documents folder..

    C:\Users\[username]\Documents\Processing\libraries
    and there the toxiclibs_p5 and toxiclibscore subdir

    https://bitbucket.org/postspectacular/toxiclibs/issues/59/no-library-found-for-toxigeom-and

    • Alain
      Reply

      The wiring is wrong:
      SCL ==> A5
      SDA ==> A4

    • Alain
      Reply

      Sorry, was meant for Ronen

  • Dmainmon
    Reply

    “After installing the processing IDE, next you will need to download a library called “Toxi”. This library is necessary for our Arduino MPU 6050 processing example. Download the latest zip file for the library from here.”

    I was able to download and install the processing IDE but not the Toxi library from the link.

    Where can I download this library? I want to test out the MPUTeapot.

  • TALHA
    Reply

    i just cant add the toxi file into the lib of processing plz tell me

    • allen
      Reply

      It is usually under Documents\Processing\

  • Akbar MH
    Reply

    I have the error “MPUTeapot” program in processing.
    on line 60 : size(300, 300, OPENGL); <> “The field PConstants.OPENGL is deprecated”
    on line 68 : println(Serial.list()); <> “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-varargs invocation, or pass individual arguments of type Object for a varargs invocation.”

    can you help me?

  • Radio wave
    Reply

    In general, Gold wave in general, is a procedure where vitamins, drugs, substances and herbs
    are combined together in a fixed formulation and injected into the middle region of the skin (named mesoderm) to destroy fat and cellulite.

  • ashfak
    Reply

    how to add the toxi library in processing 3.0??? i tried but failed again and again :(

  • moni
    Reply

    Hi friends.
    i am moni from delhi Hi, i’m currently working on a project and i’m wondering if there cool display of the speed in on the window where the plane is displayed, thank you very much for this
    thank you

  • moni
    Reply

    Hi friends.
    i am moni from delhi Hi, i’m currently working on a project and i’m wondering if there is any way to show a cool display of the speed in on the window where the plane is displayed, thank you very much for this
    thank you

  • James Rose
    Reply

    Hi , I’ve this error when compiling the code in your library that I’ve downloaded. Error stated : MPU6050_DMP6.ino:46:20: Fatal error : I2Cdev.h :No such file or directory compilation terminated.

    Is anyone able to help me? Will be really grateful to you guys.

  • Ankur Upadhyay
    Reply

    hiii I’m using the mpu-6050 but after doing all the steps
    I got an error in the serial monitor “MPU6050 connection failed” so what should I do now
    I’ve checked all the connections

  • Sarvesh Thakur
    Reply

    I am having problem uploading this code. its stuck. what to do?

  • skoz
    Reply

    Hi, i’m currently working on a project and i’m wondering if there is any way to show a cool display of the speed in m.s-1 on the window where the plane is displayed, thank you very much for this tutorial tho.

  • Ankur
    Reply

    Using it for the first time . please help me on how to configure mpu for a c motion.

  • Daniel
    Reply

    Hi Arvind.

    I’m using MacBook Pro for this MPU 6050 with Teapot. I placed the folder “toxiclibs-complete-0020” into the folder “libraries”. But when I ran Processing, I got the error message below:

    No library found for toxi.geom
    No library found for toxi.processing
    Libraries must be installed in a folder named ‘libraries’ inside the ‘sketchbook’ folder.

    Is the “toxiclibs-complete-0020” folder supposed to be in the SAME folder “libraries” as with the folders “I2cdev” and “MPU6050” ?

    Thanks.

    • Arvind Sanjeev
      Reply

      toxic libraries should be installed in the “libraries” folder of Processing and not Arduino.

  • AmieraSyafika
    Reply

    Hai Arvind;

    i’m now doing a project for balancing a rov. i use mpu 6050 as my imu sensor. i have some problem on how to connect my motor with the sensor. i use l293d. i take the reading value from #define OUTPUT_READABLE_YAWPITCHROLL

    my question is, how i can modified the coding? let say if my yaw value is >30 i need to on the motor until it reach 30. can you help me? thank you

      • Habib
        Reply

        Hi Arvind
        I am also getting the same problem as below
        //———————error—————————
        No library found for toxi.geom
        No library found for toxi.processing
        Libraries must be installed in a folder named ‘libraries’ inside the ‘sketchbook’ folder.
        //——————————————————————————————-
        I unzip and pasted the folder “toxiclibs-complete-0020″ in processing Library folder but still getting this error
        please let me know on this

        regards
        Habib

  • Ahsan
    Reply

    Hi Arvind.
    I am receiving this error. i have installed I2C library as you mentioned but error is still there.

    MPU6050_DMP6.ino:48:20: fatal error: I2Cdev.h: No such file or directory

    Please Respond.
    Best Regards.

    • Arvind Sanjeev
      Reply

      Try re installing arduino and double check if the library is in “libraries” folder.

  • Stephanie
    Reply

    Hi Arvind,

    When you say value for the output of the vibration motor..

    What exactly should I put in as the ‘value’ I have tried ‘ypr’ ‘y’ etc but no such luck :(

    Hope you can help!

    Stephanie

    • Arvind Sanjeev
      Reply

      You will see this line in the code:
      Serial.print(ypr[0] * 180/M_PI);
      Here ypr[0] * 180/M_PI is the yaw value, so do this:
      int yaw= ypr[0] * 180/M_PI
      if(yaw > thresholdValue)
      {command to turn ON motor
      }else command to turn OFF motor

      • Stephanie Smith
        Reply

        Hi Arvind,

        Thanks! I shall give it a go!

        Stephanie

  • AmieraSyafika
    Reply

    Hello Arvind;

    i’m doing a project for rov. i use the imu sensor to detect the motion of the rov. and i want to interface the motor with the arduino. is it possible? i use dc motor. where can i modified the code? i’m beginner in arduino. thank you

  • Mahmoud
    Reply

    Hello Arvind,

    First of all, I am really thankful you made this tutorial. In addition, I want to thank you for taking from your time to answer our (not so smart) questions.

    Now that I won your attention :D, I trying to make my robot know its place relative to a starting position. Can I use this board to achieve this objective? If so, then how? My idea is that I input initial position (x, y, theta) and use some sort of an equation to get the new co-ordinates (x’, y’, theta’) based on the orientation angle and the distance (or time?) covered by the motors in that direction.

    Please include as much details as you can.

    Thanks Again.

    Mahmoud

  • POOL
    Reply

    In coding, it complete to upload in arduino and in processing program it has roll pitch yaw values but airplane 3 D picture cannot move follow with imu move. how can i do it?
    sorry if my english isn’t good

    • Arvind Sanjeev
      Reply

      If the airplane doesn’t move at all then it cannot read the values from arduino, make sure you installed all the libraries correctly for processing and set the serial port to the right port and try again.

  • Asad
    Reply

    I downloaded the I2Cdev folder and placed it in Arduino-> libraries but when I burn the code on Arduino the software says

    “MPU6050_DMP6.ino:46:20: fatal error: I2Cdev.h: No such file or directory”

    • Arvind Sanjeev
      Reply

      Did you try restarting arduino? Also try re installing arduino if it doesnt work.

  • Stephanie Smith
    Reply

    Hi Arvind,

    Is it possible to add in a Vibration motor output alongside the visual output..?

    In terms of the vibration, could it go off say when the roll value is >20?

    Look forward to hearing from you!

    Thanks,

    Stephanie

    • Arvind Sanjeev
      Reply

      Definitely, you can do that. Interface the motor to arduino and use simple if/else statements to do the same.

      • Stephanie
        Reply

        Hi Arvind,

        My coding skills are terrible, could you possibly give me an example of how it would be?

        Thanks so much,

        Stef

        • Arvind Sanjeev
          Reply

          Hi Stephanie, you can start by learning to interface a motor with arduino, you can use this motor: https://www.sparkfun.com/products/8449
          And there is not much coding involved here. Just:
          if(value>20)
          Command for vibrating motor (usually: digitalWrite(pin,HIGH))
          else
          command for switching OFF the motor (digitalWrite(pin,LOW))
          And if you are a beginner to arduino, this free eBook will help: http://diyhacking.com

          • Stephanie Smith
            Reply

            Thankyou SO much!

            I shall let you know how it goes!

            Thanks,

            Stephanie

          • Stephanie Smith
            Reply

            But..just a quick question..

            In terms of adding into the coding where is best for it to be entered?

            Thanks!

            • Arvind Sanjeev
              Reply

              You can use it soon after the print statement of the angle values.

  • Sujith
    Reply

    Hi Arvind,

    Could you tell me which values are used for precise orientation detection. I tried YPR but all three values are every sensitive. You have any idea about this?. Thanks a lot for this tutorial btw. :)

    • Arvind Sanjeev
      Reply

      Hi Sujith, did you try Euler angles?

      • Sujith
        Reply

        Hey , i believe i can use the values. So if i want to perform some operation when there is a change in the value for a particular orientation, simple if statements should do right?

  • Tozz
    Reply

    Hey. Great writeup. I just got my 9150 board working (so far it is using the standard 6050 6dof libraries. Migrating to 9150 9dof is next). So those working on 9150, the writeup above works great for the initial step to qualify your environment and setup. A couple of clarifications for people who may have read other blogs about teapot demo: first, I downloaded Processing 2.2.1 rather than 1.5 and it worked like a charm first time. Just be sure to rename the directory from procesing-2.2.1 to Processing. Also I am using a Nano clone from China and it works great at 57600 baud. I haven’t checked out the behavior of the LEDs yet.

    I’ll follow up once I get the 9150 9dof working.

  • Stephanie Smith
    Reply

    Hi Arvind,

    My sensor seems to be working but the visual output of the plane is just showing a grey box..(In Processing)

    I have screenshotted this but I am unsure how to drop this into this post?

    Thanks,

    A stressed final year design student (Stephanie)

    • Arvind Sanjeev
      Reply

      Hi Stephanie,
      Did you try checking the port that the processing software is listening to? Also, try going through a free processing example codes to check if something is wrong with the installation.

      • Stephanie Smith
        Reply

        Hi Arvind,

        The port seems to be working fine as before I change the code to output in Processing, it is reading figures fine..

        What type of example code should I try that may get the visual working?

        Thanks so much,

        Stephanie

        • Arvind Sanjeev
          Reply

          Just try running any from the File–> Examples menu. Installing a different version of processing can also be something you can try.

          • Stephanie Smith
            Reply

            Hi Arvind,

            It seems to be my computer and possibly the Java as I have transferred to the University computers and it works fine.

            So thanks for your help! :)

            Thanks,

            Stef

  • Greg Moser
    Reply

    Hey Arvind, just wanted to take a moment and thank you for your tutorial! After a few hiccups (Read the directions AND follow them – libraries need to be installed!)

    Works like a champ!!

  • AmieraSyafika
    Reply

    hi, i cannot find the sketchbook folder in “step 3:Modelling the values from Arduino MPU 6050 in 3D using processing”. i already create my own libraries folder, but it still give me error. i’m using windows-32 bits. can you help me?

  • Manfred
    Reply

    Hi Arvind,

    yesterday i had my first experience with ARDUINO.

    Your tutorial is great. I got everything working like it’s discribed here with an MPU 6050 connected to a ARDUINO Nano V3.

    Thanks!

  • Israr
    Reply

    Great work.
    The ypr values shown are angle values I believe. How to convert the integer values appearing on the serial monitor into angle, say 30 degree, 45 degree etc. Since the data sheet of the MPU gives scaling factor for angular rate (degree per second) and acceleration (g) not the angle (degree). Thanks

  • David
    Reply

    Arvind,
    How do you slow down the rate at which the MPU6050 is read?
    Awesome Tutorial!
    Thanks!
    David

  • oscar
    Reply

    Hi Arvind,

    I am developing a control system to stabilize a quadropter, to do this I need the angles and their angular velocities, but as the angle measurements are a bit noisy when I calculate the angular velocities as the difference of the current and previous angle measurement divide it by sample time (0.02 s) I get big numbers, is there any way of reading directly from the IMU this values.

    Thanks,

    • Arvind Sanjeev
      Reply

      Hi Oscar,
      You can get Euler, YPR values, etc from the MPU DMP example sketch. You can use that for feeding it into the stabilisation code for the quadrotor.

  • AmieraSyafika
    Reply

    Hi, can i know if this tutorial is suitable for 9dof imu? thank you

    • Arvind Sanjeev
      Reply

      You will have to use the library for 9DOF imu, get it by searching online. Everything else is kind of the same.

  • Tomek
    Reply

    Hi!

    Do You guys know in which file can I change the pinout settings? I have MPU6000 connected to ATMega2560 and I am trying to customize this library to that sensor. I will be greatfull for some help :)

    • Arvind Sanjeev
      Reply

      Hi Tomek, this sensor uses SDA and SCL lines for communication, you can only connect them to the corresponding lines on the arduino. I dont think you can change the pin out hence.

  • David
    Reply

    I’m trying to get acceleration in gs, how do I do this?

    Awesome Tutorial I’m getting data i’m just not sure of the units.

    I’m using #define OUTPUT_READABLE_WORLDACCEL in the code

    Thanks!

  • Timothy Peterson
    Reply

    When I open up the serial monitor, only Initializing I2C devices shows up. Testing device connections does not. What do I need to change.

    • Arvind Sanjeev
      Reply

      Try resetting and checking device connections. Have you wired the INT pin to digital pin 2? If that doesn’t work, try running the other example code: MPU raw.

  • Ross
    Reply

    Hi,
    I’m trying to write code that uses the above code as a frame work and writes the raw acceleromter data to an SD card, however I keep getting a FIFO overflow because it takes to long for the arduino to write to the SD card. Is there any work around for this, even if it meant a slower sampling rate? (ideally I’d like to keep the same sampling rate) I couldn’t figure out how to set the sampling rate.
    Any help would be greatly appreciated

    • Ross
      Reply

      I have changed the last byte of line 305 of MPU6050_6Axis_MotionApps20.h to change the FIFO rate, I had to change it to “0x1D” in order to get the FIFO overflow to stop. By printing the time every loop I can see that I loop though every 157 milliseconds. Is there any way to get this to work at a faster rate?

      • Arvind Sanjeev
        Reply

        Trial and error is the best way to go, if you try increasing the speed too much, overflow will occur.

    • Arvind Sanjeev
      Reply

      Try searching for MPU6050 fifo rate changing procedure, and then change the rate.

      • Ross
        Reply

        Thanks for the help

        • Yahya Gilany
          Reply

          I’d be really grateful if you would share if you could solve this !
          I’m Still getting the FIFO overflow error
          I also changed the that last byte you mentioned above
          it did remove that message but still doesn’t get me any readings from the sensor !!

  • pranav
    Reply

    can i know how to draw a sketch using mpu6050 and arduino? i mean if the sensor moves the direction of the path need to be shown virtually in the processing software.!

    • Arvind Sanjeev
      Reply

      You will have to search for processing tutorials about this, and learn more on processing. You can use the coordinates from the sensor and then use it to draw on a xyz plane.

  • Saif
    Reply

    Initializing I2C devices…
    Testing device connections…
    MPU6050 connection failed

    Send any character to begin DMP programming and demo:

    How to get rid of this, my connections is perfect. I tried this device earlier and it worked, but I dont know why its not working right now.

    • Arvind Sanjeev
      Reply

      Did you connect the interrupt pin on MPU to digital pin 2? Also, what is the output for the MPU raw example program?

  • rich1812
    Reply

    Hi there,
    I am playing with the MPU6050, it is connected to a Mega. I use the non-modified MPU6050_DMP6.ino. Once I started the program, the 6050 spits out data just fine. However, as soon as I tile the 6050 to about 45 degrees, it instantly output data, why is that?

    • Arvind Sanjeev
      Reply

      Couldn’t understand your question, output data?

      • rich1812
        Reply

        I meant the data displayed on the serial monitor.
        When I started to run it, the data shown on the serial monitor just fine, but once I tile the breadboard with the 6050 attached, when it reaches to about 45 degrees, the data stops as if it got stuck, and also it seems like it happens sooner if I tile the breadboard very quickly. I wonder why that is? Thanks.

        • Arvind Sanjeev
          Reply

          I would suggest that the connections are getting loose while you are doing this, else if you are sure- that is not the case, then try searching for MPU6050 fifo buffer rate increasing procedure and increase/decrease the buffer rate until the problem is resolved.

  • Ishan
    Reply

    Hi , I just installed the Processing software and there is no sketchbook folder in it. And due to that i am constantly getting an error that Toxi not found.

    • Arvind Sanjeev
      Reply

      Like, mentioned in the tutorial. If you dont have a sketchbook folder, you would have to create a new one, as detailed in the tutorial.

  • Ramnath Shanbhag
    Reply

    Hello Arwind sir,
    I had follow your tutorial and test the MPU6050. Its really awsome.Thanks for this.
    Now I want to make self balancing robot. I have Arduino UNO and motor driver IC L293D. Can you please give me the connection digram and code for this.

    • AmieraSyafika
      Reply

      hi ramnath;

      i also doing balancing robot and i want to connect the mpu 6050 to ic l293d. perhaps do you have any solution yet? do you mind to share?

      thank you

  • André Hilgersom
    Reply

    Hmm,

    That was not what is was supposed to look like ..
    Is : better ..?

  • André Hilgersom
    Reply

    Hi Arvind and all,

    I found the solution for the getMotionStatus error during compiling



    Now I have a nice little Teapot (?) moving on my screen, but also thanks to your clear tutorial !

    regards, Andre

    • Arvind Sanjeev
      Reply

      Awesome :) what was the solution to the problem?

      • Nicolás Quintieri
        Reply

        Just change the return type of the getMotionStatus() function in MPU6050.cpp (line 1997) from “bool” to “uint_8”. That’s all there is to it (at least that’s what worked for me).
        Regards.
        Nic

    • Sandro
      Reply

      What was the solution ? PLease share… same problem here.

      • Sandro
        Reply

        Thanks Terminator. That solved it.
        Detaling it a bit:
        – Open the MPU6050.cpp and look for getMotionStatus;
        – Change the text “bool” to “uint8_t” before the getMotionStatus line;
        – save the file;
        – Run your sketch and be happy.

      • Arvind Sanjeev
        Reply

        Check out the comments here, just need to change the data type :)

  • André Hilgersom
    Reply

    Hi Arvind,

    Great tutorial, I would love to get this working as well but I get the exact same “getMotionStatus” errors as amarnath and Rishabh during compiling.

    I am using Arduino 1.6.1

    Hope you can Help, regards André Hilgersom

  • Muwaffaq
    Reply

    the following appeared when serial monitor was opened

    Initializing I2C devices…
    Testing device connections…
    MPU6050 connection successful

    Send any character to begin DMP programming and demo:
    Initializing DMP…
    Enabling DMP…
    Enabling interrupt detection (Arduino external interrupt 0)…
    DMP ready! Waiting for first interrupt…

    in your tutorial i dont see ” waiting for first interrupt ”
    why is it so?

    • Arvind Sanjeev
      Reply

      Have you connected interrupt pin of MPU to digital pin 2?

      • Muwaffaq
        Reply

        I connected MPU through a sensor sheild I am not sure where the interrupt pin is connected, (maybe pin 3) if so how to change this in the code.

        Also i got an compiling error ( with other program )

        C:Program FilesArduinolibrariesMPU6050MPU6050.cpp:1997:6: error: prototype for ‘bool MPU6050::getMotionStatus()’ does not match any in class ‘MPU6050’

        I think this has something to do with the library ( I downloaded from here ) ,
        How to overcome this

        • Arvind Sanjeev
          Reply

          Hey, int pin should be connected to digital pin 2 of arduino. Also, which version arduino are you using?

  • FrenchElk
    Reply

    Very good tutorial.
    For those who use the Sparkfun Breadboard (https://www.sparkfun.com/products/11028), follow the wiring:

    MPU6050 — Arduino
    VDD -> 3.3V
    INT -> Pin2
    FSYNC -> GND
    SCL -> PinA5
    SDA -> PinA4
    VIO -> VDD

  • Rishabh Maurya
    Reply

    I am having a problem uploading the code to my arduino mega even though i have added the library… It shows a compiling error i.e.
    C:UsersRINI-PCDocumentsArduinolibrariesMPU6050MPU6050.cpp:1997:6: error: prototype for ‘bool MPU6050::getMotionStatus()’ does not match any in class ‘MPU6050’
    bool MPU6050::getMotionStatus() {
    ^
    In file included from C:UsersRINI-PCDocumentsArduinolibrariesMPU6050MPU6050.cpp:37:0:
    C:UsersRINI-PCDocumentsArduinolibrariesMPU6050MPU6050.h:611:17: error: candidate is: uint8_t MPU6050::getMotionStatus()
    uint8_t getMotionStatus();
    ^
    Error compiling.

    • Arvind Sanjeev
      Reply

      Which version arduino are you using?

      • Rich W.
        Reply

        I’m having the exact same problem with Arduino 1.6.1

        • Rich W.
          Reply

          I downloaded the files from git-hub and placed then in the library but still get the same error on compile.

          • Rich W.
            Reply

            Also tried it on a different computer, but still failing the compile with the following error

            C:UsersRichardDocumentsArduinolibrariesMPU6050MPU6050.cpp:1997:6: error: prototype for ‘bool MPU6050::getMotionStatus()’ does not match any in class ‘MPU6050’
            bool MPU6050::getMotionStatus() {
            ^
            In file included from C:UsersRichardDocumentsArduinolibrariesMPU6050MPU6050.cpp:37:0:
            C:UsersRichardDocumentsArduinolibrariesMPU6050MPU6050.h:611:17: error: candidate is: uint8_t MPU6050::getMotionStatus()
            uint8_t getMotionStatus();

            • Arvind Sanjeev
              Reply

              Hi Rich,
              You just need to change the datatype: bool. The solution has already been posted in earlier comments in this tutorial page from other Makers, please check it out.

  • amarnath
    Reply

    hello sir ,
    i am getting an error and please tell me how to solve and the error is

    C:UsersamarDocumentsArduinolibrariesMPU6050MPU6050.cpp:1997:6: error: prototype for ‘bool MPU6050::getMotionStatus()’ does not match any in class ‘MPU6050’

    bool MPU6050::getMotionStatus() {

    ^

    In file included from C:UsersamarDocumentsArduinolibrariesMPU6050MPU6050.cpp:37:0:

    C:UsersamarDocumentsArduinolibrariesMPU6050MPU6050.h:611:17: error: candidate is: uint8_t MPU6050::getMotionStatus()

    uint8_t getMotionStatus();

    ^

    Error compiling.

    This report would have more information with
    “Show verbose output during compilation”
    enabled in File > Preferences.

    • Arvind Sanjeev
      Reply

      Hi Amar,
      Which version arduino are you using? Make sure you have the latest one and the latest MPU6050 library installed and try again.

      • Nazry Halim
        Reply

        Dear arvind,
        I had followed all steps, but it says that the toxiclibs library have to put in “libraries” folder in the “sketchbook” folder..

        I also did this for several times..
        but it still cant..

  • Abhilash
    Reply

    its a great tutorial but i got a weird problem were i can get readings from mpu only when i connect the init pin to tx pin or dig pin 1 of arduino uno .i don’t know why but i got yaw pitch roll and then there’s another problem the values stops after sometime .iam working on a quad and bcz of this i cant get it to stabilize .Sir any help for me

    • Arvind Sanjeev
      Reply

      You mean INT and not INIT right? INT is the interrupt pin, you should connect it to digital pin 2 for the code to work successfully.

      • Abhilash
        Reply

        My bad, it worked with a new sensor .But i never got to fly the Quadcopter stable with it ,used a kk board instead, thanks for your reply

  • Or
    Reply

    Thank you!
    I had this sensor for 2 years did not know it was so good.
    earned a Subscriber…

    one question though, the modul freezes when i shake it…can you give me an advice on that?

  • Joseph
    Reply

    I have followed the instructions exactly, but when I open the serial monitor, set the baud rate to 115200, and reset my Arduino (Uno), it [the serial monitor] displays “Initializing I2C Devices…” for a very long time and nothing else. I have quintuple checked the connections to my MPU device, but I cannot find any errors. Any ideas on what might be causing this problem? (When I tried uploading with the MPU_raw file instead I got only “‡‡¸¸¸‡¸¸‡‡¸¸‡‡‡‡‡‡‡” instead of “Initializing I2C Devices…”)

    • Arvind Sanjeev
      Reply

      If even the raw file is not working, you need to also check the baud rate on the setup() and the serial monitor tab setting. You should maybe try with another mpu module if you are also sure that the connections are correct.

      • Maya
        Reply

        Hey, having the same issue. double checked everything, and in both raw and the DMP6 versions do nothing after “Initializing I2C devices…”. Wondering if my sensor is broken (is there a way to check that? I don’t have another sensor…).
        Thanks!

  • kapil goswa.i
    Reply

    it is nt working on win 8
    its showing smthng diff in other language
    n it is nt showing the output without procesing
    i want output on serial moniter

    • Arvind Sanjeev
      Reply

      Did you try MPU_raw example code? Both the codes will show output on serial monitor.

    • pranav
      Reply

      You might have set wrong baud rate.. same thing happened to me. Try searching in the code baud rate set in the sketch and use same baud rate to get data.

  • pranav
    Reply

    hi
    its telling me mpu6050 connection failed
    whats the problem?

    • Arvind Sanjeev
      Reply

      Try checking the connections and power. Did you do it the same way as in the tutorial?

      • pranav
        Reply

        connections and power are fine. the led on mpu 6050 is also working..

  • QuanTran
    Reply

    Dear Arvind,
    i followed all steps, and it works very well. Thank you so much for sharing.
    I have some question :
    1, if I let INT not connect to port D2 arduino, for e.g D8, how can I change the code make it run correctly?
    2, if I want to change the sampling frequency of result ( now is 115200, right?) which do I have to change?

    • Arvind Sanjeev
      Reply

      Hey,
      1.There are only 2 interrupt pins on arduino. On digital pins 2 and 3. So just edit the code initialising the INT.
      2.Serial.setup(9600);

  • Manan
    Reply

    hey,
    i am having an mpu6050 and i want to interface it with 8051 microcontroller ( AT89S52). can you please help me with it in any way?
    if you can then please email me @ manannarang2010@gmail.com
    Thankyou

    • Arvind Sanjeev
      Reply

      Hi, I a havent worked on the 8051 much so dont know. Also 8051 is quite outdated I am confused as to why you would want to do this. I would recommend arduino.

      • Manan
        Reply

        Hey,
        Thank you for your reply.
        Its a college project. i have learned 8051. Moreover i don’t have any idea of adruino. And i have very less time to learn Adruino and i am not getting anything about this damn thing.
        anyway thank you for your time.

        • Arvind Sanjeev
          Reply

          Check out this beginners eBook on Arduino: http://diyhacking.com The learning time for arduino would be just 1/4th that of 8051.

          • manan
            Reply

            Hey, thankyou for your suggestion. Well, I am tryin to make a quadcopter, size is 30 cm. An automated quad specifically. My propeller size is 13 cms. And I am preferring to make the board myself as to fit in proper size and manage the weight. Please tell me the adruino board which is smallest and lightest and easily available and wont have any problem with mpu6050. I read your book. Its really nice.
            Thankyou.
            Will be waiting for your reply.

  • fady
    Reply

    i need help in using imu in positioning

    • Arvind Sanjeev
      Reply

      Details please!?

      • fady
        Reply

        i am trying to get distance from imu as i can get accelaration and angle can you help me ?

        • Arvind Sanjeev
          Reply

          Hello,
          Based on my experience, getting velocity or distance using accelerometers are really difficult, you need a lot of complex processing to be performed on it. Getting the angle is easy, you can check out this tutorial for that.

  • BOFOR
    Reply

    What should I do to make it work Arduino MEGA

    • Arvind Sanjeev
      Reply

      Find out the SDA and SCL pins on Mega and connect it the same way. You can use the same code.

  • clint
    Reply

    Thanks for all your help.

  • Anurag
    Reply

    Can you upload the code for quadcopter using arduino uno and mpu6050

  • Pradeep
    Reply

    Have you ever used MPU6050 to get the position and the velocity from the acceleration and gyroscope data

    • Arvind Sanjeev
      Reply

      Getting speed accurately from it would be difficult, would require a lot of processing. But you can use it to get the correct attitude of an object in 3D space.

  • BOFOR
    Reply

    what is the DMP Initialization failed (code 1)

    • Arvind Sanjeev
      Reply

      This mainly occurs due to connection errors or hardware malfunctions.

  • Stephanie Smith
    Reply

    Hi!

    Great tutorial!

    However, once the processing code is played..the visual screen is just grey with no simulation of the plane..

    We are also seeing ‘FIFO overflow!’ in the bottom black box..

    Do you possibly know how we can solve this?

    Thanks!

    • Arvind Sanjeev
      Reply

      Hi, did the MPU6050_DMP sketch work fine? Did it give the proper values? Also, even if the values are not coming, you should atleast see the stationary plane on the processing window.

  • parikshit mishra
    Reply

    sir,
    initializing i2c devices..
    taking too long…and is stuck there…what should i do??

    • Arvind Sanjeev
      Reply

      Try resetting the arduino board, also check if the sensor is MPU6050 and double check the connections. Do check baud rate (115200).

  • Bryce
    Reply

    Just an update: I had my GY-87 board powered off of the wrong pin on my Ardiuno pro mini. Once I switched it from the “RAW” pin to the “VCC” pin it worked like a charm.

  • Ali
    Reply

    Hi
    thanks for your reply.
    i ran the raw file, it returns MPU6050 connection failed and
    a/g: 0 0 0 0

    Whats wrong?:(

    • Arvind Sanjeev
      Reply

      Please check if the chip on the sensor is indeed MPU6050, next double check the connections and power supply.

  • Bryce
    Reply

    Partially. It says MPU 6050 connection successful but just returns a single line:
    a/g: 0 0 0 0 0 0.

    Its also worth mentioning I’m using the GY-87 10 DOF board that also has the HMC5883L on it and I ran its raw sketch as well with the same results… It connects to the device but I get all zero for values.

    • Arvind Sanjeev
      Reply

      Hi, you should download the library for the GY-87 board. This library supports only MPU6050.

  • David Randolph
    Reply

    Thanks for the great tutorial. It really got me out of a ditch today.

    Thanks again,
    Dave

  • Bryce
    Reply

    Hi, The serial monitor seems to be getting stuck on”Initializing DMP…” Here is the full read out:

    Initializing I2C devices…
    Testing device connections…
    MPU6050 connection successful

    Send any character to begin DMP programming and demo:
    Initializing DMP…

    Any idea what could be causing this?

    Thanks in advance

  • Ali
    Reply

    Hi
    I followed all the steps but i keep getting “DMP Initialization failed (code 1)” error.:(
    I checked all my connections and they are fine.

    what could be the problem?any idea?

    • Arvind Sanjeev
      Reply

      Hi, please check if the MPU6050_raw sketch works, and if its values are correct and let me know.

  • Roger
    Reply

    Hi everyone.

    I am using Arduino Fio with Xbee Adapter. Every program works fine.

    Connecting Sparkfun MPU6050 however, with the MPU dmp file from I2Cdevlib Serial Monitor says: DMP Connection failed.

    Baudrate Xbee is 57600. Serial Monitor as well.

    What could be the Problem?

    • Arvind Sanjeev
      Reply

      Can you try using 115200, to see if that solves the problem?

  • Rishi
    Reply

    Hello sir. I did everything correctly and got the output on my serial monitor. But when I tried it in processing software, it says

    “frame buffer objects are not supported by this hardware (driver)”… though I followed up all the instructions!

    What may be causing the problem sir?

  • Pasindu Kuruppuarachchi
    Reply

    Hi great tutorial and 100% working :)
    i want to connect more than one gyro sensors in my application :) how can i do that ?

    Thanks for this great tutorial :) hope to get a answer soon :D

    • Arvind Sanjeev
      Reply

      Hi, thanks :)
      Check this: http://forum.arduino.cc/index.php?topic=76204.0 You can only read one I2C sensor at a time using arduino, else you will be required to have one arduino per MPU.
      Or if you dont want to read the sensors simultaneously, you can connect all of them to the same i2c line and assign different addresses.

  • MK
    Reply

    I’m getting the same error message as you. I’m using the Mega as well. Can you explain what you did to fix this problem? Thanks!

    • Arvind Sanjeev
      Reply

      Hey, can you please explain the errors? I didn’t understand what you meant by the same errors.

  • Mark
    Reply

    So close, and yet so far! Like Chris, I didn’t have a libraries folder directly in the processing-2.2.1 folder, but there was a “plain” processing folder that did contain a libraries folder (when I deleted this folder, and saved a new sketch, the folder was recreated). However, after copying the extract of the toxiclibs-complete-0020.zip file into that “libraries” folder, I still get the following error

    No library found for toxi.geom
    No library found for toxi.processing
    Libraries must be installed in a folder named ‘libraries’ inside the ‘sketchbook’ folder.

    I went a step further and created a “sketchbook” folder and put the “libraries” folder that contained the unzipped “toxiclibs-complete-0020” folder in it, and still, no luck. I also put the subfolders of “toxiclibs-complete-0020” directly in the “libraries” folder and that didn’t help either.

    What am I missing?

    • Arvind Sanjeev
      Reply

      You did try restarting Processing after each of these changes right?

  • kishore
    Reply

    first change baud rate to 115200.
    apart from that similar program of mine is not working
    as arduino is waiting for “press any key to continue”
    even i press something in matlab, arduino is not receiving it
    this is the issue.
    can someone help please

    • Arvind Sanjeev
      Reply

      Hey in the arduino code, remove the initial lines that wait for the key press, so that the code begins automatically.

  • chfakht
    Reply

    thanks ,
    have you a matlab code that do tthis and eventully save datas into a file

    i tried this :
    arduin=serial(‘COM14′,’BaudRate’,9600); % create serial communication object on port COM18
    fopen(arduin); % initiate arduino communication
    tic;
    while (toc<=20) % stop after 20 secs
    data = fscanf(arduin,'%f');
    end
    fclose(arduin); % end communication with arduino

    but i get an error :
    Warning: Unsuccessful read: Matching failure in format.

    • Arvind Sanjeev
      Reply

      I’m sorry I haven’t tried it on Matlab. Did you try googling for “read data from arduino through Matlab”? I am sure lots of people would have tried it :)

  • Mauricio
    Reply

    Hi,

    I have a problem with the 3D model, which doesn’t moves accordingly with the sensor. I have the MPU-6050 GY-521.

    All the other examples work fine.

    Do you know what is the problem ?

    Thanks

    Best

    • Arvind Sanjeev
      Reply

      Do you get any errors on the processing IDE? And hope that you installed the libraries correctly. P.S. You’ll have to first run the arduino sketch for the teapot and then the processing sketch.

      • Mauricio
        Reply

        Hi,

        I don’t get any error int the processing IDE. And I installed all the libraries correctly.
        Yes. The processing sketch is receiving the data. But the plane doesn’t move like in the video. Is like 1 axis is OK, and 2 are wrong.

        • Arvind Sanjeev
          Reply

          Can you run the sketch MPU6050_DMP6 and see if the values for the other two axes from it are correct?

          • Usman
            Reply

            I have the same problem i checked the values like you said, they are the same but the plane is static. plz help me Thanks and BTW great tutorial really.

  • chfakht
    Reply

    Hi , i need to know how to save MPU6050 ((gyroscope + accelerometer ) ) datas in matlab (matlab script that communicate with the arduino)
    thanks

    • Arvind Sanjeev
      Reply

      You can open the serial port for the arduino on matlab to view the data.

  • Rodolfo
    Reply

    I am doing a school project for Mechanical Engineering. I wasted 3hours looking for how to use the MPU6050. You have the best tutorial. Thank you

  • jimmy hyun
    Reply

    I could see the small plane but standstill. Instead I got this error. OpenGL error 1280 at bot beginDraw(): invalid enumerant.
    Any clue?

  • tabish
    Reply

    ok thanks ill check it then inform u

  • Tabish
    Reply

    Arduino uno.yes Ive also got other errors too inthe list.how do I show these tell me the procedure to atach or share with u a scren shot of errors thanks

    • Arvind Sanjeev
      Reply

      Did you install the I2C library too? Check the updated tutorial for it. You can share the screenshot by uploading it in google drive and sharing the link here.

  • bharath
    Reply

    I want my sensor to locate virtual grids of 9 in number (3*3 matrix form) where they are virtual….I would visualise them in front of me and my sensor should be able to detect the grid,to make some kind of code..Is it possible to do it with IMU …….Can U mail me at bharath4034.madala@gmail.com if possible as in our university our internet is so slow,and the page is not loading properly

    • Arvind Sanjeev
      Reply

      For your application, take a look at the device: leapmotion. IMU’s can only give you attitude in 3D space: x, y and z angles.

  • bharath
    Reply

    If i am moving my palm having imu sensor vertically,Then can i have the height of the hand raised from initial position…If u can calculate it how presice is it..plz do reply

    • Arvind Sanjeev
      Reply

      Bharath, the IMU can only give you roll, pitch and yaw angles (x,y,z) in 3D space. It cannot give you the linear displacement from one point to another. However, you can maybe take advantage of the accelerometer to find out the acceleration from one point to another, and do some calculations to find the distance travelled. But, it would be really difficult and complex.

  • tabish
    Reply

    may i have ur personal mail so that i can give u snapshoot of error coz i cant upload pic here

  • tabish
    Reply

    yes i have done step1 and 2 correctly but still have an error at this line of code
    “MPU6050 mpu;”
    and the error is
    “mpu6050 does not name a type”

    • Arvind Sanjeev
      Reply

      Which version arduino are you using? Do you get any other errors in the list?

  • tabish
    Reply

    hello when i verify the code in arduino software i have came across with this error plz help
    ” mpu6050 does not name a type “

    • Arvind Sanjeev
      Reply

      I think you haven’t installed the MPU6050 arduino library correctly. Did you perform the steps for installing the library like on the tutorial?

  • Abhinav
    Reply

    Hi Arvind, nice tutorial. Am desperately looking for sketch to detect a tap or a sudden jerk with MPU6050. Can you help

    • Arvind Sanjeev
      Reply

      Hi Abhinav,
      Thanks :)
      You can probably monitor the values from the IMU and check for sudden spikes on yaw, pitch and roll angles. And even maybe use simple if-else statements to try it out.

  • LateUmpire
    Reply

    Sir, I have the sketch loaded with no problems, but I have an RGB set up to light different colors based on angle. It all works well except that nothing happens until I open the serial monitor and send a character. After that, my LED lights and changes colors as required. How do I get the data sent without having to open the serial monitor please? Thank you

    • Arvind Sanjeev
      Reply

      Hi, you just need to edit the first few lines of the code. Read through the code inside the loop() and remove all the code that requires you to have a character sent to it serially. After doing this, you will be able to use it for your application :)

  • Mathijs
    Reply

    Hey,
    My module is connected but the monitor sais it failed trying to test device connections:

    Initializing I2C devices…
    Testing device connections…
    MPU6050 connection failed

    Send any character to begin DMP programming and demo:

    ——
    And when I send a character:
    —–

    Initializing I2C devices…
    Testing device connections…
    MPU6050 connection failed

    Send any character to begin DMP programming and demo:
    Initializing DMP…
    DMP Initialization failed (code 1)

    ——-

    What could be the problem?

    • Arvind Sanjeev
      Reply

      Hello, this is usually caused due to improper connections. Try double checking it and uploading the code again.

      • mathijs
        Reply

        Hey again, I figured it out. I’m using an Arduino Mega so I had to use other pins for the analog ones. Thanks!

        • Arvind Sanjeev
          Reply

          Yeah, exactly. Mega uses different pins for SDA and SCL. Glad you figured it out :)

        • ricj1812
          Reply

          Would be nice when you figured out something, post the result to share with the others.

          For Mega, pin 20 — SDA and pin 2–SCL

          • Arvind Sanjeev
            Reply

            Check out some of the new comments, they have got the solution for compiling errors.

          • Peeyush
            Reply

            Thanks a lot for the pin number for Mega…. I was so confused about the error I could not sleep !

      • Sambhav
        Reply

        Hello Arvind,

        I am having the exact same issue. I have double and triple checked my connections. I can upload an image of the connections if you’d like.

        Kindly help me out with this issue.

        Thanks a ton

        Sambhav

        • Arvind Sanjeev
          Reply

          What is the issue again? Did you check out the previous comments, other makers have come up with solutions.

  • bhavik
    Reply

    hi,
    just like harsh momaya pointed, i have the same problem with my IMU sensor where it shows FIFO OVERFLOW in between the values. i looked into the link u had posted but still the problem exists.
    Also in your video u get the values stable after 10 secs. it doesnt happen in my case.
    1)how to get rid of FIFO overflow problem?
    2)how to get stable values?

  • Chris
    Reply

    Great tutorial. Was able to get my MPU6050 hooked up without problem. Thank you so much for pointing out it takes a while to stabilize. Would have thought it was broken otherwise.

    Great job!

  • Chris
    Reply

    Using processing-2.2.1 I did not see a sketchbook folder. Instead:

    Go to %USERPROFILE%DocumentsProcessinglibraries
    Create a folder called toxiclibs-complete-0020
    Copy the contents of toxiclibs-complete-0020.zip into the newly created folder.

    If the %USERPROFILE%DocumentsProcessinglibraries location does not exist, try creating a new sketch in Processing then using File->Save as. This should open a dialog at the location containing the libraries folder.

    • Arvind Sanjeev
      Reply

      Cool, thanks for the tip :)

      • AmieraSyafika
        Reply

        hi, i also having the same problem in processing. i cannot find the sketchbook folder. i already create my own libraries folder, but it still give me error. i’m using windows-32 bits. can you help me?

  • Harsh Momaya
    Reply

    Hi Arvind,

    Thanks for providing a step-by-step procedure for interfacing Mpu 6050 sensor with Arduino. I have followed all the instructions as stated above but the teapot isn’t stabilizing. It rolls continuously and after some time it stops. When I implemented the MPU6050_DMP6 (1st part) code along with ypr values, ” FIFO overflow!” message was also getting displayed on serial monitor. I think there is some problem with fifoCount or with mpuIntStatus.

    Thanks!

  • Samvrit
    Reply

    The yaw value drifts continuously even after a minute of initialization of DMP.. roll and Pitch values are quite stable. How to overcome this?

    • Arvind Sanjeev
      Reply

      How continuously? Can you share a screenshot from the serial monitor? Also, try checking the euler angles, is it showing the same behavior?

      • Samvrit
        Reply

        I have not waited till it stabilizes, because it goes on for minutes. Very rarely, it stabilizes, but when I restart the arduino, it again drifts continuously. I’m using the teapot code in processing as output, and not Euler angles (it’s not any different with Euler angles either)

        • Arvind Sanjeev
          Reply

          I would probably say that its a faulty MPU6050, because otherwise the values would stabilize like in the video. Try with a different sensor.

          • varun
            Reply

            its probably because you arent using a filter of any sort. Try using it with Kalman or complementary filters.. the gyroscope readings tend to drift with time..

  • Rajashekhar
    Reply

    Can you mail me a video to show how it happens ?
    “After installing the processing IDE, next you will need to download a library called “Toxi”. This library is necessary for our Arduino MPU 6050 processing example. Download the latest zip file for the library from here. Next, you need to extract this file and paste the folder named “toxiclibs-complete-0020″ in the libraries directory of processing. You can find the “libraries” folder inside the Sketchbook folder of processing. If you don’t, then you will have to create a new folder called “libraries” there, and paste the toxiclibs inside it. Please check out the video at the end, if you have any doubts in the following steps.”

    • Arvind Sanjeev
      Reply

      Hello Rajashekhar, please install the processing software first.
      Then, go to the installed folder or search for the “sketchbook” folder of processing using your windows search dialog box.
      Next, check if you have a folder called “libraries” inside that, if you do, paste the “toxiclibs-complete-0020” folder inside it.
      If not, create a new folder and rename it as “libraries” and paste the “toxiclibs-complete-0020” folder inside it.

      • Frank
        Reply

        hi, is there a reason why i don’t see that folder named “toxiclibs-complete-0020″ in the link you guys provided here where it says HERE? i when there to github and that folder does not contain a folder named “toxiclibs-complete-0020″ please advise thank you!

          • Frank
            Reply

            Thanks Arvind i will download and pickup where i left off, i do have a question about this imu like for example Addressing “address” how would i go about setting a address if im using like say 10 imu’s ? is there some kind of breakout board i can use like a i2c breakout or can i just common all same wires together? and place in their respective pins? im just not sure how to go about knowing who is giving me current values as most number will look the same,

            also

            how do i go about calibrating the unit it self? turning a on/off axis?

            thanks for the help so far!

  • B Nawaz
    Reply

    Hello.
    Attempting to use the MPU-6050 for the first time. So I heard from someone and also read somewhere that there is some sort of “calibration” needed for an IMU before the first time use.

    Is it needed here? How is it done?

    • Arvind Sanjeev
      Reply

      Hey, if you saw the video in this tutorial, you can see that you just need to wait a few seconds before you start getting accurate values from the sensor. There is no manual calibration required, it is really easy to work with.

      • Ibrahim
        Reply

        Hi Arvind
        I am also getting the same problem as below
        //———————error—————————
        No library found for toxi.geom
        No library found for toxi.processing
        Libraries must be installed in a folder named ‘libraries’ inside the ‘sketchbook’ folder.
        //——————————————————————————————-
        I unzip and pasted the folder “toxiclibs-complete-0020″ in processing Library folder but still getting this error
        please let me know on this

        regards
        Ibrahim

        • hafiz
          Reply

          me too. can anyone help?

pingbacks / trackbacks

Leave a Comment

61 + = 66

Start typing and press Enter to search