#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
// Define sensitivity range of the gyroscope
const float gyroSensitivity = 131.0; // for ±250 dps range
void setup() {
Serial.begin(9600);
Wire.begin();
// Initialize MPU6050
mpu.initialize();
// Set Gyro sensitivity to +/- 250 degrees/sec
mpu.setFullScaleGyroRange(MPU6050_GYRO_FS_250);
}
void loop() {
// Read gyroscope values
int16_t gyro_x_raw = mpu.getRotationX();
float gyro_x_dps = gyro_x_raw / gyroSensitivity;
int16_t gyro_y_raw = mpu.getRotationY();
float gyro_y_dps = gyro_y_raw / gyroSensitivity;
int16_t gyro_z_raw = mpu.getRotationZ();
float gyro_z_dps = gyro_z_raw / gyroSensitivity;
// Print gyroscope values
Serial.print("Gyroscope X (dps): ");
Serial.println(gyro_x_dps);
Serial.print("Gyroscope Y (dps): ");
Serial.println(gyro_y_dps);
Serial.print("Gyroscope Z (dps): ");
Serial.println(gyro_z_dps );
// Delay for better readability
delay(500);
}