Selected Sensor Insights

A small but remarkable component in modern smart devices is the geomagnetic sensor, also known as an electronic compass. Whenever we use mobile maps, that “digital pointer” that always points north relies on it. In this article, we will explore the principles of geomagnetic sensors, the secrets of their integration with inertial sensors, and their applications and new trends across various fields in an easy-to-understand manner.

Basic Principles of Geomagnetic Sensors

Earth’s Magnetic Field and Direction Measurement: The Earth is surrounded by a vast magnetic field, commonly referred to as the geomagnetic field. An electronic compass determines direction by detecting the Earth’s magnetic field, hence it is also called a digital compass. Traditional compasses use a magnetic needle to point to geomagnetic north, while electronic compasses utilize physical phenomena such as the Hall effect or magnetoresistance to convert the geomagnetic field into electrical signals, which are then processed to calculate the azimuth angle. The Hall effect can be simply understood as follows: when an electric current passes through a conductor, a perpendicular magnetic field will push the flowing electrons to one side, generating a measurable voltage; the magnetoresistance effect refers to the change in resistance of certain materials under the influence of a magnetic field, where the stronger the magnetic field or the change in direction, the more the conductivity of the material changes. Geomagnetic sensors utilize these effects to “sense” the presence of the magnetic field.

Three-Axis Measurement and Azimuth Calculation: A typical electronic compass is equipped with three orthogonal magnetic sensors that measure the magnetic field strength along the device’s X, Y, and Z axes. This is akin to placing three small antennas inside the device, each sensing the magnetic field components in the east-west, north-south, and vertical directions. When the device is kept level, the azimuth angle can be calculated using the readings from the two horizontal axes (usually corresponding to the magnetic sensor’s X and Y axes) through a simple formula. For example, in a horizontal state, the azimuth angle can typically be derived from θ = arctan2(Y, X), where θ represents the angle between the device’s orientation and magnetic north. In other words, if we align the device’s X-axis to true north, the Y-axis reading will be zero; as the device rotates, the magnetic field values of the X and Y axes change, and the arctangent of the two axes’ data can be used to determine the current direction, such as northeast or southwest.

Inclination Effects and Compensation: However, in the real world, devices are often not perfectly level. The Earth’s magnetic field is not entirely horizontal; it has a certain angle of inclination (magnetic dip angle) at different latitudes, and geomagnetic north deviates from geographic north (magnetic declination). Therefore, when the compass is tilted, the vertical component of the geomagnetic field (Z-axis) will project onto the horizontal plane, interfering with the azimuth calculation and causing errors in the compass readings. To address this attitude coupling issue, three-dimensional electronic compasses typically incorporate tilt sensors (usually using accelerometers) to detect the device’s pitch and roll angles, compensating the magnetic sensor readings for tilt. In simple terms, this means using the accelerometer to sense the device’s angle relative to the horizontal plane, then “pulling back” the magnetic field vector to the horizontal plane before calculating the azimuth. With tilt compensation, even if the compass is tilted, the calculated heading remains accurate. This combination of magnetic and tilt angles allows electronic compasses to no longer require a level position during use, greatly enhancing practicality.

Sensor Sensitivity: Geomagnetic sensors need to possess extremely high sensitivity. The Earth’s magnetic field strength ranges from approximately 0.3-0.6 Gauss (3060 microteslas), varying by region. The sensor must be able to discern minute changes in the magnetic field. For instance, a typical magnetoresistive magnetometer has a measurement range of around ±2 Gauss and uses a high-resolution ADC to detect changes of less than 1 milligauss. This means it can “detect” minute fluctuations in the Earth’s magnetic field down to one-thousandth. Such high precision is achieved through advanced materials and processes—from Hall elements to anisotropic magnetoresistance (AMR) alloys, to tunnel magnetoresistance (TMR) technology, each technology route has its trade-offs in sensitivity and power consumption. For example, AMR magnetic sensors are more sensitive and consume less power than Hall sensors, making them widely used in electronic compasses. The next generation of magnetic sensors (such as magnetoresistive sensors MI) can be four orders of magnitude more sensitive than Hall sensors, capable of measuring extremely weak magnetic field changes, making them ideal for ultra-low power applications such as orientation detection, indoor positioning, and metal object detection.

Integration with Six-Axis IMU to Form a Nine-Axis Navigation System

