Chapter 5. Using the Magnetometer

The magnetometer is a magnetoresistive permalloy sensor found in the iPhone 3GS, iPhone 4 and iPad 2, in addition to the accelerometer. The iPhone 3GS uses the AN-203 integrated circuit produced by Honeywell, while the iPhone 4 and iPad 2 make use of the newer AKM8975 produced by AKM Semiconductor. The sensor is located towards the top right hand corner of the device, and measures fields within a ±2 gauss (200 microtesla) range, and is sensitive to magnetic fields of less than 100 microgauss (0.01 microtesla).


The Earth’s magnetic field is roughly 0.6 gauss (60 microtesla). The field around a rare earth magnet can be 14,000 gauss or more.

The magnetometer measures the strength of the magnetic field surrounding the device. In the absence of any strong local fields, these measurements will be of the ambient magnetic field of the Earth, allowing the device to determine its “heading” with respect to the geomagnetic North Pole and act as a digital compass. The geomagnetic heading and true heading relative to the geographical North Pole can vary widely, by several tens of degrees depending on your location.

About the Magnetometer

Combining the heading (yaw) information (see Figure 5-1) returned by this device with the roll and pitch information returned by the accelerometer will let you determine the true orientation of the device in real time.

Using the magnetometer (a.k.a. the digital compass) in the iPhone 3GS you can determine the heading (yaw) of the device

Figure 5-1. Using ...

Get Basic Sensors in iOS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.