This post talks about using the GY-521 MPU6050 3 Axis Accelerometer Gyroscope with an Arduino.
GY-521 MPU6050 3 Axis Accelerometer Gyroscope
The GY-521 MPU6050 3 Axis Accelerometer Gyroscope is a relatively complex module.
The gyroscope allows you to tell both the angle it is positioned in all three axis directions and the movement in each of those directions. In addition this is able to report the temperature of the die so it can be used to monitor the rough temperature.
Opposite to the pins there are two mounting holes which allow you to attach it to something to be held in place.
Wiring it up to an Arduino
This sensor have 8 pins but you will typically only need to use 4 of them to connect to your Arduino.
Pin on Sensor
Pin on Arduino
A5 or SCL
For most Arduino’s the SCL pin will be A5. However you may need to confirm this.
A4 or SDA
For most Arduino’s the SDA pin will be A4. However you may need to confirm this.
Auxiliary Serial Data (Which can be used to connect another device to the MPU6050)
Auxiliary Serial Clock (Which can be used to connect another device to the MPU6050)
Not connected / GND / HIGH
This pin allows modifying of the I2C address which will allow you to use up to two of these on the same I2C bus. If it is wired to “Logic Low” then the address of the device will be 1101000 If it is wired to “Logic High” then the address of the device will be 1101001
This pin does not need to be connected.
To use it with an Arduino I am wiring up VCC, GND, SCL and SDA.
Programming the Arduino with the GY-521 MPU6050 3 Axis Accelerometer Gyroscope
To talk to the GY-521 MPU6050 3 Axis Accelerometer Gyroscope I am going to use the MPU6050 Light Arduino Library. This will mean that I do not need to write the specific I2C pulses to talk to the sensor.
You can add this to the Arduino IDE by importing the “MPU6050_light” by rfetick which can be done using “manage library” section or by downloading it from Github.
This exposes some useful functions such as getTemp() and getAngleX/Y/Z() which allows you to easily access the data. Below is some example code to use the gyroscope.
First I import the two libraries needed (Wire and MPU6050_light) so that they can be accessed and used. Once done I then set up an instance of the MPU6050 object with the Wire object.
In the setup function the serial connection is set up so we can output the data. Then the wire and MPU6050 is initialised and the gyroscope offsets are calculated. This sets up the MPU6050 object so that it is ready to receive data from the chip.
In the loop function we call the update function which polls the device for data and then call a variety of data functions to get the angles, gyroscope angle data, and accelerometer data. The functions available from this library are as follows.
Acceleration on X, Y or Z
Angular speed en X, Y or Z
Angles computed from accelero data. Warning: noisy
This sensor combined with the MPU6050 light library is an easy to use gyroscope and accelerometer. You are able to easily get information about how fast the sensor is moving (acceleration) and also the angles at which it is being held which gives it a wide range of uses.
In addition reporting the temperature of the chip can be used to see roughly the temperature around the chip.
This is a relatively easy to use chip and for any project where I need to know the movement speed or direction I would consider using it.