You are on page 1of 4

HMC5883L 3-Axis Magnetometer

Katherine Reyes

I. Overview
The Sensor I will be using is the HMC5883L 3-Axis Magnetometer and it measures magnetic
fields. This sensor measures the ambient geometric field, magnetic force which surrounds the
earth, on 3 physical axes (x,y,z) in units of micro Tesla (uT) .
Since the sensor aligns itself to the Earths magnetic poles, while the earths rotational axis
defines the geographic north and south poles, a discrepancy of 11.5 degrees lies between the
geographic and magnetic poles which interfere with the accuracy of the magnetometers values.
The accuracy of the sensors reading may also be interfered with the presence of electronics and
magnets.

II. Wiring and Connection


A. Follow the instructions below as follows in accordance to the Arduino and Magnetometer

picture:
1. Connect VIN to 5V pin on the Arduino. If you have a 3V logic Arduino, connect VIN to
3V instead
2. Connect GND to the ground pin on the Arduino
3. Connect the SDA pin on the breakout to the I2C data SDA pin on your Arduino. On an
UNO & '328 based Arduino, this is also known as A4, on a Mega it is also known as
digital 20 and on a Leonardo/Micro, digital 2
4. Connect the SCL pin on the breakout to the I2C clock SCL pin on your Arduino. On an
UNO & '328 based Arduino, this is also known as A5, on a Mega it is also known as
digital 21 and on a Leonardo/Micro, digital

III. Supporting Software


A. There are 2 libraries that need to be installed in order to use the magnetometer.
1. Download the first library here: https://github.com/adafruit/Adafruit_Sensor
2. Next, Rename the recently downloaded folder and verify that the Adafruit_Sensor folder
contains Adafruit_Sensor.h
3. Move the Adafruit_Sensor folder to an arduinosketchfolder/libraries/ folder
4. If this is your first library, create a libraries subfolder
5. Finally, Restart the IDE
B. The second Library That must be installed can me downloaded here: https://github.com/adafruit/
Adafruit_HMC5883_Unified/archive/master.zip
1. One this Uninified" library is downloaded, rename the uncompressed folder
Adafruit_HMC5883_U and verify that the Adafruit_HMC5883_U contains
Adafruit_HMC5883_U.cpp and Adafruit_HMC5883_U.
2. Place both Adafruit_Adafruit_HMC5883_U library folder and arduinosketchfolder/
libraries/ folder the same way that was done with the Adafruit_Sensor descibed in the fist
library installation instructions.
3. Restart the IDE once again
C. You can get tutorial hon how to set up the sensor at: https://learn.adafruit.com/adafruit-hmc5883l-
breakout-triple-axis-magnetometer-compass-sensor/wiring-and-test
D. And at: http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use

IV. Sample Program


1. To start the program that will run the code, first
you must open : File->Examples-
>Adafruit_HMC5883_U->magsensor (as shown
on the right) and upload to the Arduino
2. Once the program is open it must be loaded to
your Arduino board.
3.After it has
loaded, open
up the serial
monitor and
set it to 9600
baud at the
bottom right
hand corner
shown on the left
4.The outputs the program should reflect the numbers
below in micro Tesla (uT), of the x,y,z axises

V. Example Project
A. The purpose of this project is to test the difference in magnetic and directional poles when the
sensor is attached to the door while being opened and closed
B. The overall arching goal is to attack an LED light and allow for it to turn on upon tiers
detection of the door oping or closing
Data when door was closed: Data when door was open:
HMC5883 Magnetometer Test HMC5883 Magnetometer Test

------------------------------------ ------------------------------------
Sensor: HMC5883 Sensor: HMC5883
Driver Ver: 1 Driver Ver: 1
Unique ID: 12345 Unique ID: 12345
Max Value: 800.00 uT Max Value: 800.00 uT
Min Value: -800.00 uT Min Value: -800.00 uT
Resolution: 0.20 uT Resolution: 0.20 uT
------------------------------------ ------------------------------------

X: 13.18 Y: -78.55 Z: -17.04 uT X: 28.45 Y: 38.55 Z: -28.47 uT


Heading (degrees): 292.13 Heading (degrees): 66.17
X: 13.00 Y: -78.64 Z: -16.94 uT X: 28.45 Y: 38.18 Z: -27.96 uT
Heading (degrees): 291.99 Heading (degrees): 65.91
X: 13.18 Y: -78.91 Z: -16.94 uT X: 28.27 Y: 38.45 Z: -28.37 uT
Heading (degrees): 292.09 Heading (degrees): 66.28
X: 13.27 Y: -78.55 Z: -16.53 uT X: 28.55 Y: 38.36 Z: -28.27 uT
Heading (degrees): 292.20 Heading (degrees): 65.95
X: 13.27 Y: -78.73 Z: -16.84 uT X: 28.64 Y: 38.36 Z: -28.67 uT
Heading (degrees): 292.17 Heading (degrees): 65.87
X: 13.09 Y: -78.64 Z: -16.73 uT X: 28.64 Y: 38.36 Z: -29.08 uT
Heading (degrees): 292.06 Heading (degrees): 65.87
X: 13.09 Y: -78.73 Z: -17.35 uT X: 28.45 Y: 38.27 Z: -28.57 uT
Heading (degrees): 292.05 Heading (degrees): 65.98
X: 13.36 Y: -79.00 Z: -17.14 uT X: 28.64 Y: 38.27 Z: -28.27 uT
Heading (degrees): 292.21 Heading (degrees): 65.80
X: 13.18 Y: -78.73 Z: -17.04 uT X: 28.36 Y: 37.91 Z: -28.47 uT
Heading (degrees): 292.11 Heading (degrees): 65.80
X: 13.09 Y: -78.91 Z: -16.73 uT X: 28.27 Y: 38.09 Z: -28.27 uT
Heading (degrees): 292.02 Heading (degrees): 66.02
X: 13.09 Y: -78.91 Z: -16.73 uT X: 28.64 Y: 38.09 Z: -28.57 uT
Heading (degrees): 292.02 Heading (degrees): 65.67
X: 13.18 Y: -78.82 Z: -17.04 uT X: 28.45 Y: 38.18 Z: -28.57 uT
Heading (degrees): 292.10 Heading (degrees): 65.91
X: 12.91 Y: -78.73 Z: -17.04 uT X: 28.36 Y: 38.55 Z: -28.78 uT
Heading (degrees): 291.92 Heading (degrees): 66.26
X: 13.18 Y: -78.82 Z: -17.04 uT X: 28.18 Y: 38.18 Z: -28.47 uT

You might also like