#include <Wire.h>
#include <MPU6050.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(19, 23, 18, 17, 16, 15);
// Create an instance of the MPU6050 object
MPU6050 mpu;
// Variables to hold accelerometer and gyroscope data
int16_t ax, ay, az;
int16_t gx, gy, gz;
float ax1,ay1,az1;
float magnitude;
void setup() {
// Start the serial communication for debugging
Serial.begin(115200);
// Initialize I2C communication
Wire.begin();
lcd.begin(16,2);
// Initialize the MPU6050 sensor
mpu.initialize();
// Check if the MPU6050 is connected
if (mpu.testConnection()) {
Serial.println("MPU6050 is connected");
} else {
Serial.println("MPU6050 connection failed");
while (1);
}
}
void loop() {
lcd.setCursor(0,0);
// Read accelerometer and gyroscope values
mpu.getAcceleration(&ax, &ay, &az);
mpu.getRotation(&gx, &gy, &gz);
// Print accelerometer values (in raw format)
Serial.print("Accel X: ");
Serial.print(ax);
Serial.print("\tAccel Y: ");
Serial.print(ay);
Serial.print("\tAccel Z: ");
Serial.println(az);
ax1= (float)ax/16384;
ay1= (float)ay/16384;
az1= (float)az/16384;
magnitude = sqrt((ax1*ax1)+(ay1*ay1)+(az1*az1));
// Print gyroscope values (in raw format)
Serial.print("Gyro X: ");
Serial.print(gx);
Serial.print("\tGyro Y: ");
Serial.print(gy);
Serial.print("\tGyro Z: ");
Serial.println(gz);
Serial.print("magnitude value:");
Serial.print(magnitude);
if (magnitude>2.7){
Serial.println("error");
lcd.println("error");
}
else{
lcd.println("good performance");
}
// Wait for 500ms
delay(500);
}