Arduino Digital Magnetic Compass (HMC5883L - 2 Display Modes)
Intro: Arduino Digital Magnetic Compass (HMC5883L - 2 Display Modes)
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
62 Comments
zeddock 1 year ago
Since this is my first attempted project, I want to find a community that is more active on a project dealing with compass, display, UNO.
Would it be a mistake to start with this one? All answers appreciated!
Pogo555 7 weeks ago
Gee, so long. I hope that you do try it out. The original project will work, then you can tweak it to your liking.
Pogo555 10 months ago
The fix is to add the missing bounds check: if (x < 0) x += 120; Then, when pointing west, the strip correctly displays "N" on the right.
lautungho3 1 year ago
Pogo555 10 months ago
You *could* use an oled display, but the ATMega has too little ram to properly draw graphics. You might try something like a Nano Every.
EDIT
I made one with an oled display. I had to be very frugal with memory use to leave enough memory for the display buffer. But it ran and looked good. Indoors. The oled display is not daylight readable.
seyyidkutub169 1 year ago
ARDUMOTIVE
ArduinoBased
compassn.Compass
Michalis Vas
nodoubtman 8 years ago
try this instead, it DOES work! :)
const static unsigned char PROGMEM arrow_bmp[] =
{ B00100000, B00100000, B01110000, B01110000, B11111000};
Tommy2018 1 year ago
Ardumotive_com 8 years ago
Thanks for this comment!
Tommy2018 1 year ago
FJT7PE9I7CCG6CH:27:40: error: variable 'arrow_bmp' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
static unsigned char PROGMEM arrow_bmp[] ={B00100000, B00100000, B01110000, B01110000, B11111000,};
^
Multiple libraries were found for "SPI.h"
Used: C:\Program Files\arduino-nightly-windows\arduino-nightly\hardware\arduino\avr\libraries\SPI
Not used: C:\Program Files\arduino-nightly-windows\arduino-nightly\libraries\SPI
Multiple libraries were found for "Wire.h"
Used: C:\Program Files\arduino-nightly-windows\arduino-nightly\hardware\arduino\avr\libraries\Wire
Not used: C:\Program Files\arduino-nightly-windows\arduino-nightly\libraries\Wire
exit status 1
variable 'arrow_bmp' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
"
So, what is to be done?
idd_hasanaj 3 years ago
jandok48 3 years ago
lemarikoleksi 9 years ago
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
brightled 4 years ago
Ardumotive_com 9 years ago
Hi! It's Arduino based circuit. You can use Arduino uno! ;)
Joshua Bulambot 5 years ago
RaphaelJ7 5 years ago
Depends on where you bought, pin out is different.
If you did not witness any blue light, you connected to wrong pin.
Nishkotak 7 years ago
Hi,
Will the magnetic compass sensor work for the detection of strokes made by a pen. strokes like vertical, horizontal, back slash, forward slash, etc.??
JasonR4 7 years ago
For those of you having issues getting the 5110 to display, change the pins to
12 SCLK, 11 DIN, 10 D/C, 9 CS, 8 RST
jerry.ericsson2 8 years ago
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!