Role in Inertial Navigation: An electronic compass can provide an absolute heading reference solely based on the magnetometer, but it cannot obtain complete attitude information such as pitch and roll; conversely, a six-axis IMU (which includes accelerometers and gyroscopes) can measure changes in three-dimensional attitude angles but lacks a stable long-term directional reference. By integrating a three-axis magnetometer with a six-axis IMU, a nine-axis inertial measurement unit can be formed, balancing dynamic response and absolute directional reference to construct a complete attitude heading reference system (AHRS). In this nine-axis system: the accelerometer senses the direction of gravity for short-term horizontal reference, the gyroscope senses rapid rotational motion but may have zero drift errors, while the magnetometer provides a heading reference to correct drift. The three sensors fuse their data, leveraging each other’s strengths to calculate the device’s heading angle, pitch angle, roll angle, and other attitude information in real-time relative to the geographic coordinate system. This fusion allows the advantages of the sensors to compensate for each other—some have likened it to a sprinter (the gyroscope) who can quickly capture rotation but tires easily; a weightlifter (the accelerometer) who provides long-term reference but moves slowly; and a reliable compass (the magnetometer) that points to absolute direction. By binding the three together, we achieve both sensitive and robust attitude perception capabilities.

Heading Stability and Correction: Specifically, in the nine-axis fusion algorithm, the magnetometer’s most important role is to provide heading correction. Since the accelerometer cannot sense rotation around the vertical axis (yaw), the gyroscope can measure yaw angular velocity but its integration over time will drift, causing the device’s direction to become “disoriented” over time. At this point, the magnetometer acts as a tireless “north pointer” for the system. Fusion algorithms (such as Kalman filtering, complementary filtering, etc.) continuously compare the heading calculated by the gyroscope with the magnetic north direction measured by the magnetometer, gradually correcting the deviation between the two, thus eliminating the gyroscope’s accumulated errors. As a result, regardless of how long the device is used, its orientation can remain anchored to the geographic direction without drifting over time. This is crucial for navigation and attitude control—imagine a drone hovering in the air; without the absolute directional reference provided by the electronic compass, relying solely on the gyroscope, its nose may have long lost its orientation after a while, making it difficult to maintain a stable hover.

Significance of Data Fusion: In practical applications, sensor data fusion technology has become key to enhancing user experience. Smartphones, wearable devices, VR headsets, and even robotic vacuum cleaners all require devices to smoothly and accurately perceive their orientation and adapt to environmental changes. This necessitates the use of fusion algorithms involving accelerometers, gyroscopes, and magnetometers to provide precise attitude (pitch, roll) and heading information. The fused nine-axis navigation system is widely used in aircraft navigation, smartphone attitude sensing, game control, and other scenarios: for example, in smartphones, the combination of nine-axis sensors allows map applications to rotate the map’s orientation in real-time as you turn; drone flight control utilizes nine-axis data to achieve autonomous hovering and heading maintenance; VR devices ensure that the viewpoint does not drift over time through fusion algorithms. In summary, the emergence of nine-axis IMUs has endowed machines with the ability of “spatial perception,” its importance is as indispensable as humans relying on the vestibular system and visual references to maintain a sense of direction.

Application Scenarios: From Smartphone Compasses to Drone Navigation

Smartphones: Almost all smartphones are equipped with electronic compasses to provide directional sensing for maps and augmented reality. When we take out our phones for navigation at an intersection, the compass sensor immediately informs the application of our phone’s orientation, allowing it to display a directional arrow on the map, preventing us from “turning around in circles trying to find north.” Even when the phone is stationary, the compass can accurately display the orientation without needing to wait for movement like pure GPS. Additionally, some smartphone apps have transformed the magnetometer into a metal detector: for instance, when the phone is near ferromagnetic metals like nails or rebar, the sensor readings will change abnormally, allowing for the detection of hidden metal objects (there are applications on the market that use smartphone magnetic sensors to locate electrical wires within walls).

Drone Heading Maintenance: The autopilot of drones heavily relies on electronic compasses to provide real-time heading information. GPS can tell the drone where it is, but only the compass can tell it where its nose is pointing. During flight, the gyroscope’s heading may drift slightly over time; without compass correction, the drone may slowly deviate from its intended heading after hovering for a long time. Navigation modules equipped with compasses allow drones to clearly understand their orientation whether in rapid maneuvers or hovering. For example, when performing aerial photography tasks, the flight control can accurately adjust the gimbal and body orientation based on compass information, ensuring the lens always points at the target to capture the desired image. The compass is also crucial for drone return—combined with GPS, it can guide the drone’s nose back to the starting point, executing precise “one-click return” commands.

