Magnetometer placement — where and why

Magnetometer placement — where and why

In my last posting (Accelerometer placement — where and why [1]) I discussed tradeoffs to be considered when choosing where to locate an accelerometer in your design. THIS posting does the same thing, but for magnetometers. This posting also builds on topics previously discussed in Hard and soft iron magnetic compensation explained [2] as well as material presented at Design West 2012 [3].

For the purposes of this discussion, we’ll consider the following use model: magnetometer as the magnetic component in an electronic compass. In this case you desire to measure the earth’s magnetic magnetic field, which ranges from 25 to 65 microTeslas, depending upon your location upon the earth. This is a relatively weak field, and can easily be rendered unmeasurable unless you pay attention to magnetic issues during your system design. Magnetic sensors used for consumer and industrial applications have ranges much larger (>1000mT) than the earth field to be able to deal with hard and soft iron interference on the measured field.

In our context:

  • Soft iron includes ferrous EMI shielding, films for inductive chargers, screws, battery contacts, etc.
  • Hard iron elements are permanent magnets within speakers, proximity switches, vibrators, etc.
  • In addition, we may have magnetic fields resulting from speaker/motor windings, PCB traces, etc.

If you don’t have any of the above elements in your design, you can probably stop reading now. But unfortunately, most designs DO have to deal with these issues. Let’s start with general guidelines:

  1. Make the magnetometer placement the first step when outlining a new PCB layout.
  2. The ideal location for the magnetometer is for it to be as far away as possible from all sources of hard and soft interference and from high current traces.
  3. Time varying current traces cannot be mathematically compensated for, whereas you may be able to treat constant current traces as hard iron interference, which can be compensated for.
  4. The best locations are often to be found on an edge or at a corner of the PCB.
  5. Place any Hall effect sensor and its magnet as far away as possible from the magnetometer.
  6. Other electromagnetic components may include loudspeakers, vibrators, hearing aid coils, batteries and near field communication (NFC) antennas. These will create permanent hard iron, induced soft iron and current-sourced magnetic fields and should also be placed as far as possible from the magnetometer.
  7. Don’t attempt to shield the magnetometer from magnetic fields generated by components on the PCB. Remember, our goal is to measure the earth’s magnetic field. If you shield the sensor magnetically, you will destroy the very signal you are trying to measure.
  8. If shield cans are required to isolate sensitive sub-systems such as radios from each other, then they must be made from low permeability conductive materials1
  9. Industrial design and mechanical engineering teams should be involved at the start of any project involving a magnetometer. All mechanical components should be reviewed for their ferromagnetic content and replaced with low permeability alternatives.

Although we can mathematically compensate for many soft iron impacts, it’s still best to avoid them when we can. As an example, let’s consider the effects of a small piece of steel on the value of the magnetic field measured nearby. Assume 1″ by 1″ by 0.02″ thick steel as shown in Figure 1A below. If you were to look at that piece of steel from the side, you have the view shown in Figure 1B.

Figure 1: 1 inch by 1 inch by 0.02 inch steel shield
Figure 1C is the same edge view, but now we’ve added some information to specify simulation conditions. I use the excellent (and free!) FEMM 4.2 two dimensional finite element simulator by David Meeker [4] whenever I want to explore magnetostatic issues.

For our simulation, I assumed an earth’s magnetic field of approximately 40 microTeslas, which is free to rotate over a range of 0 to 180 degrees during the simulation. This is equivalent to holding the field static, and rotating the sensor (which is what happens in the real world). The red line in Figure 1C represents a range of points in which I’ll measure the magnetic field intensity for each of those variations in field direction. The results were extracted and summarized via Excel, and are shown in Figure 2 below.

