How to Calibrate a Magnetometer | Digi-Key Electronics
Magnetometers are fantastic sensors that allow you to measure the strength and direction of magnetic fields. With a little bit of math, they can be used as digital compasses to find your absolute orientation on Earth. However, they are very susceptible to extraneous magnetic fields (hard iron distortions) and nearby ferrous materials (soft iron distortions). In this video, we construct a basic digital compass using a magnetometer, which measures the strength and direction of the Earth’s magnetic field. We demonstrate possible distortion effects and show how to perform hard iron and soft iron calibration. A written version of this guide can be found here: https://www.digikey.com/en/maker/projects/how-to-calibrate-a-magnetometer/50f6bc8f36454a03b664dca30cf33a8b Example code shown in the video: https://github.com/ShawnHymel/mag-cal-example Adafruit SensorLab: https://github.com/adafruit/Adafruit_SensorLab PJRC MotionCal: https://www.pjrc.com/store/prop_shield.html NOAA magnetic declination calculator: https://www.ngdc.noaa.gov/geomag/declination.shtml Due to the moving, liquid metal in the outer core, the Earth acts like a giant magnet. While the magnetic field produced is not very strong, we can still detect it with permanent magnets (how a needle compass works) or magnetometers. If we find the direction of the field, we can find the direction of the magnetic north and south poles. From there, we can calculate our absolute heading. However, nearby permanent magnets and electric currents produce magnetic fields that can interfere with these readings. This is known as “hard iron distortion.” We can sample the magnetic field strength around the sensor to create simple X, Y, and Z offset values that we subtract from our raw readings. Additionally, nearby ferrous materials can distort the magnetic fields (known as “soft iron distortions”). We can sample the raw X, Y, and Z values and analytically find the scaling factors to account for this type of distortion. If you’d like to dig into the math, we recommend checking out this application note: https://www.nxp.com/docs/en/application-note/AN4246.pdf In the video, we show how to perform the magnetometer calibration process using Adafruit SensorLab and PJRC MotionCal. We then use the offset values from that program to create a calibrated digital compass. Finally, we include magnetic declination so you can see how to convert from a magnetic heading to a geographic heading. Product Links: Adafruit Feather M0 Basic - https://www.digikey.com/en/products/detail/adafruit-industries-llc/2772/5775537 Adafruit Triple-Axis Magnetometer LIS3MDL - https://www.digikey.com/en/products/detail/adafruit-industries-llc/4479/11569126 Adafruit STEMMA JST PH 4-pin to male header cable - https://www.digikey.com/en/products/detail/adafruit-industries-llc/3955/9745250 Related Videos: Magnetometer Tutorial - https://www.digikey.com/en/videos/n/next-industries-srl-the-tactigon/tutorial-3-magnetometer 3D Magnetic Field Sensor IC (Magnetometer) - https://www.digikey.com/en/videos/m/melexis/3d-magnetic-field-sensor-ic-magnetometer Related Project Links: How to Calibrate a Magnetometer - https://www.digikey.com/en/maker/projects/how-to-calibrate-a-magnetometer/50f6bc8f36454a03b664dca30cf33a8b Related Articles: Adafruit Magnetometer Calibration Tutorial - https://learn.adafruit.com/adafruit-sensorlab-magnetometer-calibration How to Calibrate a Magnetometer? - https://www.appelsiini.net/2018/calibrate-magnetometer/ Tutorial: How to calibrate a compass (and accelerometer) with Arduino - https://thecavepearlproject.org/2015/05/22/calibrating-any-compass-or-accelerometer-for-arduino/ Magnetometer Hard & Soft Iron Calibration - https://www.vectornav.com/resources/inertial-navigation-primer/specifications--and--error-budgets/specs-hsicalibration Calibrate an eCompass in the Presence of Hard- and Soft-Iron Interference - https://www.nxp.com/docs/en/application-note/AN4246.pdf Learn more: Maker.io - https://www.digikey.com/en/maker Digi-Key’s Blog – TheCircuit https://www.digikey.com/en/blog Connect with Digi-Key on Facebook https://www.facebook.com/digikey.electronics/ And follow us on Twitter https://twitter.com/digikey
Download
1 formatsVideo Formats
Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.