Automotive Navigation and GPS Assistance: Many in-car navigation devices and high-end GPS modules incorporate electronic compasses to enhance the navigation experience. Purely relying on GPS signals for navigation cannot determine the vehicle’s heading when it is stationary; it can only estimate direction based on positional changes after the vehicle moves, which can lead to unclear map orientation or even incorrect directions when starting. Navigation devices with compasses can instantly display the vehicle’s direction even when stopped at a red light, allowing drivers to clearly understand their facing direction. Moreover, in tunnels or urban canyons where GPS signals may be temporarily lost, inertial navigation systems combined with electronic compasses can continuously provide short-term heading and position estimates, smoothly transitioning through signal interruption periods and avoiding sudden navigation disruptions.

Metal Detection and Security: In addition to small-scale metal detection with smartphones, small magnetic sensors are also used in professional handheld metal detection devices or security gates. Larger-scale magnetometers are applied in geological and archaeological fields to detect buried metal objects or ferromagnetic anomalies. For example, archaeologists use high-sensitivity magnetometers to scan the ground, discovering hidden ancient kilns, city walls, etc. (as these relics contain magnetic materials that disturb the local magnetic field); in security systems, magnetic sensors can be used as electronic fences or virtual walls, such as some robotic vacuum cleaners laying magnetic strips at the edges of carpets, where the built-in compass detects changes in the magnetic field to determine that the area ahead is off-limits. Geological exploration: In mineral resource exploration and geophysical surveys, magnetic measurement is an important method. Geologists deploy magnetometers on the ground or in the air to map the subtle changes in magnetic field strength, identifying underground ore bodies or geological structures. Since certain ores (like iron deposits) significantly affect the local magnetic field, magnetic anomalies often indicate potential mineral deposits. This method is cost-effective and efficient, capable of quickly locating mineral veins or fault structures over vast areas, making it one of the most widely used geophysical exploration methods. Besides minerals, magnetic exploration is also used for non-destructive archaeological detection (locating buried relics) and environmental surveys (detecting underground steel pipes, waste, etc.). It can be said that from searching for buried treasures to monitoring crustal structures, magnetic sensing technology is an unsung hero that plays an indispensable role.

Introduction to Common Chips

Honeywell HMC5883L: This is a classic three-axis magnetometer chip produced by Honeywell, utilizing anisotropic magnetoresistance (AMR) technology, compact in size, and featuring an I²C interface. The HMC5883L has a range of ±8 Gauss and a resolution of 5 milliGauss/LSB. Due to its stability and reliability, it has been widely used in early smartphones, drone flight control, and Arduino electronic compass modules. It includes temperature compensation and self-test functions, maintaining calibration accuracy in harsh environments, making it a preferred device for many developers starting with electronic compasses.

AKM AK8975: Japan’s Asahi Kasei Microdevices (AKM) is a giant in the smartphone electronic compass field, with a significant proportion of magnetic sensors in smartphones being AKM products, such as the AK8973 and AK8975 series. The AK8975 is a three-axis digital magnetic sensor based on the Hall effect, characterized by low power consumption and high resolution, widely found in Android smartphones and early iPhone models. It supports I²C communication, directly outputting the three-axis magnetic field strength to the application processor, enabling smartphones to easily implement compass functions. AKM’s electronic compass solutions are compact and easy to calibrate, having once dominated the smartphone compass market.

ST LSM303 Series: STMicroelectronics (ST) has launched the LSM303DLH and other series modules, integrating “three-axis magnetometer + three-axis accelerometer” into a single chip, pioneering combination sensors. This 6 DoF combination allows the magnetic sensor and accelerometer to be in the same coordinate system, facilitating the implementation of tilt compensation for electronic compasses. Designers using this module can quickly create low-cost, high-performance electronic compass solutions. The LSM303 series comes with attitude calculation examples and is applied in various devices such as smartphones and model aircraft flight control, reflecting the trend of miniaturization in sensor fusion.

Bosch BMM150/BMM350: Bosch’s BMM150 is a highly integrated MEMS three-axis magnetometer, used in numerous wearable devices and smartphones due to its low power consumption and robust performance. In 2023, Bosch released the more powerful BMM350, claiming higher resolution and anti-interference capabilities, optimized for applications such as AR/VR head tracking and indoor navigation. These chips are based on Hall or magnetoresistive technology and incorporate Bosch’s proprietary self-calibration algorithms, providing the precision and stability required for consumer applications while maintaining a compact size.

