Welcome!

Think Labs is an ongoing effort by Seven2 to provide research and educational opportunities in the web development and mobile field. To see what we’ve been cookin’ up, check out our blog postings.

Created by
Seven2 Login

Categories
Tags
Team Think Labs | Get More Positive Feedback from Your Magnetometer
3654
single,single-post,postid-3654,single-format-standard,ajax_fade,page_not_loaded,,,wpb-js-composer js-comp-ver-4.2.3,vc_responsive
706px-Descartes_magnetic_field

Get More Positive Feedback from Your Magnetometer

Magnetometers
A magnetometer, is an instrument for measuring the strength and sometimes the direction of a magnetic field. This device was invented in 1832 by German mathematician and physical Carl Friedrich Gauss and later perfected by Nikola Tesla to measure rotating magnetic fields. These devices can be found in almost every smartphone.

706px-Descartes_magnetic_field
magnetic field, by René Descartes

 

Mobile Devices

Magnetometers are a very attractive item to have in a mobile device. Their most common use is measuring the Earth’s magnetic field, allowing a mobile device to act as a compass. Many devices use a vector magnetometer that are capable of measuring a magnetic field relative to a particular direction. Dip and azimuth are measured using three orthogonal magnetometers.

The iPhone 3GS has a magnetoresistive permalloy sensor magnetometer, the AN-203 produced by Honeywell. The device is able to detect magnetic fields less than 100 µgauss within a ±2 gauss range.

Magnetic Field Strengths:

10−9–10−8 gauss – the magnetic field of the human brain
0.31–0.58 gauss – the Earth’s magnetic field at its surface
25 gauss – the Earth’s magnetic field in its core
50 gauss – a typical refrigerator magnet
100 gauss – a small iron magnet
2000 gauss – a small neodymium-iron-boron (NIB) magnet
600-70,000 gauss – a medical magnetic resonance imaging machine
10^12–10^13 gauss – the surface of a neutron star
4×10^13 gauss – the quantum electrodynamic threshold
10^15 gauss – the magnetic field of some newly created magnetars
10^17 gauss – the upper limit to neutron star magnetism; no known object in the universe can generate a stronger magnetic field
Gaus Unit: http://en.wikipedia.org/wiki/Gauss_(unit)

Code
There are a variety of dev environments and libraries that can be used to development a mobile app. A popular dev environment, the iOS SDK, uses the Core Location framework to access the magnetometer. This library can get the current location or heading of a device. The framework is accessed through classes and protocols to configure and schedule the delivery of location and heading events, mainly CLLocationManager and CLHeading.

CLLocationManager
The CLLocationManager class defines the interface for configuring the delivery of location- and heading-related events to your application. An instance of CLLocationManager is used to establish when location and heading events should be delivered and to start and stop the actual delivery of those events.

CLHeading
One of the Location Manager’s events, didUpdateHeading, passes heading data via the object CLHeading. The heading data includes computed values for magnetic and true north. CLHeading.x,CLHeading.y and CLHeading.z return values measured in microteslas (1 gauss = 100 microtesla).

        
// heading service configuration
locationManager.headingFilter = kCLHeadingFilterNone;

// setup delegate callbacks
locationManager.delegate = self;

// start the compass
[locationManager startUpdatingHeading];
....

// This delegate method is invoked when the location manager has heading data.
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)heading {
...
float zHeading;
...
zHeading = heading.z;