Hi! I was working with the HCM5883L magnetometer and asking the code por x,y,z positions, the problem is that the values go from 0, to 1000, to 50 in just seconds when I'm not really moving it at all. Do you know a github or a place to find a better code for my magnetometer or do you guys have a code you have implemented previously on your projects? Thanks
A magnetometer measures the strengths of magnetic fields. How do you propose to convert the measurements into x,y,z position?
Most people use magnetometers to measure compass directions, usually the angle from magnetic or true North.
It is measuring orientation/direction not position.
Tom...
![]()
Ohh yeah my bad, I was referring to directions. Someone said to me that we needed to calibrate it for around 5 min is it true?
I was using this code but still the values that are printed on the serial monitor are like 2,1000,40,500,0,80, etc not on a range like 0,-2,5,3,-1 that is correct. I'm literally not moving the sensor
#include <Wire.h>
#include <QMC5883L.h>
QMC5883L compass;
void setup() {
Wire.begin();
Serial.begin(9600);
compass.init();
}
void loop() {
int x, y, z;
compass.read(&x, &y, &z);
Serial.print("x: ");
Serial.print(x);
Serial.print(" y: ");
Serial.print(y);
Serial.print(" z: ");
Serial.println(z);
delay(250);
}
Hi,
What model Arduino are you using?
Tom...
![]()
Arduino UNO, I'm using Arduino IDE to program it
In order to work as a compass, the magnetometer must be calibrated. The best overview and tutorial is this one: Tutorial: How to calibrate a compass (and accelerometer) with Arduino | Underwater Arduino Data Loggers
first off , figure out what module you're using !
QMC5883L or HMC5883L ?? ![]()
I found out that the HMC5883L is like fake so it is best to use the QMC5883L library, someone recommended that to me