TDK InvenSense Series: TDK has deeply integrated magnetometers with inertial sensors, launching nine-axis sensors like the ICM-20948 (which includes a magnetometer) and the latest dual-chip 9DoF solutions, providing positioning and navigation-level accuracy by integrating six-axis IMUs and three-axis TMR magnetometers. Additionally, its subsidiary iSentek has developed the IST8308/8320 magnetometers, featuring a wide range of up to ±10 milliTesla and advanced offset compensation technology, allowing them to function normally in strong magnetic interference environments. This addresses the interference issues caused by numerous magnetic components (such as speaker magnets, wireless charging coils, etc.) within modern smartphones. As sensor technology evolves, new chips continuously set industry benchmarks in sensitivity, temperature drift, and dynamic range, ensuring that electronic compasses remain reliable in more complex environments.

Calibration and Interference Compensation of Geomagnetic Sensors

Hard Iron Interference: Hard iron interference refers to the presence of permanent magnets or magnetic materials within or around the device, creating a constant magnetic field offset. For example, the speaker magnets and headphone magnets in a phone can cause fixed deviations in compass readings. This interference manifests as an overall shift in magnetic field readings, causing the sensor output’s “circle” to deviate from the origin. The solution is to perform offset calibration during manufacturing or usage: rotating the device around each axis to measure the maximum and minimum magnetic field values, calculating the offsets for the X, Y, and Z axes, and subtracting them. Many smartphones prompt users to perform an “8-shaped rotation” to eliminate hard iron offsets. Engineers in the design phase also use Helmholtz coils and other equipment to record the sensor’s original offset in the absence of external magnetic fields, generating what is known as a “hard iron compensation vector,” which is burned into the compass driver for permanent compensation. After proper compensation, the center of the magnetic field output should return to near the coordinate origin.

Soft Iron Interference: Soft iron interference comes from non-magnetic materials that distort external magnetic fields, such as iron casings, screws in phones, or surrounding iron door frames and steel furniture. Soft iron materials become magnetized in a magnetic field, altering the direction and magnitude of the local magnetic field, causing the magnetometer output to deform (typically, the output trajectory that should be circular becomes elliptical). The challenge with soft iron effects is that their influence depends on the orientation of the material relative to the sensor; as the device’s attitude changes, the interference also changes. Compensating for soft iron interference usually requires more complex elliptical calibration: obtaining a large number of magnetic field data points in various directions, using algorithms to fit an eccentric ellipsoid, and then normalizing it to an ideal unit circle. This process can be completed at the factory (for example, using a rotating platform to measure and generate a soft iron compensation matrix SIC, which is used in software to correct sensor output) or can be adjusted in real-time by the user through software (some device firmware continuously collects magnetic field data for self-learning calibration during regular use). After ideal calibration, regardless of the presence of any soft magnetic materials around the device, the compass readings can be stretched and translated in all directions to ensure accuracy.

Attitude Coupling Errors: As mentioned earlier, tilting the compass introduces attitude coupling errors—the pitch and roll of the device cause changes in the projection of magnetic field components, leading to incorrect heading calculations. Without compensation, a compass tilted at 45° will output a “north” needle that deviates from true north even if its orientation remains unchanged. The remedy for this is to combine the accelerometer for tilt correction. Modern electronic compasses use sensor fusion algorithms to first transform the three-axis magnetic field values using the tilt angle measured by the accelerometer into equivalent X and Y values in a horizontal attitude before calculating the azimuth. Therefore, it is essential to ensure that the accelerometer and magnetometer are aligned and calibrated before system use; otherwise, inconsistencies in their coordinate systems can introduce new errors. Some high-precision compasses also consider the impact of temperature drift on tilt angles and magnetic declination, providing temperature compensation to maintain stable pointing in various environments.

User Calibration and Intelligent Compensation: For consumer devices, compass calibration is usually semi-automated or automated. Many smartphones prompt users to perform an “8-shaped movement” when detecting abnormal magnetic fields, which is intended to correct both hard iron and soft iron errors. New algorithms attempt hands-free calibration: utilizing various natural movements of the user (walking, picking up and putting down the phone, etc.) to collect multi-directional magnetic field data for automatic calibration. For instance, Xiaomi has patented a method that uses the internal sensors of the phone to determine when it is in a valid calibration motion, thus quietly completing compass calibration without user awareness. Additionally, application layers will filter and assess the reliability of compass data—when detecting abnormal spikes (such as suddenly approaching a large iron plate), the navigation program may temporarily distrust the magnetometer and switch to gyroscope integration until the environmental magnetic interference passes before switching back. It can be said that a series of hardware and software collaborations ensure that electronic compasses remain reliable in complex real-world environments: whether in a pocket smartphone or a speeding drone, their compasses continuously self-correct and “fight” against interference to consistently guide the correct direction.

