This is a simple test of a Hall effect sensor, an electronic component to detect the presence of a magnetic field.
(It detects Hall voltage; if I understand correctly, charge carriers (electrons) moving through a magnetic field veer off to one side, resulting in voltage laterally across the current flow. I picture a canal full of water, with diagonal baffles in it; when the water flows (electric current), the baffles (magnetic field) push it sideways, so the water is slightly higher at one side of the canal than it is at the other (Hall voltage).)
Parts used:
Results: Distances are from magnet body front to Hall effect sensor package front, in centimeters to the nearest millimeter. (In the video, a nail is used to show the magnet's strength intuitively before testing.)
Magnet | Trigger | Release |
---|---|---|
Explorabook wand magnet (Book © 1991, ISBN 1-878257-14-5) | 0.6 | 0.9 |
Horshoe fridge magnet | 0.5-0.7 | 0.9-1.0 |
Rare Earth 1/8" cube (side) | 0.2 | 0.3 |
Rare Earth 1/8" cube from SparkFun (95¢ each) (pole) | 0.5 | 0.7 |
Rare Earth 1/8" cube (pole, stacked pair) | 0.6 | 0.9 |
Hard drive magnet | 1.8 | 2.7 |
Fridge magnet (round) | 0.1-0.2 | 0.2-0.3 |
Rare Earth 12x3mm Round from Joann Craft and Fabrics ($3 for 6), advertized as "over 2000 Gauss" | 1.1 | 1.6 |
Rare Earth 12x3mm Round (edge) | 0.5 | 0.7 |
Rare Earth 12x3mm Round (stacked pair) | 1.4 | 2.0 |
Code and Circuit:
The video shows using an analog input and a pullup resistor. However, the same results may be achieved using a digital input and the Arduino's built-in pullup resistor. (Output from this Hall effect sensor is binary, anyway.) For that, the Hall effect sensor's pin 1 (leftmost when facing the writing) is connected to +, pin 2 to -, and pin 3 to one of the Arduino's digital pins (in this case, 12).
/**
* Switch the status LED on or off to match a digital input pin.
*/
#define PIN_SENSOR 12
#define PIN_STATUS 13
void setup()
{
pinMode(PIN_STATUS, OUTPUT);
pinMode(PIN_SENSOR, INPUT);
digitalWrite(PIN_SENSOR, HIGH);
}
void loop()
{
digitalWrite(PIN_STATUS, digitalRead(PIN_SENSOR));
}