Compass in Smartphones — Essence, Working Principle and Application

Author: IT Sectr Published: 2026-03-25 Reading time: 8 min

Compass in a smartphone is a digital sensor based on a magnetometer that determines the direction to the Earth’s magnetic poles. The technology allows navigation, mapping, and augmented reality applications to accurately determine the device’s orientation in space. According to STMicroelectronics, 2025, modern MEMS magnetometers provide accuracy of direction determination up to 1–2 degrees.

Key Takeaways

  • Compass in a smartphone is a digital compass based on a MEMS magnetometer that measures the Earth’s magnetic field.
  • Modern magnetometers use the Hall effect or magnetoresistive effect to determine the direction of the magnetic field.
  • Accurate operation of a digital compass requires calibration to compensate for parasitic magnetic fields from speakers and other components.
  • The smartphone magnetometer measures the magnetic field along three axes (X, Y, Z), allowing direction determination in any device orientation.
  • The digital compass is used in navigation applications, augmented reality, geolocation services, and astronomy programs.

What Is a Digital Compass in a Smartphone?

Digital compass in a smartphone is a sensor based on a magnetometer that measures the Earth’s magnetic field strength and determines the azimuth (angle relative to magnetic north). Unlike a mechanical compass, a digital compass uses microelectromechanical systems (MEMS) to detect the magnetic field. The magnetometer measures the field along three axes, allowing correct direction determination at any smartphone tilt.

How the Sensor Works

A modern MEMS magnetometer is a microchip measuring 2×2×1 mm, integrated into the smartphone body together with an accelerometer and gyroscope (as part of a 9-axis IMU). The sensor measures not only the direction but also the intensity of the Earth’s magnetic field (25–65 µT depending on latitude). The presence of metal objects and parasitic magnetic fields from speakers, vibration motor, and camera create distortions, so software correction of readings is necessary for accurate operation.

The first digital compasses in mobile phones appeared in 2009 with the release of the iPhone 3GS — the first smartphone with a built-in magnetometer. Today, magnetometers are installed in the vast majority of smartphones, including budget models. According to Yole Group, the MEMS magnetometer market for mobile devices exceeds 1.5 billion units per year, confirming the demand for this technology.

Working Principle of a Magnetometer

The core of a MEMS magnetometer is a sensing element that changes its electrical characteristics under the influence of an external magnetic field. Modern smartphones use the Hall effect or the magnetoresistive effect (AMR — Anisotropic Magneto-Resistance). The principle is based on the fact that a current-carrying material changes its resistance when exposed to a magnetic field, and the magnetic field vector is calculated from the voltage change.

Hall Effect and AMR

Hall effect sensors detect voltage changes at the edges of a semiconductor plate caused by the Lorentz force acting on moving charges. Magnetoresistive sensors (AMR) use a permalloy (NiFe) film whose resistance depends on the direction of the magnetic field. AMR sensors provide smaller size and higher sensitivity compared to Hall sensors, which is why they dominate in modern smartphones.

TypeSensitivityPower ConsumptionSize
HallMediumLowMedium
AMRHighLowSmall
GMRVery HighMediumSmall

Magnetometer data is combined with accelerometer readings to correct tilt and determine the north direction in the horizontal plane. The sensor fusion algorithm uses the Madgwick filter or Kalman filter to combine data from the magnetometer, gyroscope, and accelerometer. This provides a stable and accurate azimuth even during fast rotations and device shaking.

Types of Magnetometers in Mobile Devices

Three main types of MEMS magnetometers are used in the mobile industry: Hall effect, anisotropic magnetoresistive (AMR), and giant magnetoresistive (GMR). AMR magnetometers are the most widely used in smartphones due to their optimal balance of sensitivity, power consumption, and cost. Leading manufacturers include AKM (Asahi Kasei Microdevices), STMicroelectronics, and Bosch Sensortec.

The sensitivity of an AMR magnetometer in a typical smartphone is 0.3–1 µT with a dynamic range of ±1000 µT (±8 Gauss), which is sufficient for accurately measuring the Earth’s field (30–65 µT) and compensating for parasitic fields. The sensor sampling rate can reach 100–200 Hz, but most applications use 10–50 Hz to save energy. Automatic compensation for temperature and housing stress deformations is implemented at the sensor driver level.

Digital Compass Calibration

Compass calibration is the process of compensating for parasitic magnetic fields created by smartphone components: speakers, vibration motor, camera, and battery. Without calibration, magnetometer readings can deviate from the true direction by 10–30 degrees. The calibration system determines the offset matrix (hard-iron bias) along three axes and applies it to correct all subsequent measurements.

Calibration Algorithms and Methods

The standard compass calibration method is drawing a “figure 8”: the user rotates the smartphone along a trajectory resembling the digit 8. During movement, the sensor records the magnetic field in all possible orientations, and the algorithm accumulates points and approximates a sphere with a center offset from zero. The sphere radius corresponds to the Earth’s magnetic field magnitude, and the center represents the parasitic offset vector. After approximation, the system calculates correction coefficients for each axis.

Modern calibration algorithms from Qualcomm and MediaTek perform continuous background calibration without user intervention. They analyze magnetic field changes during device rotations and automatically update correction parameters. If the sensor detects a new parasitic field (e.g., when attaching a magnetic case), the system initiates recalibration within 1–2 seconds of continuous device movement.

