Introduction: GY-521 MPU6050 3 Axis Gyroscope and Accelerometer With Arduino

This video tutorial goes over the installation and setup of a GY-521 board with a MPU6050 3 Axis Gyroscope and Accelerometer with an Arduino. After some initial troubleshooting with I was able to get the component working. At first I had trouble with loose breadboard connections so I decided to solder in the pins that came with the component. That solved my problem and I was off and running. I used some 3D modeling software to illustrate the operation of the component.

Everything you need to duplicate this project can be found here:

http://diyhacking.com/arduino-mpu-6050-imu-sensor-...

Step 1: Solder Pins to the Component

Picture of Solder Pins to the Component

The component came with two sets of pins which I highly recommend soldering to the component.

I tried testing with a breadboard at first but only ran into frustration as the connections were loose. I was able to get a red led on the board so my voltage and ground were connected. However, when I ran my MPU6050 software on the Arduino, my serial monitor would show the error message: "MPU6050 connection failed". Soldering the pins to the board solved the connection issue. So if you are having this error message and are using a breadboard, solder could solve the problem.

Step 2: Connect to Arduino

Now that you have your pins soldered to the component you can wire it up to the Arduino Uno.

VCC -> 5v

GND -> GND

SCL -> A5

SDA -> A4

INT -> D2 (used for interrupt)

(the other pins do not need to be connected)

Step 3: Use I2C Scanner and MPU6050 Arduino Software

Picture of Use I2C Scanner and MPU6050 Arduino Software

Using I2C Scanner, verify that the Arduino finds the device.

If the device is found then try using the MPU6050 example software to see if you get raw data.

The MPU6050 libraries can be downloaded here: http://diyhacking.com/projects/MPU6050.zip

The I2C libraries can be downloaded here: http://diyhacking.com/projects/I2Cdev.zip

Note: if the output is random characters, make sure your serial connection is set to 9600 baud in the arduino setup.

Step 4: Run the MPU Teapot Example With Processor IDE

Picture of Run the MPU Teapot Example With Processor IDE

Download and install the Processor IDE.

You can download the Processor IDE here: https://processing.org/download/?processing

Then open the MPU Teapot example and change some code.

Comment out: #define OUTPUT_READABLE_YAWPITCHROLL

And uncomment the line: //#define OUTPUT_TEAPOT

will look like this:

//#define OUTPUT_READABLE_YAWPITCHROLL

and

#define OUTPUT_TEAPOT.

You will also need to change some lines of code for the Arduino MPU6050 Teapot example:

String portName = “/dev/ttyUSB1”;.
Change "ttyUSB1" to the port where your Arduino is connected. eg. "COM3";

I had some trouble finding the Toxiclabs library needed for this demo but I eventually found it here: https://bitbucket.org/postspectacular/toxiclibs/do...

You will need to modify some lines of code as detailed here:

http://diyhacking.com/arduino-mpu-6050-imu-sensor-...

Have Fun!

Comments

CHATO25 (author)2016-11-29

hi i need the code of the MPU6050 for arduino Due.

JNathan15 (author)2016-06-12

i need help and ive seen your gyro led project, and its awesome and easy. can you instead of gyro, use the accelerometer values? example if accelx value is 2000-2500 led 1 lights up, value 2500-3000 led 1&2 lights up and so on. could you help? thanks alot!

PS: i only need 1 accelerometer value, either x/y value.

anuj1993 (author)2016-04-13

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?

About This Instructable

22,172views

23favorites

License:

Bio: Will write code for food. :) If you need help with any of your embedded Arduino applications please send me a message.
More by dmainmon:ArduCAM Mini ESP8266 Web CameraESP8266-12E DHT ThermostatESP8266 OLED Clock IoT Using AJAX
Add instructable to: