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}$
 A: 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.
A: 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.
