I am using a magnetometer to detect metal objects. I typically take a reading when the software starts (zero offset calibration) and assuming that there are no metal objects in the vicinity and then periodically start take a reading from the sensor. If a metal object is placed in the vicinity of the sensor, the readings usually exceed a certain threshold and the presence of an object can be detected this way. So far so good.
However, due to other nearby objects (metal objects not directly in the vicinity etc) and thermal drift the magnetometer base reading will drift from the originally taken one. Are there any algorithms/methods suggested in order to try to maintain a good zero offset?
I was thinking of starting with the initial zeroing perhaps and then upon sensing that the object was removed, a new reading for the zero calibration could be taken. This way it always updates whenever there isn't an object.