Magnetometer Offset Drift
Here are some possible approaches:


AC couple your sensor.
Continuously produce an extremely low-pass filtered version of your signal (&lt;0.1Hz) and use that as your "zero". You can filter in hardware or in software (using something like FIR filters). If done in software want to seed your filter with the initially measured value as zero so that when you start up you don't have to wait 10 seconds or more for the zero to settle.
Instead of using the magnetic field strength for detection,
differentiate the signal and use the rate-of-change/slope of the
magnetic field strength for detection. This is basically a software
version of #1. Calculating slope can be tricky in practice because
of noise. Small amplitude, but rapid noise fluctuations make is so
that if you calculate the slope between very closely spaced samples
the slope could be enormous but is not actually reflective of the
overall slope. Which means you either have to low-pass filter first
(in either software or hardware) or just use samples spaced farther
apart in time so the rapid fluctuations due to noise aren't
interpreted as a severe slope in the signal.

Take any real world signal with noise (even a flat line) and
differentiate it in spreadsheet software and plot it will be very
obvious.


All these methods will overlook something moving very slowly.