Hello everyone.
So I have been trying to build a GPS-guided robot in which I need to use an HMC5883L magnetometer to add a sense of direction. I have used the HMC5883L module available in the market which I later found out is not Honeywell's original module, rather it is a Chinese version of the original commonly known as the QMC5883L.
The library I am using for my module is the one already available in the Arduino IDE libraries. I just went to manage libraries, searched for QMC5883L, and installed the library. I did not install some other library from Github.
Anyways, upon completing the project, my robot was not working properly. It was either spinning around its own axis or spinning on a circular track. It is most likely some issue with the compass.
I opened a direction code available in the examples of the library. It showed directions like North, South etc. I rotated the compass and I compared it with the results of the compass on my phone and it turned out that all other directions were correct except for the 'West' direction. Whenever my phone compass showed 'West', my QMC5883L showed North. It is showing wrong direction when directed towards west. And this, I think, is the problem that why project is not working properly.
So, is my sensor faulty? Or should I use some other library? Or should I use some other compass instead of QMC5883L? Please help me.
I am attaching the example code of direction from the library.
Thank you.
</>
/*
QMC5883LCompass.h Library Direction Example Sketch
Learn more at [https://github.com/mprograms/QMC5883Compas]
This example shows how to get Compass direction.
===============================================================================================================
Release under the GNU General Public License v3
[The GNU General Public License v3.0 - GNU Project - Free Software Foundation]
*/
#include <QMC5883LCompass.h>
QMC5883LCompass compass;
void setup() {
Serial.begin(9600);
compass.init();
}
void loop() {
compass.read();
byte a = compass.getAzimuth();
char myArray[3];
compass.getDirection(myArray, a);
Serial.print(myArray[0]);
Serial.print(myArray[1]);
Serial.print(myArray[2]);
Serial.println();
delay(250);
}
</>