Arduino B.Tech/Diploma Beginner

Interfacing MPU6050 Accelerometer & Gyroscope with Arduino

Interfacing MPU6050 3-axis Accelerometer & Gyroscope with Arduino Code to measure acceleration, rotation, temperature and pitch, roll, yaw

  • Suitable forB.Tech/Diploma Arduino students
  • Build time1-2 weeks
  • LevelBeginner
  • Available atAjvika Labs, Kakinada

About this project

Overview
In this tutorial, we will learn interfacing of
MPU6050 Accelerometer & Gyroscope Sensor
with
Arduino
R4 Minima Board. The MPU6050 is a versatile and widely-used sensor that combines a
3-axis gyroscope
and a
3-axis accelerometer
, making it ideal for numerous motion-sensing applications.
The MPU6050 can be used with Arduino to
calculate acceleration
is all the
X, Y
and
Z
axis. It can also be used to measure the
angular velocity
. When the accelerometer data, gyroscope data and magnetometer data are combined together, the
pitch, roll, yaw
value can be calculated. The guide covers the measurement of acceleration, angular velocity, temperature as well as pitch, roll, yaw calculation by
interfacing MPU6050
with
Arduino
. You may take a look at the
BMI160
which is an advanced Gyroscope Accelerometer module from Bosch.
Bill of Materials
For this tutorial I am using the
SunFounder Arduino Starter Kit
which has 90+ components.
Here are the list of components I am using from this Kit.
S.N.
Components
Quantity
Purchase Links

Arduino UNO R4/R3 Board

Amazon
AliExpress

MPU6050 Gyroscope Accelerometer

Amazon
AliExpress
SunFounder

Connecting Wires

Amazon
AliExpress
SunFounder

Type C USB Cable

Amazon
AliExpress

Breadboard

Amazon
AliExpress
SunFounder
MPU6050 Accelerometer & Gyroscope Module
The
MPU-6050
, a motion tracking device, integrates a
3-axis gyroscope
with a
3-axis accelerometer
, making it a 6-axis sensor.
This device is capable of detecting variations in movement, acceleration, and rotational dynamics. It’s frequently utilized in areas like robotics, game controllers, and various other electronics that necessitate motion sensing. Due to its precise performance and affordability, it is highly favored in the DIY enthusiast circle. You may refer to
MPU6050 Datasheet
from
Invensense
for detailed information.
Working Principle
The MPU-6050 sensor module is equipped with a 3-axis accelerometer and a 3-axis gyroscope.
To understand its coordinate systems, place the MPU6050 flat on a table with the labeled side facing up and a dot on the upper left corner of this surface.
In this position, the vertical direction pointing upwards defines the chip’s Z-axis. The horizontal direction stretching from left to right is identified as the X-axis. Correspondingly, the direction extending from the back of the chip towards the front is designated as the Y-axis.
3-axis Accelerometer
The
accelerometer
in the
MPU6050
operates based on the
piezoelectric effect
, where certain materials produce an
electric charge
when subjected to
mechanical stress
Visualize a cuboidal box containing a small ball, similar to the illustration. The walls of this box are constructed from
piezoelectric crystals
. When the box is tilted,
gravity
causes the ball to move towards the
tilt direction
. Upon colliding with a wall, the ball generates minute
piezoelectric currents
. In this cuboid, there are three pairs of opposite walls, each pair representing an axis in
3D space
: the
Y
, and
Z
axes. The currents from the piezoelectric walls indicate the tilt direction and its intensity.
Using the MPU6050, acceleration along each coordinate axis can be detected. In a stationary position on a desk, the
Z-axis acceleration
measures
1 gravity unit
, while the
and
Y
axes register