Applications of Geomagnetism in Indoor Positioning, AR/VR, and Smart Wearables Trends

Indoor Positioning Navigation: In indoor environments, GPS signals are often weak or absent, leading to the emergence of technologies that combine geomagnetic field characteristics for positioning. Large buildings, due to their steel structures, create unique “fingerprint” distributions of the geomagnetic field throughout their interiors. Startups like IndoorAtlas utilize smartphone magnetometers to scan the magnetic field anomaly maps within buildings, then match these magnetic maps with real-time magnetic field readings during navigation to infer the user’s location. This geomagnetic fingerprint positioning holds promise for indoor navigation in large shopping malls, airports, etc., without relying on GPS. Of course, magnetic positioning typically needs to be combined with other methods such as Wi-Fi and Bluetooth to improve accuracy. Even without precise positioning, electronic compasses can still play a role indoors: for example, in navigation apps within shopping malls, the compass can instantly provide direction, allowing users to see which way they are facing even while standing still, greatly enhancing the navigation experience.

Augmented Reality (AR) / Virtual Reality (VR): In the AR/VR field, orientation tracking is one of the key technologies determining immersion. Whether in mobile AR applications or head-mounted VR devices, continuous perception of the user’s head or device orientation is essential. Due to the drift issues of pure gyroscopes, prolonged use of VR often leads to a slow drift in perspective, causing the visuals to misalign with the real direction, resulting in dizziness and discomfort. To avoid this situation, AR/VR devices typically incorporate magnetometers to provide absolute orientation calibration. The magnetometer acts like adding a “digital horizon” and a “virtual north star” to the virtual world, ensuring that the device has reference coordinates in any state. When users wear VR headsets and remain still, the magnetometer can prevent the visuals from drifting; during slow movements, it can also correct the position and attitude errors generated by the double integration of the accelerometer. Furthermore, future AR glasses and MR devices may utilize geomagnetic fields to interact with the environment, achieving spatial anchoring (for example, placing virtual furniture according to real orientation, sharing aligned coordinate systems among multiple devices, etc.). It is worth noting that the application of geomagnetic sensors in AR/VR imposes higher performance requirements—requiring faster output rates, higher resolutions, and anti-interference capabilities. Manufacturers are also launching specialized models to meet these demands, such as some new magnetometers claiming to be suitable for head direction tracking, ensuring orientation accuracy at the 0.1° level, indicating that geomagnetic technology is becoming an indispensable foundational support in the era of the metaverse.

Smart Wearable Devices: From smartwatches to fitness bands, and emerging outdoor adventure devices, geomagnetic sensors have significant applications in the wearable field. Smartwatches typically incorporate electronic compasses to provide compass functions, helping users determine direction while hiking or climbing. For example, the compass application on the Apple Watch can display the current orientation in degrees and direction, and it can achieve real-time orientation calibration in conjunction with maps, making it popular among outdoor enthusiasts. For watches that support map navigation, the compass can also provide orientation references when GPS signals are weak. In sports tracking, magnetometers work alongside accelerometers and gyroscopes to participate in gait analysis and posture recognition, such as helping to determine changes in a runner’s orientation and accurately record route directions. Special wearables like positioning insoles and guide devices can also utilize geomagnetic sensing for orientation perception. In security monitoring, some wearable cameras with compasses can record the orientation data of the camera during shooting, facilitating the restoration of the shooting angle on maps later. Overall, as wearable devices become increasingly miniaturized and multifunctional, compact yet information-rich geomagnetic sensors have become the “secret weapon” for these devices to achieve spatial perception.

The development history of geomagnetic sensors reflects humanity’s continuous efforts to enhance its “sense of direction.” From the initial magnetic needles in maritime compasses that resisted swaying to today’s smart compasses embedded in smartphones, drones, and AR glasses, we have not only miniaturized the compass into a chip but also endowed machines with the intuition to explore space. In the future, as quantum magnetometers and superconducting magnetic sensing technologies become practical, the sensitivity and application boundaries of geomagnetic sensors will continue to be refreshed. Whether we are in the wilderness, the city, or the virtual world, those invisible geomagnetic field lines are always there, and the electronic compass, our silent guide, will continue to point the way, enabling technological devices to better perceive this magnetic field-filled world.

Leave a Comment