Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Voltaat Arduino Ultimate Kit
80 min
Share

Measure titling using MPU-6050

The MPU6050 is a sensor that can provide us with very useful data about acceleration, velocity, and rotation along all three axes. That’s why it has a wide range of applications in drones, robots, smart phones, video game controllers, and many other devices.

Project Video

Overview

In this tutorial we will learn about a very interesting sensor called the MPU6050, which is very important in planes since it helps the autopilot control your flight in a safe manner.

Getting the Items

Arduino Uno R3 (Voltaat Version)
Get Item
3 Axis Gyroscope & Accelerometer Module (MPU-6050)
Get Item
Jumper Wires – Male to Female (40 Pack)
Get Item

Steps

Wiring it Up

Connect the wires between the MPU6050 sensor and the Arduino, as shown in the image below.

 Connections from the Arduino to the MPU6050:


      • Arduino 5V pin → MPU6050 VCC pin (+ pin)


      • Arduino GND pin → MPU6050 GND pin (- pin)


      • Arduino pin 5 → MPU6050 SCL pin


       • Arduino pin 4 → MPU6050 SDA pin

Coding



/*
 Voltaat learn (http://learn.voltaat.com/)
 Link for full tutorial:
 Wire library:
 MPU6050 library:

 Tutorial: Measure titling using MPU6050

 The purpose of this sketch is to get readings from the MPU6050 sensor
 and print this data directly on your computer.

 Connections from the Arduino to the MPU6050:
 • Arduino 5V pin → MPU6050 VCC pin (+ pin)
 • Arduino GND pin → MPU6050 GND pin (- pin)
 • Arduino pin 5 → MPU6050 SCL pin
 • Arduino pin 4 → MPU6050 SDA pin

*/

//Include MPU6050 Library
#include "MPU6050_tockn.h"
//This library allows you to connect with I2C/TWI devices
#include "Wire.h"

MPU6050 mpu6050(Wire);

//Define variable
long timer = 0;

//Commands inside void setup run once
void setup() {
 //Start the serial monitor at 19200 baud rate (19200 bits per second)
 Serial.begin(9600);
 //This function initializes the Wire library and join the I2C bus as a controller or a peripheral
 Wire.begin();
 //This function initializes the MPU6050 library
 mpu6050.begin();
 //See state of calculating calibration in serial monitor
 mpu6050.calcGyroOffsets(true);
}

//Commands inside void loop run forever
void loop() {
 //Get all data of MPU6050
 mpu6050.update();

 if (millis() - timer > 1000) {
   //Print data to serial monitor
   Serial.println("=======================================================");
   Serial.print("temp : "); Serial.println(mpu6050.getTemp());
   Serial.print("accX : "); Serial.print(mpu6050.getAccX());
   Serial.print("\taccY : "); Serial.print(mpu6050.getAccY());
   Serial.print("\taccZ : "); Serial.println(mpu6050.getAccZ());

   Serial.print("gyroX : "); Serial.print(mpu6050.getGyroX());
   Serial.print("\tgyroY : "); Serial.print(mpu6050.getGyroY());
   Serial.print("\tgyroZ : "); Serial.println(mpu6050.getGyroZ());

   Serial.print("accAngleX : "); Serial.print(mpu6050.getAccAngleX());
   Serial.print("\taccAngleY : "); Serial.println(mpu6050.getAccAngleY());

   Serial.print("gyroAngleX : "); Serial.print(mpu6050.getGyroAngleX());
   Serial.print("\tgyroAngleY : "); Serial.print(mpu6050.getGyroAngleY());
   Serial.print("\tgyroAngleZ : "); Serial.println(mpu6050.getGyroAngleZ());

   Serial.print("angleX : "); Serial.print(mpu6050.getAngleX());
   Serial.print("\tangleY : "); Serial.print(mpu6050.getAngleY());
   Serial.print("\tangleZ : "); Serial.println(mpu6050.getAngleZ());
   Serial.println("=======================================================\n");
   timer = millis();

 }

}

Testing it Out

know when your plant needs watering

Now access the serial monitor on your Arduino IDE by clicking on the magnifying glass icon at the top right corner.

know when your plant needs watering

Now as we see in the following image the serial monitor displays the reading values from the MPU6050 sensor.

know when your plant needs watering

Resources

No items found.