Gyroscope and Accelerometer

Gyroscope and Accelerometer

Components:

1- Arduino

 

2-MPU6050 Sensor

 

3- Wires

Connections:

Vcc : 5v 

Gnd : Gnd

SCL : A5

SDA : A4

INT : D2

Code:

#include <Wire.h>
#include <MPU6050.h>

MPU6050 mpu;

void setup() {
  Serial.begin(9600);
  while (!Serial) {}

  if (!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G)) {
    Serial.println(“Failed to initialize gyroscope sensor.”);
    while (1);
  }

  mpu.calibrateGyro();
}

void loop() {
  float angle = mpu.getAngleZ();
  Serial.print(“Angle: “);
  Serial.println(angle);

  delay(100);
}

Leave a comment

Your email address will not be published. Required fields are marked *