loading

Hello!!!

Today I will show you how to make your own arduino compass by using the MHC5883L 3-axis digital compass board.

Before you start, make sure that you have:

  • Arduino uno
  • HMC5883L sensor board
  • Nokia 5110 display (pcb version)
  • 2x push-button
  • 1x on/off switch

(you can use breadboard to build it easier)

I prefer to build my own arduino based circuit by using the ATmega328p uno possessor, but this is optional for you. Buttons are used for turn on or off display leds and to change display mode of compass.

Official page: http://www.ardumotive.com/digital-compass.html

Watch video on YouTube:

Step 1: About HMC5883L Board

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).

The HMC5883L board can be powered up by 5V or 3.3V pins of Arduino uno board. No need to add any capacitors or resistors to your circuit.

Pinout and connection with uno:

  • Vcc to 5V or 3.3V
  • GND to GND
  • SDA to A4
  • SCL to A5
  • DRDY to nothing...

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 2: Breadboard Schematic Circuit

Here is the circuit on breadboard schematic. Make sure to read "pinout" notes on image and connect lcd and sensor correct with arduino uno.

Step 3: Libraries and Code

Before open code file "arduino_compass.ino" install the necessary libraries to arduino ide libraries folder.

Just open the libraries.rar file and extract / copy all files to libraries folder.

If you have windows os and you don't know where this folder is, watch this video on YouTube: youtu.be/CdjUUo_owIc

For some parts of code, I want to thank Markus Ulsab and Galin Dimitrov who shared their own arduino compass projects.

What I did?

  • Changed Markus project to support HMC5883L sensor
  • Combined two projects for "two display modes" function
  • Correct some minor bugs
  • Add comments in my code

Step 4: Building the 'box' - Tips

This is an optional procedure!

To build the box i used one thin balsa sheet. You can easily cut it with a small cutter and paint it with marker.

See the images above to take an idea, but keep in mind that you can design and build your own box.

If you will use a battery, do not put it near HMC5883L sensor.

Some tips:

  • Make marks of components on balsa sheet
  • Cut carefully with a small cutter - Be patient and make sure that you will not cut your self!
  • Paint it with your favorite color marker
  • Put components on it
  • Use some glue to close the box

Watch video on YouTube: youtu.be/i7GaVqMSzMA (make sure to click like button ;-) )

www.ardumotive.com find Greek Arduino Projects

