MAGNETOMETER

TINKS038

  1. The Compass Module is designed for low-field magnetic sensing with a digital interface and perfect to give precise heading information.
  2. This compact sensor fits into small projects such as UAVs and robot navigation systems.
  3. The sensor converts any magnetic field to a differential voltage output on 3 axes.
Features:-
  1. Power 3V-5V DC
  2. Chipset HMC5883L
  3. Communication via I2C protocol
  4. 3-axis sensing
  5. Small, low-profile package.
Applications:-
  1. They are used for navigational purposes.
  2. They are used in anti-lock braking systems in vehicles.
  3. Magnetometers are used for mineral exploration, it is used to search world-class deposits of gold, silver, iron copper, etc.
  4. They are used in many defence applications; UAVs, submarines, etc.
  5. Magnetometers have found usages in smartphones which have applications that serve as compasses.

    

#include <Wire.h>
#include <HMC5883L.h>
HMC5883L compass;
void setup()
{
Serial.begin(9600);
Wire.begin();
compass = HMC5883L();
compass.SetScale(1.3);
compass.SetMeasurementMode(Measurement_Continuous);
}
void loop()
{
MagnetometerRaw raw = compass.ReadRawAxis();
MagnetometerScaled scaled = compass.ReadScaledAxis();
float xHeading = atan2(scaled.YAxis, scaled.XAxis);
float yHeading = atan2(scaled.ZAxis, scaled.XAxis);
float zHeading = atan2(scaled.ZAxis, scaled.YAxis);
if(xHeading < 0) xHeading += 2*PI;
if(xHeading > 2*PI) xHeading -= 2*PI;
if(yHeading < 0) yHeading += 2*PI;
if(yHeading > 2*PI) yHeading -= 2*PI;
if(zHeading < 0) zHeading += 2*PI;
if(zHeading > 2*PI) zHeading -= 2*PI;
float xDegrees = xHeading * 180/M_PI;
float yDegrees = yHeading * 180/M_PI;
float zDegrees = zHeading * 180/M_PI;
Serial.println(xDegrees);

Serial.print(",");
Serial.println(yDegrees);

Serial.print(",");
Serial.println(zDegrees);

Serial.println(";");
delay(100);
}