11-25-2019, 04:03 PM
(11-25-2019, 12:52 PM)Sebastian Staacks Wrote: Your assumption, that you should subtract a reference value and that you should use the uncalibrated magnetometer is quite correct.Wow, thank you so much for the detailed response!
In fact, the magnetometer is a rather tricky sensor if you want to get absolute values. The first thing you should do, is to make sure that you know exactly where in your phone the magnetometer is, because the the dipole field of small magnets (not so relevant for "big" ones like the earth) drops rapidly with the distance. To find the magnetometer, you can use an iron nail or something similar, magnetize the nail and move its tip across the surface of your phone until you get a strong reading as you reach the magnetometer. I am emphasizing this, because the magnetometer is never in the center of the device but usually somewhere at the edge of the phone, most often in the top-right or top-left corner.
Now for the really annoying part, the calibration:
The magnetometer in your phone is extremely sensitive as it is designed to be used as a compass. Therefore it can easily resolve 50µT, but it also saturates at few mT. These are very small fields, so any kind of unwanted magnetization will influence your readings. Unfortunately, you phone is full of things that create magnetic fields and that can be easily magnetized (which is why the magnetometer is usually at the edge - far away from those things). If your phone is exposed to a strong magnetic field (like the magnets used to remove theft-protection while shopping for clothes), something might get magnetized and your compass would point in the wrong direction as it sees the permanent magnetization of some components in your phone.
That is why every phone has some strategy to recalibrate. Sometimes you can trigger this. When you are doing a magnetometer measurement and your absolute field is 100µT or more, then you can rotate the phone about every axis (still while measuring) and at some point it will suddenly drop to 50µT as the phone very likely will use the data from the rotation to subtract the constant contribution from the magnetized component. The field from this component is still there, but it is just subtracted in the calibrated data. This is nice as it means that your compass will start working again, but for measurements this can be quite annoying as you try to measure a higher field on purpose.
Therefore, you should switch to the uncalibrated magnetometer, where this would not happen. On some phones, you might not see a big difference, while on others you might see a difference of several 100mT. The downside is that you have to subtract the background yourself. To do this, you should start a measurement without your magnet, note the values and then add the magnet you want to measure. Simply subtract the values that you had without the magnet. However, you need to be careful not to move or rotate your phone as this would change the contribution of earth's magnetic field (or even local contributions - some tables have strong fields from their iron parts) and the values you want to subtract are no longer correct. So, you need to be very diligent to get good results.
Also, since you mention a neodymium magnet: Those can have rather strong fields. I do not expect them to damage your phone, but they will easily saturate your sensor. So, make sure that the magnet is either weak enough (not sure if even the small neodymium magnets are that weak) or far enough from your phone to stay below 2mT. Just make sure that if you would get closer the measured field can still increase. Then, of course, you have to make sure that the magnet is in the same position for every measurement.
Hope, this helps