This is a tutorial on how to do magnetic field measurement with an Arduino, a HMC5883L triple axis magnetometer and a Piezo Speaker.
First of all, here is a schematic on how to hook up everything.
Source images from:
HMC5883L GND -> Arduino GND
HMC5883L VCC -> Arduino 3.3V
HMC5883L SDA -> Arduino A4
HMC5883L SCL -> Arduino A5
Piezo Speaker – -> Arduino D10 (Any digital PWM port is sufficient)
Piezo Speaker + -> Arduino GND
Let’s get to the programming part.
First of all download this HMC5883L Arduino library:
Then put the HMC5883L folder into your library.
Default Library Folder Location
Mac: In (home directory)/Documents/Arduino/libraries
PC: My Documents -> Arduino -> libraries
Linux: (home directory)/sketchbook/libraries
Once this is done you can start programming.
I’ve put my code on Github, you can find it here: https://github.com/Black-Pixel/Arduino/tree/master/magneticFieldStrength
It should not be hard to understand. If you have any questions or suggestions feel free to write a comment.
Sources and other helpful sites: