Digital compass using magnetometer HMC5883L 

place the magnetometer module on the breadboard connect the power to Arduino's 3v3 pin (3.3 volts) connect ground to Arduino's ground pin connect SDA(serial data) pin toA4 of Arduino (UNO or nano, check the pinouts of your Arduino type) connect SCL (serial clock )to A5 of Arduino pin.

connect the USB cable from the computer to Arduino open Arduino ide copy the sketch, choose the appropriate board and COM port click upload and open the serial monitor.

the heading angle is calculated keeping the board parallel to earth surface or x-axis is perpendicular to the earth's surface.