Electronic – How to determine the distance from a magnet using Magnetometer

distancemagneticsmagnetometer

I have a triple-axis magnetometer and a magnet, and I am trying to calculate the relative position of the magnet from the magnetometer.

The magnetometer outputs the strength of any fields detected in each of the (X,Y,Z) directions, and I understand that I'll have to compensate for the Earth's own field, as well as how to determine the relative location of the magnet, but what I do not understand is how to determine the distance that the magnet is from the magnetometer.

So my question is: assuming that I have a magnetometer pointed exactly straight towards a magnet, and the magnetometer is outputting the field strength, is there an equation that I can use to determine the distance that they are apart?

I have attempted doing some research into this, but all the results I am finding vary from one another incredibly. Any help/advice would be much appreciated.

Edit 1: I feel like I should note that I'm using a cylindrical magnet. Would the calculations be different if I were to use a rectangular one?

Best Answer

No, you can't derive the distance to a magnet from a single field strength measurement without knowing the strength of the magnet.

However, you can derive distance from two readings at different distances from the magnet. Magnetic field strength falls off with the square of the distance. By moving a small and known amount towards or away from the magnet, you can calculate the distance to the magnet by how much the field strength changed over the know distance between the two measurements.

For example, if you moved 1 m closer to a magnet and the field strength quadrupled, then the magnet must have been 2 m away from the original measuring point. If the field strength only doubled, then you moved 1/sqrt(2) closer to the magnet. The 1 m closer was therefore .29 of the distance to the magnet, which means the magnet was 3.4 m from the original measurement.