#include <Wire.h> // Include Wire library for I2C communication
#include <MPU6050_light.h> // Include library for MPU6050 communication
#include <LiquidCrystal_I2C.h> // Library for LCD Display
MPU6050 mpu(Wire); // Create an MPU6050 object and pass Wire as the I2C communication parameter
LiquidCrystal_I2C lcd(0x27, 16, 2); // Define LCD address and dimensions
unsigned long timer = 0;
void setup()
{
Serial.begin(9600); // Start serial communication for debugging
lcd.begin(16, 2); // Initialize the LCD Display
lcd.backlight();
Wire.begin(); // Initialize I2C communication
mpu.begin(); // Initialize the MPU6050 sensor
Serial.print(F("MPU6050 status: "));
Serial.println(F("Calculating offsets, do not move MPU6050"));
delay(1000);
mpu.calcGyroOffsets(); // Calibrate the gyroscope
Serial.println("Done!\n");
}
void loop() {
mpu.update(); // Get the latest values from the MPU6050 sensor
if ((millis() - timer) > 100) { // Print data every 100ms
timer = millis();
lcd.clear();
lcd.print(" Angle: ");
lcd.print(int(mpu.getAngleZ())); // Get the Z-axis angle value and print it on the LCD
delay(10);
}
}