Min menu

Pages

Project 28 : Getting Started With Arduino and MPU6050

 

Getting Started With Arduino and MPU6050

In this project, I’ll show you how the MPU6050 Sensor works and also how to interface Arduino with MPU6050. We will be interfacing an MPU-6050 breakout board with Arduino UNO and read the values from the Accelerometer and Gyroscope
Before going in to the project, you need to understand a few basics of the MPU6050 Sensor. MPU-6050 is an IMU Sensor that contains a MEMS (Microelectromechanical System) Accelerometer and MEMS Gyroscope on a single chip.
Here, IMU Sensor, where IMU stands for Inertial Measurement Unit, is a device that measures the specific force using Accelerometer, angular rate using Gyroscope and magnetic field using Magnetometers.

Components Required

Hardware

  • Arduino UNO 
  • MPU6050 Breakout Board 
  • Connecting Wires 

Software

  • Arduino IDE 
  • Processing (for 3D Visualization)

Circuit Diagram

The following image shows the circuit diagram for interfacing MPU6050 with Arduino UNO. As mentioned earlier, the interface between MPU6050 and Arduino must be implemented using I2C Protocol.
Hence, the SCL Pin of the Arduino (A5) is connected to the SCL Pin of the MPU6050. Similarly, the SDA Pin of the Arduino (A4) is connected to the SDA Pin of the MPU6050 board.
Additionally, we will be using the Interrupt feature of the MPU6050 to indicate (or interrupt) Arduino when the 1024 Byte FIFO buffer is full. So, connect the INT pin of the MPU6050 to the external interrupt 0 (INT0) pin of Arduino UNO i.e. Pin 2.

#include<Wire.h>
const int MPU6050_addr=0x68;
int16_t AccX,AccY,AccZ,Temp,GyroX,GyroY,GyroZ;
void setup(){
Wire.begin();
Wire.beginTransmission(MPU6050_addr);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
Serial.begin(9600);
}
void loop(){
Wire.beginTransmission(MPU6050_addr);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU6050_addr,14,true);
AccX=Wire.read()<<8|Wire.read();
AccY=Wire.read()<<8|Wire.read();
AccZ=Wire.read()<<8|Wire.read();
Temp=Wire.read()<<8|Wire.read();
GyroX=Wire.read()<<8|Wire.read();
GyroY=Wire.read()<<8|Wire.read();
GyroZ=Wire.read()<<8|Wire.read();
Serial.print("AccX = "); Serial.print(AccX);
Serial.print(" || AccY = "); Serial.print(AccY);
Serial.print(" || AccZ = "); Serial.print(AccZ);
Serial.print(" || Temp = "); Serial.print(Temp/340.00+36.53);
Serial.print(" || GyroX = "); Serial.print(GyroX);
Serial.print(" || GyroY = "); Serial.print(GyroY);
Serial.print(" || GyroZ = "); Serial.println(GyroZ);
delay(100);
}
reaction: