Example Code for Arduino-Electronic Compass
Last revision 2026/01/06
This article offers a practical guide for setting up an Arduino-based electronic compass using CurieNano and the QMC5883 library. Detailed steps for hardware and software preparation are provided, along with operational instructions to achieve accurate compass readings.
Hardware Preparation
Software Preparation
- Download Arduino IDE: Click to Download Arduino IDE
- Download the DFRobot_QMC5883 library: DFRobot_QMC5883 library
- About how to install the library?
Install the Arduino/Genuino 101 plugin by following the Getting Started tutorial.
Operation Steps
-
From "File -> Examples -> QMC5883 -> QMC5883_compass" to open "QMC5883_compass.ino", select your "board" and "port" and upload to the CurieNano in the same way you uploaded the blink sketch.

-
Wait five seconds after the download is complete, open the serial monitor port and set the baud rate 9600.
Result
Rotate the CurieNano board and you should see the angle change.

More Tutorials
Was this article helpful?