. If the sensor is tilted or experiences weightlessness or overload, the readings alter accordingly.
The MPU6050 offers four selectable measurement ranges:
±2g, ±4g, ±8g
, and
±16g
(
default is ±2g
), each providing a specific
precision level
. The values span from
-32768
to
32767
The accelerometer’s output is converted into an
acceleration value
by mapping the raw data from the reading range to the measurement range, using the formula:
Acceleration=(
Accelerometer axis raw data / 65536 * full scale Acceleration range) g
For example, consider the
X-axis
with a raw data reading of
16384
and a
±2g
range:
Acceleration along the X axis= (
16384 / 65536 * 4) g =1g
3-axis Gyroscope
Gyroscopes
in devices like the
MPU6050
operate based on the principle of
Coriolis acceleration
. Picture a fork-like structure in a continuous back-and-forth motion, anchored using
piezoelectric crystals
. When this setup is tilted, the crystals experience a force in the
tilt direction
, a result of the
inertia
from the moving fork. This force leads the crystals to generate an
electric current
through the
piezoelectric effect
, which is then amplified.
The
gyroscope
, similar to the
accelerometer
, offers four measurement ranges:
±250, ±500, ±1000
, and
±2000
degrees per second. The method of calculation and the
principle of operation
are largely analogous to those of the accelerometer.
The
formula
to convert the
gyroscope’s raw data
into
angular velocity
is:
Angular velocity =
(Gyroscope axis raw data / 65536 * full scale Gyroscope range) °/s
For instance, if the
gyroscope’s raw data
along the X axis is
16384
and the range is
±250°/s
, the calculation for
angular velocity
along the X axis would be:
Angular velocity along the X axis =
(16384 / 65536 * 500)°/s =125°/s
Features of MPU6050
3.3/5V Working voltage
I2C Interface (up to 400Kb/s)
Acceleration measurement range: ±2/±4/±8/±16g
Gyroscope measurement range: ±250/±500/±1000/±2000°/s
ADC resolution: 16bit
Resolution: ACC:16384LSB/g(Max), Gyro:131LSB/(°/s)(Max)
Output Speed: ACC: 1KHz(Max), Gyro: 8KHz(Max)
Output rate of attitude solution:200Hz
Working temperature: -40℃~85℃
Size: 16x18mm
MPU6050 Pinout
The MPU-6050 module has 8 pins:
INT:
Interrupt digital output pin.
AD0:
I2C Slave Address LSB pin. This is the 0th bit in 7-bit slave address of device. If connected to VCC then it is read as logic one and slave address changes.
XCL:
Auxiliary Serial Clock pin. This pin is used to connect other I2C interface enabled sensors SCL pin to MPU-6050.
XDA:
Auxiliary Serial Data pin. This pin is used to connect other I2C interface enabled sensors SDA pin to MPU-6050.
SCL:
Serial Clock pin. Connect this pin to microcontrollers SCL pin.
SDA:
Serial Data pin. Connect this pin to microcontrollers SDA pin.
GND:
Ground pin. Connect this pin to ground connection.
VCC:
Power supply pin. Connect this pin to +5V DC supply.
Interfacing MPU6050 Accelerometer & Gyroscope with Arduino
Now let us
interface MPU6050
Accelerometer & Gyroscope Module with
Arduino
R4 Board. Here is the
connection
diagram.
The connection is very simple as shown above:
VCC
: Connect to the 3.3V on the Arduino.
GND
: Connect to the Ground (GND) on the Arduino.
SCL
: Connect to the A5 pin of your Arduino.
SDA
: Connect to the A4 pin of your Arduino.
You can use a breadboard for assembly and jumper wires for connection.
Reading Accelerometer, Gyroscope & Temperature Data from MPU6050
After the
hardware setup
is complete, we can move to the
coding
part of this project. In this example, we will be particularly emphasizing
accelerometer
gyroscope
, and
temperature
data reading.
The Accelerometer data can be read and converted to common units like
meters per second squared
(m/s^2). Gyroscope data is typically in
degrees per second
. The temperature sensor data can be used for
calibrating
other sensor readings.
The code requires
Adafruit MPU6050 Library
for compilation. Therefore add the library to the Arduino library folder. Here is the complete code for reading the accelerometer, gyroscope and temperature data by interfacing MPU6050 with Arduino R4 Board.

// Include the necessary libraries
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
// Create an object for the MPU6050 sensor
Adafruit_MPU6050
mpu
;
void
setup
(
)
{
// Initialize the serial communication
Serial
begin
(
9600
)
;
// Check if the MPU6050 sensor is

Technologies used

ArduinoBLEMPU6050AngularI2CADC

Hardware components

  • Arduino
  • MPU6050

Software & tools

  • Arduino IDE

What you get

  • Working project / hardware kit, tested before delivery
  • Complete source code with explanation
  • Project demo and guidance for your viva
  • Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed. Payment is in two parts: • 50% advance to start the project • Remaining 50% before delivery Note: • Documentation and PPT are not included by default • If you need documentation/PPT, it can be arranged for extra time and cost We'll confirm the exact timeline and cost with you after reviewing your requirements.