MPU 6050 not giving reliable data

A bit of a newbie here but I need my MPU 6050 to give the yaw pitch and roll and display them on an LCD but when I do it gives me data in the thousands and fluctuates greatly within one tick to the next. I have tried many codes and am not sure if it’s a wiring issue or a coding issue. If anyone could help me it’ll be greatly appreciated.

This is my code:
#include <MPU6050.h>
#include<Wire.h>
#include <LiquidCrystal.h>
MPU6050 mpu;
LiquidCrystal lcd(12, 11, 5, 4, 3, 7);
const int MPU=0x68;
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
unsigned long timer = 0;
float timeStep = 0.01;

// Pitch, Roll and Yaw values
float pitch = 0;
float roll = 0;
float yaw = 0;

void setup(){

lcd.begin(16,2);
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);

Serial.begin(9600);

}

void loop(){

Wire.beginTransmission(MPU);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU,12,true);
AcX=Wire.read()<<8|Wire.read();
AcY=Wire.read()<<8|Wire.read();
AcZ=Wire.read()<<8|Wire.read();
GyX=Wire.read()<<8|Wire.read();
GyY=Wire.read()<<8|Wire.read();
GyZ=Wire.read()<<8|Wire.read();

Serial.print("Gyroscope: ");
Serial.print("X = "); Serial.print(GyX);
lcd.setCursor(0,0);
lcd.print("X= “); lcd.print(GyX);
Serial.print(” | Y = "); Serial.print(GyY);
lcd.setCursor(9,0);
lcd.print("Y= “); lcd.print(GyY);
Serial.print(” | Z = "); Serial.println(GyZ);
lcd.setCursor(6,1);
lcd.print("Z= “); lcd.print(GyZ);
Serial.println(” ");
delay(2000);
}

MPU6050_LCD.ino.ino (1.21 KB)

You are displaying the raw rate of rotation values from the gyro, which don't tell you much.

The accelerometer and gyro data need to be processed and merged in order to calculate roll and pitch angles. You can start reading about how that works here.

Thank you for your replay, as I stated, I am a newbie and don't know how to merge the raw data and could not find it on the website you have shown. Any further explanation would be gratefully appreciated.

There are libraries that do the data processing for you. Google "Arduino MPU6050" for tutorials.

The web site I linked explains what the angles mean and the theory of operation.

To make any sense of the program results, you will need to have some basic understanding of that material.