<p>Hi,</p><p>Will the magnetic compass sensor work for the detection of strokes made by a pen. strokes like vertical, horizontal, back slash, forward slash, etc.??</p>
<p>For those of you having issues getting the 5110 to display, change the pins to </p><p>12 SCLK, 11 DIN, 10 D/C, 9 CS, 8 RST</p>
<p>Finally got it to upload to my Uno but nothing on the screen? Very frustrated, I think I shall search for one that I can get to work!</p>
<p>Change the 5110 pinout to Adafruit_PCD8544 display = Adafruit_PCD8544(12, 11, 10, 9, 8); </p><p>Seems to be conflicting with something using the other pinout. </p>
<p>I made it, and it works good for me. Perhaps a bit slow in reaction to movements but I don't think I got the sensor level. All wiring was done with cat-5 scrap wire. I used a nano instead of uno to save space, and mounted it on a perfboard, a second perfboard was used for the switch and buttons, all mounted in a small black project box, the front being cut out with a knife to allow the screen mounting. The board and sensor are held in place with hot glue, screen mounted with two stand offs (I only had two of that size) and I am using a USB cable for power, and in case I need to adjust the programing.</p>
<p>For those who are still batteling this to make it work, I found the error that I was having, and now I can get it working just fine: I looked above the error and found that the Arduino App was using an old version of the library files. When I went and removed the old versions (based on the create date) and the old version of the Adafruit sensor library things began working once again. Guess that's what I get for always transfering my librarary files to new computers when I set them up. Thanks a million to the fellow who has taken so much flack over his wonderful work, this compass will be installed in a project box and mounted in our Class A Motor Home that we spend the winters, and much of the Spring/Fall months traveling in. For some strange reason the unit came with no compass on board. Perhaps it is the fact that she is 12 years old, who knows. Anyhow thanks again, you do great work!</p>
<p>I recently downloaded and tried compiling the sketch but all I am getting are the following errors.</p><p>(sketch file) Digital Compass Dual Display.ino:25:27: error: use of undeclared identifier 'PULLUP'<br>Button buttonA = Button(2,PULLUP); //Button to turn on/off display light</p><p><br> ^<br>(sketch file) Digital Compass Dual Display.ino:26:27: error: use of undeclared identifier 'PULLUP'<br>Button buttonB = Button(8,PULLUP); //Button for changing display mode<br> ^</p><p>Can you please help</p><p>Stuartyh</p>
<p>I emailed the author and got a reply that he knows about a couple of bug but has not got around to fix then... So I did !!!!</p><p>I'll post all on my blog later today. jonstephensonsblog.com</p><p>Jon</p>
<p>Well it looked like a nice simple project... but hell..I even make the lib's separate like this: #include &quot;j:/compass/SPI/SPI.h&quot; .</p><p>But still get so many errors I cannot even load it..</p><p>QUOTE:</p><p>In file included from C:\Users\John\Documents\Arduino\arduino_compass\arduino_compass.ino:13:0:</p><p>j:/compass/Adafruit_HMC5883_U/Adafruit_HMC5883_U.h:99:10: error: conflicting return type specified for 'virtual void Adafruit_HMC5883_Unified::getEvent(sensors_event_t*)'</p><p> void getEvent(sensors_event_t*);</p><p> ^</p><p>UNQUOTE...</p><p>This is just one error..</p><p>I'm using IDE v 1.6.8</p>
<p>I am using HMC5883L for my project. I have interfaced it<br>with the arduino and executed the program given in the website. But the problem is it is<br>showing the same angle (66.68) when I rotate &amp; if I do it in other places I<br>am facing the same problem. I have also added declination angle of that place.<br>So please help me how to make it work properly.</p>
<p>The compass board photo does not match the wiring diagram, and it's also different from the one in the photos of the device you built!</p><p>These things also say they require 3.3volts... hooking them to 5 will supposedly destroy them? Did you use a logic converter?</p>
<p>Made it, got it working, thanks to you, nodoubtman.</p>
<p>can u send me the code?</p>
<p>I need a little clarification. Your parts lists shows a Arduino-Uno board, Nokia display and a HMC5883L magnotometer . What is the board you show connected to the Display LCD? I have no experience with Arduino.</p>
<p>try this instead, it DOES work! :)</p><p>const static unsigned char PROGMEM arrow_bmp[] =<br>{ B00100000, B00100000, B01110000, B01110000, B11111000};</p>
<p>Thanks for this comment!</p>
<p>Nice compass!</p><p>Ardumotive_com, try <br>to calibrate your HMC5883L. Without calibration the measurement of the <br>magnetic field vector is not accurate (especially if your location is <br>the north or south of the Earth). </p><p>See my instructable about it:</p><p>https://www.instructables.com/id/Easy-hard-and-soft-iron-magnetometer-calibration/</p>
<p>Thanks! ;)</p>
<p>I installed all libraries into arduino folder but still not working. Below is the error</p><p>arduino_compass.ino:27:40: error: variable 'arrow_bmp' must be const <br>in order to be put into read-only section by means of <br>'__attribute__((progmem))' <br></p><p>Error compiling.</p><p>Any solution? or any other similar code?</p>
<p>hey dude? Did you see my solution? </p><p>Up?</p>
<p>I believe that is a problem with LCD and library. Try to search web to find a library that is compatible with your lcd screen. Thanks </p>
<p><br></p><p>I tried to make the compass but by this error, which means?</p><p>thanks</p><p><br></p><p>Arduino: 1.6.3 (Windows 7), Scheda: &quot;Arduino Uno&quot;</p><p>arduino_compass.ino: 27: 40: errore: 'arrow_bmp' variabile deve essere const per essere messo in sola lettura sezione attraverso '__attribute __ ((progmem))' Errore Durante la COMPILAZIONE</p>
<p>see up :)</p>
<p>Install additional libraries first.</p>
<p>I have the same problem...!!!<br>I have reinstall the Libraries again about 4 times and the same error again and again..!!!<br>What do you mean &quot;Install additional libraries first.&quot;..??<br>If you want you can send me pm in Greek..!!</p>
<p>You must copy paste all libraries that you will find in &quot;libraries.zip&quot; file. If you did this step and you still take this error I can't help you. Something is going wrong with your lcd 5110 and library. Try to search google about this error.</p>
<p>Thanks for the reply..!!<br>i did it..!!and still the same error....!!<br>the LCD 5110 works ok..with demo..!!<br>Adafruit_PCD8544 is the Library for 5110 that you give!<br>Google does not give an answer about that.<br>What version of arduino ide you use? ex. 1.6.3??</p>
<p></p><p>Installed, it does not work anyway.</p>
<p>Did you install all libaries? Below someone else has the same problem and when finally install (all) libraries, problem solved. </p>
<p>Arduino: 1.6.4 (Windows 8.1), Board: &quot;Arduino Nano, ATmega328&quot;</p><p>arduino_compass.ino:10:20: fatal error: Button.h: No such file or directory<br>compilation terminated.<br>Error compiling</p><p>I have in the same place all the libraries, but only say error with Button.h</p>
<p>Hi! You must install &quot;Button&quot; library too.</p>
<p>Sir..I would like to ask a link examples to make arduino based circuit..I want to try to make..Thank you :)</p>
<p>Hello, you can find more projects and examples with arduino uno here <a href="http://www.ardumotive.com" rel="nofollow"> www.ardumotive.com </a> (Greek) and here http://en.ardumotive.com (English).</p><p>English Ardumotive is under developing and it will have more tutorials and projects in English very soon, so stay online! ;)</p><p>Tip: You can translate Greek ardumotive by using google chrome, google translate or bing translate :D</p>
<p>Hello,</p><p>TKS for sharing this is what I am looking for.</p><p>Unfortunately when rotating the sensor far from magnetic devices, and 90&deg; at once, the displlay does not show 90&deg; variation but something like</p><p>59</p><p>193</p><p>275</p><p>330</p><p>And the needle is wrong too.</p><p>Declination is set for my location in the sketch.</p><p>I use the Libraries from this site</p><p>Can you please help ?</p><p> </p><p>TKS</p><p>Laconique</p><p> </p>
<p>Just make sure that HMC5883L is on flat surface.</p><p>If you watch my video you will see that works fine ;) </p>
<p>TKS for prompt answer. It is on a flat surface.</p><p>Generaly problems with arduino come from unadequate libraries.</p><p>Would you be so kind to provide links to the right ones </p><p>Kindly </p><p>Lacornique</p>
<p>Try to re-install all libraries. You can find a download link on step 3. Let me know if you succeed ;) </p>
<p>Hi,</p><p>Finaly I found I have to calibrate the HMC5883.</p><p>I used the infos found here:</p><p><a href="http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-magnetometr-hmc5883l.html" rel="nofollow">http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-magnetometr-hmc5883l.html</a></p><p>For instance I had to modify X and Y offset and now it is allright.</p><p>I tried with two HMC5883 and they have different offsets.</p>
<p>I need a module , any module can be sent via email<br><br>email :huntermoci@gmail.com <br><br>thank you</p>
<p>i will try make this project but I dont understand with this circuit behind the LCD, i can not find in this tutorial, what the function of that circuit</p>
<p>Hi! It's Arduino based circuit. You can use Arduino uno! ;)</p>
<p>Tried x-times before to make a working compass of that MHC, never worked...</p><p>Most had to be calibrated as soon as I left my desk. Gonna try this one out! Thanks for sharing!</p>
<p>This program error sir,,, help<br>arduino_compass.ino:27:40: error: variable 'arrow_bmp' must be const in order to be put into read-only section by means of '__attribute__((progmem))'</p><p>Error compiling.</p>
<p>Install additional libraries first. </p>
<p>done sir :)</p>
<p>where diagram blok Arduino Digital Magnetic Compass..?</p>
<p>You can find breadboard circuite schematic on step 2.</p>
<p>Easy to make looks cool,thanks for the idea.</p>
<p>This is awesome! I would have never guessed that this could be done! </p>
<p>Thanks!!! In the world of arduino, all are possible! :D</p>

About This Instructable

73,150views

143favorites

License:

More by Ardumotive_com:Arduino 3D Printed Compass Arduino Bluetooth Car With Custom PCB DIY Arduino LED Matrix Display - 80x8 Px 
Add instructable to: