I'm wondering what is the best way (if it's even possible) to detect a magnet from approximately 50cm? The sensor would be passing over it like in the attached drawing.
How strong do you think the magnet should be? Will a simple 3 axis magnetometer be enough? I'm worried that other magnetic field sources might create too much noise compared to the magnet's field.
I was playing around with a HMC5883L magnetometer a few weeks ago, and found that a small 'normal' magnet affected the readings noticeably from about 15-20cm away, so if you use a reasonable-sized rare-earth magnet, you could achieve 50cm I reckon.
The best way to find out is to try it.
robtillaart:
Note that the field of a magnet looses strength with 3rd power
so at 50 cm B is 100+ times weaker than at 10 cm .
When your MF becomes weaker than Earth MF (0.5 Gauss) you cannot detect it any more.
I have some 2" diameter rare-earth magnets here, which are extremely powerful. I had them in mind.
With a normal magnet I got a pretty good reaction at the distance I quoted, so it wouldn't surprise me if there was a noticeable reaction using the rare-earth magnet at 50cm. A magnetometer can detect a vehicle from quite a few metres away, and they are often used as metal-detectors. Still, it will only cost the price of one or two reasonably-sized rare-earth magnets to find out. I'd be interested to hear the result. (I now wish I'd thought to test mine when I had that circuit assembled.)
one of the brainiac labs found a way to detect a magnetic field from a long distance. I posted the link a few days ago but cannot find it.
as was noted, you cannot directly detect a thing when the background value is higher. however, like the Force, you can detect a disturbance. that is how they can detect submarines and ships from great distances.
When your MF becomes weaker than Earth MF (0.5 Gauss) you cannot detect it any more.
I agree with dave-in-nj's comment. In the above situation you can detect a moving magnet because it will alter the total magnetic field in a changing way. So, calculate the rate of change. If that rate drops below the noise, then obviously the method fails.
I use a 3D magnetometer as a driveway alarm. The monitor program reads the total magnetic field about 4 times a second, calculates a running average vector and looks for sudden deviations from the average. It can reliably detect an automobile moving by about 2 meters away.
I've just ordered a HMC5883L and I'll borrow a small neodymium bar magnet to test with (40x10x4mm N38 12kg lift), I'll post the results once I have them
Detecting a 'disturbance in the Force' when the sensor is getting closer/exactly above the magnet is exactly what I am trying to achieve, do you know any good articles describing how to do it? I'll try the running average first but maybe something more advanced would be better.
Here is the key section of the gate alarm code I use to detect a "disturbance in the Force". The LSM303D magnetometer I use returns numbers typically in the range of 0-1000 along each axis.
typedef struct vector
{
float x, y, z;
} vector;
int m[3],mx,my,mz;
int i,deltaA;
vector fm, fm_avg, diff; //"vector" is a 3-element array of floats
//...
// loop:
// read magnetometer
read_mag_raw(m);
fm.x = m[0];
fm.y = m[1];
fm.z = m[2];
// calculate difference from average, then update the average
diff.x = fm.x - fm_avg.x;
diff.y = fm.y - fm_avg.y;
diff.z = fm.z - fm_avg.z;
//low pass filter
fm_avg.x += (fm.x - fm_avg.x)*0.2;
fm_avg.y += (fm.y - fm_avg.y)*0.2;
fm_avg.z += (fm.z - fm_avg.z)*0.2;
// distance from this point to average
deltaA = sqrt(diff.x*diff.x + diff.y*diff.y + diff.z*diff.z);
passcounter++;
// the magic alarm value 22 (below) was determined by experiment (mean deltaA = 5.6, sd = 2.6)
// send a message, either upon alarm or at regular intervals
if(deltaA > 22 || passcounter == 0) { //alarm or keepalive, every ~255/4 seconds
...
// end loop
@Maciejp, I'll be interested to hear how you go. I wasn't specifically testing my HMC5883L for magnet detection, just for compensating an MPU6050, but the magnet was close by so I did some playing passing it across in front of the magnetometer at right angles to the x axis, and saw a good swing in values as the magnet moved past.
As others mentioned, it was probably so noticeable because I was moving the magnet.