GlossaryMagnetometer
Magnetometer
A magnetometer is a sensor that measures the strength and direction of a magnetic field. On drones and robots, a three-axis magnetometer acts as an electronic compass, measuring Earth's magnetic field to estimate heading.
How it works
Most small magnetometers use magnetoresistive or Hall effect elements whose output changes with the field along each axis, and the device reports a 3D field vector. When the sensor is level, the horizontal part of that vector points toward magnetic north. With tilt known from an accelerometer, heading can be computed at any orientation. The angle between magnetic north and true north, called declination, varies by location and comes from models such as the World Magnetic Model.
The vehicle itself distorts the readings. Hard iron effects come from permanent magnets and magnetized steel and add a fixed offset. Soft iron effects come from ferrous materials that bend the field and stretch the readings. Calibration rotates the vehicle through many orientations and fits corrections for both. Currents in nearby wires also create fields, and those change with throttle.
Magnetometer vs IMU
An IMU measures acceleration and rotation rate. Integrating rotation rate gives heading, but small gyro errors accumulate into drift. A magnetometer gives an absolute heading reference that does not drift, but it is noisy and easily disturbed. Estimation filters combine the two: the gyro for short-term motion, the magnetometer to correct long-term drift.
Why it matters
Heading errors make drones fly in the wrong direction, circle when trying to hold position or fail preflight checks. Magnetic interference from power wiring is a classic cause, because it changes with motor current and cannot be removed by a one-time calibration.
How to get it right
- Mount the magnetometer away from power wires, motors, ESCs, batteries and steel parts, often on a GNSS mast.
- Twist high-current wire pairs so their fields cancel.
- Calibrate on the fully assembled vehicle, with every part in its final position.
- Use current-based compensation where the flight stack supports it.
- Fit more than one magnetometer and compare them to catch interference.
- Avoid ferrous screws, standoffs and brackets near the sensor.
Magnetometers in robotics and drone hardware
ArduPilot documentation treats compass placement and calibration as core setup steps, including compensation for motor current. On power-dense drones, the layout of the power distribution board, battery leads and ESC wiring decides how much interference reaches the compass. Indoor robots and ground robots near steel structures often give the magnetometer little weight and rely on other heading sources.