#include <Wire.h>
#include <MPU6050.h>
// Create an instance of the MPU6050 class
MPU6050 mpu;
void setup() {
// Start the I2C communication
Wire.begin();
// Start serial communication
Serial.begin(9600);
// Initialize the MPU6050
mpu.initialize();
// Check if the MPU6050 is connected
if (mpu.testConnection()) {
Serial.println("MPU6050 connection successful");
} else {
Serial.println("MPU6050 connection failed");
}
}
void loop() {
// Variables to hold sensor data
int16_t ax, ay, az;
int16_t gx, gy, gz;
// Get the raw data from the MPU6050fall
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
// Print the sensor data to the serial monitor
Serial.print("ax: "); Serial.print(ax);
Serial.print(" ay: "); Serial.print(ay);
Serial.print(" az: "); Serial.print(az);
Serial.print(" gx: "); Serial.print(gx);
Serial.print(" gy: "); Serial.print(gy);
Serial.print(" gz: "); Serial.println(gz);
// Wait for a short period before taking the next reading
delay(100);
}