#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
void setup() {
Serial.begin(9600);
Wire.begin();
// Initialize MPU6050
Serial.println("Initializing the MPU6050...");
mpu.initialize();
if (!mpu.testConnection()) {
Serial.println("MPU6050 connection failed!");
while (1);
}
Serial.println("MPU6050 ready!");
delay(1000);
}
void loop() {
int16_t ax, ay, az; // Acceleration values
int16_t gx, gy, gz; // Gyroscope values
// Read the raw accelerometer and gyroscope data
mpu.getAcceleration(&ax, &ay, &az);
mpu.getRotation(&gx, &gy, &gz);
// Print accelerometer values
Serial.print("Accel X: "); Serial.print(ax);
Serial.print(" | Accel Y: "); Serial.print(ay);
Serial.print(" | Accel Z: "); Serial.println(az);
// Print gyroscope values
Serial.print("Gyro X: "); Serial.print(gx);
Serial.print(" | Gyro Y: "); Serial.print(gy);
Serial.print(" | Gyro Z: "); Serial.println(gz);
delay(500); // Wait a bit between readings
}