Figure 2: Two Dimensional Finite Element Simulation Results
The results are pretty much what you expect:

  • Soft iron effects distort the magnetic field as a function of the angle between the ferrous material and the magnetic field. This results in an “envelope” of when you plot the magnitude of possible magnetic field values.
  • Significant field attenuation is possible either immediately above or below any magnetic shield. Don’t put your sensor there! The worst place to put your sensor is immediately above or below the center of a magnetic shield. This is easy to do if you are not paying attention. Shielding used for EMI may also be magnetic, or you may be including a film used for inductive charging in your design. Both can really screw up your chances for getting consistent magnetic readings.
  • Field lines tend to converge near the edges of ferrous materials. You see that here with the wide spread between max and min values in the envelope near the edge of the shield. If you go back to [2] and review our prior discussion on the elliptical distortion effects of soft iron on sensor readings, you will see that this spread of max and min field readings directly translates in more distortion being seen in the 3D ellipsoid of sensor readings. Magnetic compensation software can correct for much of this distortion, but as the ellipsoid becomes extreme, this correction will become less effective.
  • Finally, even a little distance between your sensor and the shield helps tremendously. You can see that the min/max ratio drops to less than 2 only 0.1 inches from the shield on both sides. This is fairly modest distortion, and should be easily correctable.

Next, let’s consider impacts on magnetic field resulting from wires and traces on your PCB. We can use the Biot-Savart law to estimate the effect of wire and trace currents on sensor readings. For long wires and traces, Biot-Savart can be simplified to:

|B| = µ0I / 2 π r (Equation 1)

  • B = magnetic field in Teslas (T)
  • µ0 = 4 π E-7 T*m/A
  • I = current in amps
  • r = distance from wire/trace to sensor in meters

This can be re-arranged to:

I <= 5 r |B| (Equation 2)

  • B = magnetic field in microTeslas (µT)
  • I = current in milliamps
  • r = distance from wire/trace to sensor in mm

If you know the field magnitude you can afford to ignore and the distance from your sensor to trace/wire, then you can use Equation 2 to calculate the maximum wire/trace current in mA.

As an example, let:

  • B = 0.1 microTeslas magnetic field
  • r = 10mm distance from sensor to wire/trace


I <= 5 r |B| = 5 X 10 X 0.1 = 5mA = maximum current allowed in the trace.
We can treat the DC component of this current as a hard iron offset (it looks like a magnet). AC components show up as “noise” in our sensor output.


By now, you should understand that adding a magnetic sensor to your design should be done early in the design cycle, and with careful consideration with respect to surrounding elements in the physical design. Do this, and your chances of being bitten by problems during product debug and evaluation will be greatly reduced.


  1. such as brass, beryllium-copper alloys, aluminum, nickel-silver alloys (such as 752 or 754), or even low permeability stainless steel alloys (such as SUS305 or SUS316). The aim is to combine low electrical resistance (to minimize electrical field leakage) with low magnetic permeability (to minimize induced soft iron fields). It is good practice to keep even low permeability shields a minimum of 7mm away from the magnetometer sensor.


  1. Accelerometer placement — where and why, The Embedded Beat, 2 August 2012
  2. Hard and soft iron magnetic compensation explained, The Embedded Beat, 14 March 2011
  3. Physical Design Considerations for Products Incorporating Inertial & Magnetic Sensors”, presented at “Sensors In Design 2012” at “Design West 2012”, Michael Stanley
  4. Free tool! Finite Element Method Magnetics, FEMM 4.2.
Michael Stanley
Michael Stanley
Mike Stanley develops advanced algorithms and applications for MCUs and sensors, including sensor fusion and sensor data analytics. He is a founding member of the MEMS Industry Group’s Accelerated Innovation Community and a contributor to the IEEE Standard for Sensor Performance Parameter Definitions (IEEE 2700-2014). He is co-author of a chapter on intelligent sensors in “Measurement, Instrumentation, and Sensors Handbook” (volume two), and speaks on sensor topics. When the Arizona temperature drops below 100 degrees, you'll find Mike flying his F450 quadcopter . Follow him @SensorFusion.

Comments are closed.

Buy now