Gyroscope and Accelorometer

In this project, you'll learn how to connect and control the GY-521 gyro and accelerometer module which uses the MPU-6050 digital motion processor to detect the spin, tilt, and acceleration of an object.

The MPU-6050 uses the I2C protocol to communicate with the Arduino. The 7-bit I2C device address for the MPU-6050 is 0x68.

The MPU6050_RobotsForFun library contains all of the functions for interfacing with the MPU-6050.

Parts needed: GY-521 gyro and accelerometer
1 Making the connections
  • Connect the SCL pin on the MPU to pin A5 on the Arduino.
  • Connect the SDA pin on the MPU to pin A4 on the Arduino.
  • Connect the INT pin on the MPU to pin 2 on the Arduino.
  • Connect Vcc to 5V.
  • Connect GND to GND.
2 Download the MPU6050_RobotsForFun library.
3 Install the MPU6050_RobotsForFun library by selecting Sketch from the Arduino IDE menu
  • then select Import Library or Include Library
  • then select Add Library or Add .ZIP Library
Locate and select the MPU6050_RobotsForFun.zip file that you just downloaded in step 2. It should be in the Download folder.

Click the Open button

(Refer to this document for more information on how to install a library if you run into problems.)
4 Create a new program by selecting File from the menu
  • then select Examples
  • then select MPU6050_RobotsForFun
  • then select MPU6050_Basic_Gyro
5 Open the Serial Monitor.
6 Upload and run the program.
7 You will see the gyro x, y, z axis values printed. Tilt the MPU along the three axis to see the values change.

Are you ready to build a self balancing robot? Click on the Experiment button to learn how to build one.