Introduction The electronic compass is designed to detect the earth’s magnetic field and provide magnetic heading data to a microcontroller like Arduino. The one we’ll be using today is the GY-271 module, based on the HMC5883L sensor. Equipped with a Hall-effect sensor, the GY-271 offers reasonable accuracy for measuring magnetic orientation. It incorporates a three-axis system that detects variations in the magnetic field on the X, Y and Z axes. This data can be used to determine the direction in which the module is oriented in relation to magnetic north.GY-271 compass pins Vcc : To be connected to the 3.3V of the Arduino boardGND : Connect to Arduino board groundSDA : Connect to pin A4 of analog outputsSCL: Connect to pin A5 of analog outputs Electronic schematic Here’s the circuit diagram for connecting the GY-271. It uses the i2C of the Arduino board: Programming To download the program for the GY-271 compass you’ll need to install the adafruit library for the HMC5883, which is the chip that controls our compass: