Mission Critical
Published © CC BY-NC

MPU 6050 Tutorial | How to Program MPU 6050 With Arduino

Hello all, welcome to another Arduino Sensor Tutorial, in this Blog, we will learn how to wire and code MPU 6050, lets start!

BeginnerProtip0 minutes266
MPU 6050 Tutorial | How to Program MPU 6050 With Arduino

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
SparkFun Triple Axis Accelerometer and Gyro Breakout - MPU-6050
SparkFun Triple Axis Accelerometer and Gyro Breakout - MPU-6050
×1
UTSOURCE Electronic Parts
UTSOURCE Electronic Parts
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)
Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)

Story

Read more

Code

Code snippet #3

Plain text
// mpu.setGyroOffsetX(155);
// mpu.setGyroOffsetY(15);  
// mpu.setGyroOffsetZ(15);

( uncomment by removing "//" )

Code snippet #6

Plain text
void checkSettings()
{
  Serial.println();
  
  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(" * Gyroscope:         ");
  switch(mpu.getScale())
  {
    case MPU6050_SCALE_2000DPS:        Serial.println("2000 dps"); break;
    case MPU6050_SCALE_1000DPS:        Serial.println("1000 dps"); break;
    case MPU6050_SCALE_500DPS:         Serial.println("500 dps"); break;
    case MPU6050_SCALE_250DPS:         Serial.println("250 dps"); break;
  } 
  
  Serial.print(" * Gyroscope offsets: ");
  Serial.print(mpu.getGyroOffsetX());
  Serial.print(" / ");
  Serial.print(mpu.getGyroOffsetY());
  Serial.print(" / ");
  Serial.println(mpu.getGyroOffsetZ());
  
  Serial.println();
}

Code snippet #8

Plain text
  Serial.print(" Xraw = ");  
  Serial.print(rawGyro.XAxis);
  Serial.print(" Yraw = ");
  Serial.print(rawGyro.YAxis);
  Serial.print(" Zraw = ");
  Serial.println(rawGyro.ZAxis);
  Serial.print(" Xnorm = ");
  Serial.print(normGyro.XAxis);
  Serial.print(" Ynorm = ");
  Serial.print(normGyro.YAxis);
  Serial.print(" Znorm = ");
  Serial.println(normGyro.ZAxis);

Code snippet #10

Plain text
Initialize MPU6050
 * Sleep Mode:        Disabled
 * Clock Source:      PLL with X axis gyroscope reference
 * Gyroscope:         2000 dps
 * Gyroscope offsets: 0 / 0 / 0

 Xraw = -65.00 Yraw = 25.00 Zraw = -29.00
 Xnorm = 0.00 Ynorm = 0.00 Znorm = 0.00
 Xraw = -62.00 Yraw = 20.00 Zraw = -32.00
 Xnorm = 0.00 Ynorm = 0.00 Znorm = 0.00
 Xraw = -64.00 Yraw = 25.00 Zraw = -30.00
 Xnorm = 0.00 Ynorm = 0.00 Znorm = 0.00
 Xraw = -66.00 Yraw = 23.00 Zraw = -29.00
 Xnorm = 0.00 Ynorm = 0.00 Znorm = 0.00
 Xraw = -67.00 Yraw = 20.00 Zraw = -33.00
 Xnorm = 0.00 Ynorm = 0.00 Znorm = 0.00
 Xraw = -64.00 Yraw = 22.00 Zraw = -31.00
 Xnorm = 0.00 Ynorm = 0.00 Znorm = 0.00

Github

https://github.com/jarzebski/Arduino-MPU6050

Credits

Mission Critical

Mission Critical

25 projects • 13 followers
Hello Geeks, Mission Critical is an Electronics Based Channel on YouTube

Comments