Arduino 3D Printed Compass




In this Instructables guide I will show you how to make your own Arduino based digital magnetic compass.

In this guide you will also find the .stl files of the 3d printed case/box.

Let's get started!

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: ​What You Will Need - Hardware

For this project you will need:

If you want to make the whole circuit to fit inside our 3D printed box you must buy:

You will also need the Arduino uno board for the programming procedure.

If you want to make it super easy, without the 3d printed case or if you want to make it bigger to your own box you will need:


  • 3D printer (for the box/case of your compass)
  • Soldering iron if you want to make your own small circuit
  • Glue

Step 2: The Circuit

Above you will find the breadboard and electronic circuit schematic. Ι suggest you to build your circuit on (small) breadboard first. The connections are easy, just follow the pinout.

Here you can find the electronic circuit schematic on better detail than above image

About the HMC5883 sensor:

The HMC5883L sensor is a 3-axis digital magnetometer IC designed for low-field magnetic sensing. The sensor has a full-scale range of +8 to -8 Gauss and a resolution of up to 5 milli-Gauss. Communication with the HMC5883L is simple and all done through an I2C interface. That means you will need to connect power, ground and only two cables to Arduino uno board (SDA,SCL).


Because this is a magnetic compass if you put it near to battery, motors, metallic surface or magnetic field, the result will diverge from the actual.

Also make sure to use it on a flat surface!

Step 3: The Code

Download the code from here and open it with Arduino IDE. Inside you will also find all necessary libraries!

Program the ATmega328p with your Arduino uno board, detach it from it and plug it on your custom circuit.

(if you are using a breadboard for testing, here you must see that everything working fine)

Special note: Code line: 60 to 63

// Once you have your heading, you must then add your 'Declination Angle', which is the 'Error' of the compassnetic field in your location.
// Find yours here: // Mine is: -13* 2' W, which is ~13 Degrees, or (which we need) 0.22 radians

float declinationAngle = 0.22; //<--Change 0.22 with yours. If you can't find your declination just delete those lines ;)

Step 4: 3D Printer Files

Use full support on your printing procedure.

Above image will help you to understand how you can fit them all inside it.

Make sure that the sensor is glued well on the bottom part - lid and the "x" label looking to the same direction as "N" letter on the top of the main part.

Step 5: Well Done!

Well...that's it!

I hope you liked this, let me know in the comments!
I would also like to see some photos with your new 3D printed Arduino Compass!

Microcontroller Contest 2017

Participated in the
Microcontroller Contest 2017

Be the First to Share


    • Instrument Contest

      Instrument Contest
    • Make it Glow Contest

      Make it Glow Contest
    • STEM Contest

      STEM Contest

    8 Discussions


    2 years ago

    It's a cute way of having fun and using up some time, but if you actually needed a compass for outdoor pursuits (where you life might depend on it) then you'd get a tough, traditional compass. The only thing you depend on then is the Earth's magnetic field not failing. The idea that anyone might rely on a battery powered electronic compass in a wilderness setting is frightening.

    2 replies

    Reply 11 months ago

    All airplanes use the same thing only the parts are built stronger...why buy if you can build it.


    1 year ago

    really nice project,I will be using it on a small sailboat ...please remove the metal screws and use plastic ones also I will use lipo battery with charge controller with it pluged into boat power. And THANKS real nice job


    Reply 2 years ago

    Thank you Swansong ;) I hope to see a photo from your own compass!