Home built Hall sensor switch using LM311 comparator.
Fig. 1

LM311 Comparator Projects for Hobbyists Using Hall Sensors

by Lewis Loflin

The LM311 is a versatile high-speed comparator that works very well for hobbyist projects involving magnetic sensing. This tutorial demonstrates how to combine the LM311 with ratiometric (linear) Hall effect sensors to create stable Hall switches and Hall latches with hysteresis. Adding positive feedback turns the comparator into a Schmitt trigger, which prevents oscillation and provides clean, reliable switching.

Also see Hall Sensor Circuits, Theory, Operation

Review of Ratiometric Hall Sensors

With a ratiometric sensor the output voltage (VOUT) increases or decreases depending on magnet strength, polarity, and distance from the Hall device.

With no magnetic field present, VOUT typically measures a little over 50% of the supply voltage. As the south pole approaches the printed face, VOUT increases. The north pole on the printed side decreases VOUT (sometimes all the way to zero with a strong magnet). The non-printed face works in the opposite manner.

Note: 1 Tesla = 1000 mT; 1 mT = 10 gauss. A strong refrigerator magnet is roughly 100 gauss (10 mT). An MRI machine magnet is 1–3 Tesla.

Hall switches and latches are considered digital devices because they add a Schmitt trigger and an open-collector output transistor.

LM311 pin connections.
Fig. 2

In the basic circuit (Fig. 1), a ratiometric Hall sensor is connected to an LM311 comparator. The LM311 has an open-collector output. The output transistor turns on when the Hall sensor’s VOUT exceeds the reference voltage (VREF), turning on the LED.

Caution: Always check the maximum voltage rating of your Hall sensor. Most ratiometric sensors are rated for 4.5V to 6V.

With 12V supply, VOUT sits at approximately 6V with no magnet. Setting VREF at 7V means the comparator turns on (and the LED lights) when a south pole increases VOUT above 7V. However, if VOUT hovers right at the threshold, the circuit can become unstable or oscillate.

To fix this, we need **hysteresis** — separate turn-on and turn-off points.

Hysteresis voltage points Hall switch versus Hall latch.
Fig. 3 — Hysteresis voltage points: Hall switch vs Hall latch

A Hall Switch (with Hysteresis)

In Fig. 4, resistor R4 introduces hysteresis. This creates two different reference voltages depending on whether the comparator output is high or low (Schmitt trigger behavior).

LM311 based Hall Switch
Fig. 4

Calculations when the LM311 is off (VOUT < VREF):

When the south pole increases VOUT to 6.82V, the LM311 turns on and the LED lights.

When the LM311 turns on:

Hysteresis = Bop − Brp = 0.5V

See detailed calculations: Hysteresis Hall Switch Calculations

A Hall Latch

Change R4 from 100K to 22K to create a Hall latch. The circuit now requires the opposite magnetic pole to turn it off.

A south pole turns the latch on. Removing the magnet keeps it on. Only a north pole will turn it off.

See detailed calculations:

Support This Site – Donate via PayPal