Connecting MPU6050 Gyroscope + Accelerometer to Arduino

Here is how to connect MPU6050 Gyroscope+Accelerometer to our Hackabot Uno Robot Kit.

Connections

This is how MPU6050 look like:

mpu6050-gyro-accelerometer-arduino

Note that it shows the X & Y axes on the circuit board. Z-axis is the one perpendicular to the board. There are straight and angled header pins included in the kit.

I selected the angled ones. After soldering, it is very convenient to insert the sensor to the breadboard. Z-axis is pointing to the forward direction. X-axis points upward.

So, if the robot moves forward (from idle), the sensor will detect acceleration in Z-direction.

mpu6050-mounted-on-robot-kit-small

MPU6050 uses I2C bus to communicate to Arduino. Here is the wiring:

Sensor   :    Arduino Uno

VCC        :   +5V

GND       :   GND

SCL         :   pin A5

SDA        :   pin A4

INT         :   pin 2

Leave the ‘XCL’, ‘XDA’, and ‘ADO’ pins on the sensor unconnected. ‘XCL’ and ‘XDA’ are the pins in the auxiliary I2C bus. It is possible to hook up other sensors like magnetometer to MPU6050. We may cover this in the future.  ‘INT’ pin is for interrupts.

Programming

In this tutorial, I am using the i2cdevlib library from Jeff Rowberg. You may download and import it to your Arduino IDE.

There are excellent examples coming with Jeff’s library. You may open them in Arduino IDE as follows: ‘File’ -> ‘Examples’ -> ‘MPU6050’ -> ‘Examples’ -> …

MPU6050_raw

In this example, the code simply prints the X/Y/Z acceleration and roll, pitch, yaw readings.