MPU6050 Sensor

Gyroscope and Accelerometer with MPU6050

Introduction

This experiment demonstrates how to use the MPU6050 sensor, which combines a gyroscope and accelerometer, to measure motion and orientation. It is commonly used in motion tracking and robotics applications.

MPU6050 Sensor

Components Needed

Circuit Setup

  1. Connect the VCC pin of the MPU6050 to the 5V pin on the Arduino.
  2. Connect the GND pin to the GND pin on the Arduino.
  3. Connect the SDA and SCL pins to the corresponding pins on the Arduino (A4 and A5 on Arduino Uno).

Ensure the sensor is properly connected to the Arduino.

MPU6050 Circuit Setup

Code for Gyroscope and Accelerometer

Upload the following code to your Arduino to read data from the MPU6050 sensor:


#include 
#include 

MPU6050 mpu;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu.initialize();
}

void loop() {
  int16_t ax, ay, az;
  int16_t gx, gy, gz;
  mpu.getAcceleration(&ax, &ay, &az);
  mpu.getRotation(&gx, &gy, &gz);
  
  Serial.print("Accel X: "); Serial.print(ax);
  Serial.print(" Y: "); Serial.print(ay);
  Serial.print(" Z: "); Serial.println(az);
  
  Serial.print("Gyro X: "); Serial.print(gx);
  Serial.print(" Y: "); Serial.print(gy);
  Serial.print(" Z: "); Serial.println(gz);
  
  delay(500);
}
            

Explanation

The code initializes the MPU6050 sensor and reads both the acceleration and gyroscope data. The sensor detects movement along three axes (X, Y, Z), and the data is output to the serial monitor.

Troubleshooting