HMC5883L digital compass module gives 3-axis magnetic field component values, which can be used to determine the Azimuth angle (Heading). However, this method will give accurate Heading only when the module is held horizontal to the gound.
That is, when the module is tilted, the calculated Heading value will be incorrect. To compensate for the tilt, an accelerometer sensor is used to calculate the tilt angles (Roll and Pitch). The tilt angles are applied to a correction formula to obtain the accurate Heading value. Here, accelerometer values are read from MPU6050 Accelerometer+Gyroscope module.