#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
void setup() {
Serial.begin(115200);
while (!Serial);
delay(20);
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(20);
}
}
}
void loop() {
sensors_event_t acc, gyro, temp;
mpu.getEvent(&acc, &gyro, &temp);
// Print Acceleration on X, Y, Z Axes
Serial.println("Acceleration (m/s^2):");
Serial.print("X: "); Serial.print(acc.acceleration.x);
Serial.print(" | Y: "); Serial.print(acc.acceleration.y);
Serial.print(" | Z: "); Serial.println(acc.acceleration.z);
// Print Rotation on X, Y, Z Axes
Serial.println("Rotation (degrees/sec):");
Serial.print("X: "); Serial.print(gyro.gyro.x * 180 / 3.14);
Serial.print(" | Y: "); Serial.print(gyro.gyro.y * 180 / 3.14);
Serial.print(" | Z: "); Serial.println(gyro.gyro.z * 180 / 3.14);
// Print Temperature
Serial.print("Temperature (°C): ");
Serial.println(temp.temperature);
Serial.println(); // Add an empty line between readings
delay(1000); // Delay between readings
}