Compass Usage in Mobile Applications

Digital compass is used in a wide range of mobile applications. The primary use is in navigation and mapping services (Google Maps, Yandex.Maps, 2GIS), which determine the device’s orientation on the map to correctly display the user’s direction of travel. In augmented reality (AR) applications, the compass ensures correct placement of virtual objects relative to cardinal directions.

In astronomy applications (Star Walk, SkySafari), the compass combined with an accelerometer determines the direction the smartphone is pointing and shows the corresponding area of the night sky. Fishing and tourism apps use the compass to mark points of interest on the map with azimuth reference. GPS fitness tracking uses compass readings to determine running or cycling direction, improving route display accuracy.

Using the Compass via Android API

To access the digital compass on Android, the TYPE_MAGNETIC_FIELD sensor from the Sensor API is used. Developers register a listener for magnetometer reading changes and receive an array of magnetic field strength values along three axes in microteslas. To determine the azimuth, magnetometer data is combined with accelerometer data through a rotation matrix using sensor fusion.

kotlin
import android.hardware.Sensor
import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager

class CompassManager(
    private val sensorManager: SensorManager
) : SensorEventListener {

    private val magnetometer = FloatArray(3)
    private val accelerometer = FloatArray(3)
    private val rotationMatrix = FloatArray(9)
    private val orientation = FloatArray(3)

    override fun onSensorChanged(event: SensorEvent) {
        if (event.sensor.type == Sensor.TYPE_MAGNETIC_FIELD) {
            event.values.copyInto(magnetometer)
        } else if (event.sensor.type == Sensor.TYPE_ACCELEROMETER) {
            event.values.copyInto(accelerometer)
        }
        
        SensorManager.getRotationMatrix(
            rotationMatrix, null,
            accelerometer, magnetometer
        )
        SensorManager.getOrientation(rotationMatrix, orientation)
        
        val azimuth = Math.toDegrees(orientation[0].toDouble())
        // azimuth: 0 = north, 90 = east, 180 = south, 270 = west
    }

    fun start() {
        sensorManager.registerListener(this,
            sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
            SensorManager.SENSOR_DELAY_UI)
        sensorManager.registerListener(this,
            sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
            SensorManager.SENSOR_DELAY_UI)
    }

    override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) {}
}

The azimuth obtained through getOrientation is measured in radians and can take values from -π to π, where 0 corresponds to magnetic north. For on-screen display, values are converted to degrees (Math.toDegrees) normalized to the 0–360 range. It is important to account for magnetic declination — the angle between magnetic and true (geographic) north, which depends on geographic location and changes over time. Google Maps automatically adjusts declination through the GeomagneticField API.

Frequently Asked Questions

How does a digital compass work in a smartphone?

Digital compass uses a MEMS magnetometer — a 2×2 mm chip that measures the Earth’s magnetic field along three axes. Magnetometer data is combined with accelerometer readings to determine the azimuth — the angle between the north direction and the device’s orientation.

Why does the compass on my phone show the wrong direction?

Incorrect compass readings are most often caused by lack of calibration, magnetic interference from speakers or vibration motor, as well as magnetic cases. The solution is to perform a “figure 8” calibration movement or remove magnetic accessories. For persistent errors, sensor inspection may be required.

Does the compass need calibration and how do I do it?

Yes, compass calibration is necessary to compensate for parasitic magnetic fields inside the smartphone. In most modern devices, calibration is performed automatically in the background. For manual calibration, draw a “figure 8” with your smartphone in the air — the system will collect data from all angles and correct the readings.

How do I access the compass in an Android application?

On Android, compass access is provided through the Sensor API with the TYPE_MAGNETIC_FIELD sensor. The azimuth is calculated via SensorManager.getRotationMatrix() and getOrientation(), combining magnetometer and accelerometer data. The resulting azimuth can be adapted for on-screen display.

Which smartphone models have the most accurate compass?

The most accurate compasses are installed in smartphones with a triple IMU sensor (magnetometer + gyroscope + accelerometer) and an active calibration system. Leaders include flagship Google Pixel, Samsung Galaxy S-series, and iPhone Pro models — they use AKM and Bosch magnetometers with 0.3 µT sensitivity and automatic correction.

Summary

  • Compass (digital compass) in a smartphone is a MEMS magnetometer that measures the Earth’s magnetic field to determine the azimuth and device orientation.
  • Modern magnetometers use the AMR effect (anisotropic magnetoresistance), providing 0.3 µT sensitivity and a compact 2×2 mm size.
  • Accurate compass readings require calibration to compensate for magnetic fields from smartphone speakers, vibration motor, and camera.
  • The direction to north is calculated through sensor fusion — combining magnetometer data with accelerometer and gyroscope for tilt correction.
  • The digital compass is used in navigation, mapping, augmented reality, astronomy, and fitness tracking to determine orientation and direction of movement.
  • On Android, compass access is provided through TYPE_MAGNETIC_FIELD with azimuth calculation via getRotationMatrix and getOrientation.
  • Magnetic declination (the angle between magnetic and geographic north) is automatically corrected in navigation APIs from Google and Apple.

We will develop a mobile application turnkey

IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.

Discuss the project

Read also