Measuring neodymium magnet strength with magnetometer sensor in phone

I try to measure neodymium magnet magnetic field strength, exactly - how it depends on distance to magnet, by using integrated magnetometer sensor in Huawei phone. My setup is like :

Then I move neodymium magnet as pictured - horizontally along ruler, and measure dropping magnetic field intensity with app "Magnetic Field Sensor". Because magnetic field has dipole nature - I was expected to get field dropping $$\propto r^{-3}$$ relationship to distance. But to my surprise, that was not the case. For bigger distances what I've got is relationship $$\boxed {\propto r^{-1.5}}$$ with a very good fit,- coefficient of determination $$R^2 = 0.99$$. Results are neither $$r^{-2}$$ as in monopole fields, nor $$r^{-3}$$ as in dipole fields. So there must be some error in measuring magnetic field strength. Here comes the question - What possible reasons of this measurement error can be :

• Problems in Huawei magnetic field sensor. (Was designed to measure Earth magnetic field, so neodymium magnetic field somehow is distorted by Earth magnetic field readings in the sensor ??)
• Problems in a measuring app "Magnetic Field Sensor" - incorrectly interpolates/extrapolates sensor data, rounding issues, bugs, etc...
• Both of these two above ?
• Anything else which I have not thought about.

Any ideas ?

EDIT

Here is my measurement data requested :

distance (mm) / Field (μT) (A case) / Field (μT) (B case)
0   1025    478
2   918     436
4   734     399
6   539     344
8   403     293
10  308     239
12  242     198
14  209     164
16  170     130
18  141     109
20  122     106
22  103     88
24  90      79
26  79      68
28  70      61
30  63      53


B case was measured field strength by sliding magnet along vertical axis close to phone (perpendicularly to the one shown in picture). Amazingly, sliding magnet vertically, at bigger distances, relationship stays the same $$r^{-1.5}$$

• Do you think you could include your data if it's not too difficult? Also, I'm guessing you plotted a log-log graph to get the exponent? How many points did you have? – Philip Jan 7 at 20:06
• measurement data included, graph is plotted starting from a distance of 14 mm, because at close distances is total chaos, and exponent is fluctuating about $-1$. No, it's not a logarithmic scale - ordinary ones. Seems like field strength does not want to drop at all. Maybe Huawei phone has integrated magnet inside, which is affecting the readings or something ? – Agnius Vasiliauskas Jan 7 at 20:19
• What is your phone model? – Ruslan Jan 7 at 21:46
• Huawei P30 Pro model – Agnius Vasiliauskas Jan 7 at 22:15

Your data cannot fit your proposd equation. It should become infinite at r=0 and your data dooes not behave like this. Obviously what you call r=0 does not correspeond to a sensor at zero distance from the field source. Whatever that means.

If I try a dependence of (r+18)^x I get x=3 with R2=0.997 where r and 18 are in mm. Other exponents give good fits too, depending on what origin you choose.

Edit

It looks like your magnet is cubic. Here is the formula some manufacturer gives for the field of their cubic magnet: https://www.supermagnete.de/eng/faq/How-do-you-calculate-the-magnetic-flux-density#formula-for-block-magnet-flux-density As you can see, it's nothing like the simple dipole formula. And this is only for the field along the z axis. Now I can expect that if you expand the arctangents in series and look at z much larger than the dimensions of the cube you may get some inverse cube dependence (I did not try it).
But if your sensor is off-axis then the dependence becomes more comlicated. Even for simple dipole, the proportionality constant in the B versus 1/$$r^3$$ formula depends on the angle, so the magnitude of B is not a function of just r. And you still have the problem of determining the origin, how z=0 in the formula relates to your setup.

• Oh interesting, I see, thanks. But then how to know exact offset in mm where sensor in phone is located ? As you have said, one choosing different sensor offset - will get different exponent. How to extract true exponent. Or to find out true location of magnetometer sensor ? I've tried sliding magnet along different phone places, the maximum field peak I've got at a pictured bottom corner. Maybe sensor is deeper inside a phone ? But then I can't move magnet close to it. So how to solve this problem, for not substituting $18 mm$ offset without a real reason ? – Agnius Vasiliauskas Jan 7 at 21:03
• I am not saying that an offset of 18 mm is the right one. I just tried values until I got the exponent if -3 just to show that you can get it. The field may not be a function of just r but may depend on x, y, z component. I don't think it is spherically symmetric, to depend just on r. And the sensor's symmetry matters too. – nasu Jan 7 at 21:26
• And even for ideal dipole, the simple dependence works only for faraway points. Nearby is more complicated. – nasu Jan 7 at 21:28
• I edited the answer to include some info from a magnet manufacturer for cubic magnets. From the picture looks like you use a cubic magnet, right? – nasu Jan 8 at 0:09
• Very intresting. I played with the formula too but in a different way. I took the dimeansions of the magnet 5mm (it looks like being around this size in the picture) and plotted the field nummerically. I found that for distances (z) over about 100 mm it fits well with an inverse cubic power. For distances in your measured range the exponent is closer to 1.5 indeed. You can plot a log-log graph and see that it becomes close to a straight line for large z, but not or your range of distances. – nasu Jan 9 at 4:52

The range of the magnetoresistive sensors is typically about 1 milli-tesla. Permanent magnet have much higher fields at close range, so you sensor may have gotten saturated. Then you need to reset it, by moving the phone in a figure-8 pattern.

So it is best to start the measurement at a larger distance.

• Thanks, you both were right. Magnet shape & saturation was the case. – Agnius Vasiliauskas Jan 8 at 17:15