MPU6050-Accelerometer+Gyroscope Sensor Basics

Introduction: MPU6050-Accelerometer+Gyroscope Sensor Basics

The MPU6050 is a very useful sensor .

The mpu 6050 is an IMU:An inertial measurement unit (IMU)
is an electronic device that measures and reports a body's specific force, angular rate, and sometimes the orientation of the body, using a combination of accelerometers, gyroscopes.

It is a 6 axis device

3 of the axis can measure acceleration and the other 3 are for angular acceleration measurements.

Using the acceleration and angular acceleration it is possible to get a fairly accurate estimate of the angle

In this tutorial we will be exploring how we can use the MPU6050 with a library to make things a lot easier.


  1. Arduino board
  2. MPU6050
  3. Jumper wires
  4. Breadboard

Step 1: Complete the Circuit

The sensor uses a protocol known as I2c to communicate with the Arduino to send it the values.

The A4 pin is used for SCL- serial clock and should be connected to SCL of the sensor and

,A5 to SDA-Serial data line.

The Vcc is connected to 5v and the Gnd is connected to ground

Step 2: Coding

#include <MPU6050_tocn.h>
#include <Wire.h>

Before I begin, this library is not written by me, I just think it is the simplest one there and love using it.

These are the header files ^^, wire.h is used to establish an i2c communication

MPU6050 mpu6050(Wire);

here we name our gyroscope, or create an object for those who are familar with OOPs.

void setup() {

Initially we calculate offsets since all the angle readings are going to be with respect to the initial orientation.

void loop() {
  Serial.print("angleX : ");
  Serial.print("\tangleY : ");
  Serial.print("\tangleZ : ");

Each gives us the measure of the angle.

Step 3: Other Functions

The library contains other functions


mpu6050.getTemp()//gives the temperature(not very accurate)
mpu6050.getAccX()//Linear acceleration in X direction

(similar functions are mpu6050.getAccY(), mpu6050.getAccZ())

mpu6050.getGyroX()//Angular acceleration about the x axis

(similar functions are mpu6050.getGyroY(), mpu6050.getGyroZ())

Be the First to Share


    • Battery Powered Contest

      Battery Powered Contest
    • Plywood Challenge

      Plywood Challenge
    • Plastic Contest

      Plastic Contest