I came pretty close to calling this one "Magnets, How do they work?" But I thought that might confuse more than it would amuse. All jokes aside, hall effect sensors are pretty cool, and also pretty simple to use, but there are a few types you may not know about and I figured it would be a good time to introduce them incase your next project was In need of sensing some magnetic forces.

If you don't know, a hall-effect sensor is a device that reacts to a magnetic field. The most common reaction being the sensor acting as a digital switch "turning on" in the presence of a strong enough magnetic field. And actually most people when first looking into them only know of these. But the reality is that there any many different types, from ones that output an analog signal depending on the strength and polarity of a magnet, to ones that latch on when a strong enough field is sensed, but won't unlatch until an equally strong, opposing field is sensed.

Hall effect sensors are all rated to work with a specific strength of magnet field (measured in Gauss) which dissipates with distance from the magnet. Just like sound, it is softer when you are further away from the source. The only reason this is important, is because the distance a magnet needs to get to one of these sensors to trigger it is totally dependent of the magnets strength. So a really powerful magnet will trigger the sensor from a greater distance than a weak magnet. Sounds obvious I know, but these sensors also have a max Gauss rating as well. So, too powerful of a magnet, getting too close, can mess them up and eventually break them. Most sensors are sold in a wide range of sensitivity. The 3 in this article work well with household magnets, but if you need ones to work with very strong magnets, they are available.

The 3 sensors we will be going over are:
OPTEK Technology OH090U - Simple Hall Effect Sensor
Melexis US1881 - Latching Hall Effect Sensor
Allegro A1321 - Ratiometric Linear Hall Effect Sensor

OPTEK Technology OH090U

The OH090U (available from digikey at $1.75) is probably what you think of when you think of a hall effect sensor, this guy acts just like a digital reed switch, when a magnetic field gets close enough, it switches. In the case of the OH090U, it switches LOW. So when no magnetic field of the minimum trigger value is sensed, the OH090U output pin will be equal to the source voltage (4.5V to 24V), and when a field of the minimum trigger strength is within range, the output pin will be ground, or 0v.

One nice thing about the OH090U is that it schmitt triggers. Meaning there is a gap between when it triggers on, and triggers off. So if the sensor triggers on at 90 gauss, it wont release until it drops below 65 gauss. This keeps it from triggering on/off/on/off if a magnet is right on the cusp of that minimum trigger spot.

Hooking It Up

The doc sheet for the OH090U says you need a capacitor between ground and the out pin, however, in my testing, it worked perfectly without it. This is probably to smooth out the signal, and 95% of the time, this is going to be ok with out the capacitor, but if you plan on using this for automative purposes or other situations that could put people in harm's way if it were to misfire, use the capacitor, seriously. The sensor does need a 500-860Ω resistor between VCC (V+) and the output pin for it to work.

Melexis US1881

The Melexis US1881 (available from sparkfun at $0.95) is a Latching Hall Effect Sensor meaning that once it is triggered it latches and will not unlatch until a magnetic force of reverse polarity and strength is sensed. So If the north pole of a magnet turned it on, the south pole of a magnet is then needed to turn it off. When the US1881 is triggered the output will be equal to the source voltage (3.5 to 24V) and unlatched will output 0v/ground.

I did find that using an overly strong magnet with this sensor would sometimes not latch it or would latch it to the point that it was hard to unlatch. So keep your 1in rare earth magnets away from this one.

Hooking It Up

Just like the OH090U above, the US1881's documentation recommends some capacitors from ground to output and VCC. But again, I tested it without them, and as long as you have a 10K resistor between VCC and the output, it will work for 95% of what you need to do. From what I could tell, the capacitors are just there to smooth the output and stop the signal from bouncing, but most microcontrollers like the Arduino will not have any issue with this. If you find that the sensor seems to be triggering more than once each time it should, try putting the capacitors in, it could be your problem.

Allegro A1321

The Allegro A1321 (available from modern device at $2.60) is a linear hall effect sensor. Unlike the other two, this sensor does not have a wide operating voltage range, and is limited to 4.5 to 5.5v (Assuming 5v for article). When no minimum magnetic feild is sensed, this sensor will output half of the source voltage, (2.5v). When the north side of a magnet approaches the face of the sensor, the output voltage will linearly ramp up to the source (5v) and when the south pole of a magnet approaches the face of the A1321, the output will linearly drop to ground (0V).

Hooking It Up

Unlike the other 2 sensors, no external parts are needed to use the A1321, just connect 5v to pin 1, ground to pin 2, and pin 3 will output a linear voltage as described above.


The behaviors of all of the above sensors are shown in this video.

Extending this

Magnets are really cool, on their own, but mixed with hall effect sensors they can do some pretty cool things, like levitation! You can use them to actuality count when a wheel or gear rotates by placing a small magnet on the end of the wheel or gear. The A1321 can be used to sense when a lamp is turned on by placing it over the cord. When the lamp turns on a small magnetic field is produced, enough to be sensed. In my research it seems companies are really trying to push their use in steering assemblies for cars, acting as high precision rotary encoders. But don't do something so boring like that.... create secret locks that require you to place a magnet on a certain spot to open, fill a floor with hundreds of them and place magnets on your shoes and watch the floor light up where ever you walk. WAIT...

Use the latching ones, get like hundreds of them, and place them with LEDs under a resin floor. Put north facing magnets on your shoes, and south on other people's shoes and see when you have walked, but others have not! Yeah, it's late.