How to Interface MPU6050 with the Arduino?

Содержание

In this tutorial we will learn about Interfacing with MPU 6050 sensor on Arduino Boards. It measures the angle and speed values of accelerometer and gyroscope. We have already discussed the basic knowledge of MPU 6050- Introduction to MPU6050 Motion Sensor

How to Interface MPU6050 with the Arduino?

What is MPU6050?

MPU 6050 is an MEMS-based 6-axis motion tracking device. Which consists of a three-axis accelerometer and a three-axis gyroscope. It has on-chip gyroscope and accelerometer sensors with temperature sensors.

MPU 6050 is a digital device. The module is very low in size, has low power consumption requirements, is highly accurate, has high repetition, high shock tolerance, has application-specific performance programmability and low consumer price points.

MPU6050 can be easily interfaced with other sensors such as magnetometers and microcontrollers MPU6050 is basically a sensor for motion processing devices. It is the world’s first six-dimension motion tracking device. It was designed for low-cost and high-performance smartphones, tablets and wearable sensors. It is capable of processing nine-axis algorithms, it simultaneously captures motion in x, y and z axis.

Features:

3- axis gyroscope

3- axis accelerometer

16-bit ADC conversion for each channel

1024-bit FIFO buffer

Digital output temperature sensor

Integrated Digital Motion Processor

Inbuilt temperature sensor

MPU6050 Module Pinout:

How to Interface MPU6050 with the Arduino?

VCC: is the power supply for the module. Connect it to the 5V output of the Arduino.

GND: should be connected to the ground of Arduino.

SCL: is a I2C Clock pin. This is a timing signal supplied by the Bus Master device. Connect to the SCL pin on the Arduino.

SDA: is a I2C Data pin. This line is used for both transmit and receive. Connect to the SDA pin on the Arduino.

XDA: is the external I2C data line. The external I2C bus is for connecting external sensors.

XCL: is the external I2C clock line.

AD0 : it allows you to change the internal I2C address of the MPU6050 module. It can be used if the module is conflicting with another I2C device, or if you wish to use two MPU6050s on the same I2C bus. When you leave the ADO pin unconnected, the default I2C address is 0x68HEX and when you connect it to 3.3V, the I2C address becomes 0x69HEX.

INT: is the Interrupt Output. MPU6050 can be programmed to raise interrupt on gesture detection, panning, zooming, scrolling, tap detection, and shake detection.

Components Required:

Connections:

Arduino MPU6050
5v/3v VCC
GND GND
A5/ SCL pin SCL
A4/SDA pin SDA
pin 2 INT

Library Installation:

To install the library navigate to the Sketch Include Library Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries.

How to Interface MPU6050 with the Arduino?

Filter your search by typing ‘mpu6050’. There should be a couple entries. Look for Adafruit MPU6050 Library by Adafruit. Click on that entry, and then select Install.

How to Interface MPU6050 with the Arduino?

Program upload:

How to Interface MPU6050 with the Arduino?

#include Wire.h #include MPU6050.h MPU6050 mpu; void setup() < Serial.begin(115200); Serial.println("Initialize MPU6050"); while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G)) < Serial.println("Could not find a valid MPU6050 sensor, check wiring!"); delay(500); >// If you want, you can set accelerometer offsets // mpu.setAccelOffsetX(); // mpu.setAccelOffsetY(); // mpu.setAccelOffsetZ(); checkSettings(); > void checkSettings() < Serial.println("microdigisoft tutorials"); Serial.print(" * Sleep Mode: "); Serial.println(mpu.getSleepEnabled() ? "Enabled" : "Disabled"); Serial.print(" * Clock Source: "); switch(mpu.getClockSource()) < case MPU6050_CLOCK_KEEP_RESET: Serial.println("Stops the clock and keeps the timing generator in reset"); break; case MPU6050_CLOCK_EXTERNAL_19MHZ: Serial.println("PLL with external 19.2MHz reference"); break; case MPU6050_CLOCK_EXTERNAL_32KHZ: Serial.println("PLL with external 32.768kHz reference"); break; case MPU6050_CLOCK_PLL_ZGYRO: Serial.println("PLL with Z axis gyroscope reference"); break; case MPU6050_CLOCK_PLL_YGYRO: Serial.println("PLL with Y axis gyroscope reference"); break; case MPU6050_CLOCK_PLL_XGYRO: Serial.println("PLL with X axis gyroscope reference"); break; case MPU6050_CLOCK_INTERNAL_8MHZ: Serial.println("Internal 8MHz oscillator"); break; >Serial.print(" * Accelerometer: "); switch(mpu.getRange()) < case MPU6050_RANGE_16G: Serial.println("+/- 16 g"); break; case MPU6050_RANGE_8G: Serial.println("+/- 8 g"); break; case MPU6050_RANGE_4G: Serial.println("+/- 4 g"); break; case MPU6050_RANGE_2G: Serial.println("+/- 2 g"); break; >Serial.print(" * Accelerometer offsets: "); Serial.print(mpu.getAccelOffsetX()); Serial.print(" / "); Serial.print(mpu.getAccelOffsetY()); Serial.print(" / "); Serial.println(mpu.getAccelOffsetZ()); Serial.println(); > void loop() < Vector rawAccel = mpu.readRawAccel(); Vector normAccel = mpu.readNormalizeAccel(); Serial.print(" Xraw = "); Serial.print(rawAccel.XAxis); Serial.print(" Yraw = "); Serial.print(rawAccel.YAxis); Serial.print(" Zraw = "); Serial.println(rawAccel.ZAxis); Serial.print(" Xnorm = "); Serial.print(normAccel.XAxis); Serial.print(" Ynorm = "); Serial.print(normAccel.YAxis); Serial.print(" Znorm wp-block-image size-full is-resized is-style-default">


Источник: microdigisoft.com