Measuring angle with gyroscope

Hi,
I'm using MPU6050 accelerometer and gyroscope module with Arduino NANO and wanted to ask, whether it is possible to calculate angle from the gyroscope data, or not? And if it is, how could I do it?

The angle of what?

I don’t think it’s possible. See this post: gyro sensor to measure angle - Sensors - Arduino Forum

The gyro measures the rate of rotation.

For short periods of time you can integrate the output data with respect to time to get the angle through which the sensor has rotated. But it is only a rough approximation.

For angles relative to the gravity vector (down) use the accelerometer. For azimuth (compass direction) angles, use a three-axis magnetometer. The rate gyroscope is good for "Am I rotating?" and, to some extent, "How fast am I rotating?"

Okay, thanks for all the replies and I have one more question. Is it possible to combine accelerometer and gyroscope data to get more precise tilt value than just using accelerometer (or at least get some tilt value)?
I've used a code for measuring tilt with accelerometer and would like to combine it with gyro values.

Here is the accelerometer code:

#include "Wire.h"
#include "Math.h"
#include "I2Cdev.h"
#include "MPU6050.h"
 

MPU6050 accelerometer;
 

const float pi = 3.141592;

const int pocet_vzorku = 100;

int16_t ax, ay, az;
float x, y, z;
int  pocet;
float _angle_x, angle_x, _angle_y, angle_y;
long ax_p, ay_p, az_p;
 
void setup() {
   
    Wire.begin();

    Serial.begin(38400);
 
    accelerometer.initialize();
   
    if (accelerometer.testConnection());
    Serial.println("Connection OK...");  
}
 
void loop() {
    
    accelerometer.getAcceleration(&ax, &ay, &az);

    ax_p = ax_p + ax;
    ay_p = ay_p + ay;
    az_p = az_p + az;

    pocet++;
      
    if (pocet == pocet_vzorku)
    {
    
     x = ax_p/pocet_vzorku;
     y = ay_p/pocet_vzorku;
     z = az_p/pocet_vzorku;
  
     angle_y = atan2(y, sqrt(square(x) + square(z))      )/(pi/180);
   
     delay(2000);
     pocet = 0;
     ax_p = 0;
     ay_p = 0;
     az_p = 0;
      
    Serial.println(angle_y);
    }
   
   
}

pocet vzorku = number of samples

For a Uno/Mega, look up "arduino complementary filter", pieter-jan.com - This website is for sale! - pieter jan Resources and Information..

Otherwise go with a Kalman Filter like this: GitHub - denyssene/SimpleKalmanFilter: A basic implementation of Kalman Filter for single variable models. which I found works quite well.

more precise tilt value

If the sensor is not moving, the gyro is useless, or worse. It just adds noise.

Tilt is measured using the accelerometer.