Comparators and References
This page covers two small analog ICs: the LM393 dual open-collector comparator and the TL431 programmable shunt voltage reference. Both are single-supply parts that show up constantly in threshold detection, power supplies, and sensor front-ends.
LM393 dual comparator
The LM393 is a dual general-purpose comparator with open-collector outputs, running from a single supply of 2 V to 36 V (nominal 5 V). Each of its two independent comparators answers one question: is the IN+ voltage above or below IN-?
Pinout
| Pin | Label | Description |
|---|---|---|
| 1 | OUT1 | Comparator 1 output (open-collector) |
| 2 | IN1- | Comparator 1 inverting input |
| 3 | IN1+ | Comparator 1 non-inverting input |
| 4 | GND | Ground |
| 5 | IN2+ | Comparator 2 non-inverting input |
| 6 | IN2- | Comparator 2 inverting input |
| 7 | OUT2 | Comparator 2 output (open-collector) |
| 8 | VCC | Supply (2–36 V) |
Pin 1 is at the notch/dot end (DIP-8). Add a 100 nF decoupling capacitor across VCC and GND.
Comparator vs op-amp
A comparator looks like an op-amp but is built to slam its output fully high or low, not to sit in a linear region. Use a comparator when you only care which input is bigger:
IN+ < IN-→ output sinks current (pulls LOW)IN+ > IN-→ output floats (hi-Z, pulled HIGH by the resistor)
There is no output phase inversion. The input common-mode range runs from GND up to VCC − 2 V, so keep both inputs at least 2 V below the supply rail.
Open-collector output + pull-up
The output is just the collector of an internal transistor — it can pull the pin down to ground but cannot drive it up. Every output needs an external pull-up resistor (typically 10 kΩ) to VCC or to a separate logic rail. Without it the output floats and reads garbage.
This is actually a feature: tie the pull-up to a 3.3 V rail and the LM393 drives 3.3 V logic even while its own VCC is 5 V. The output can sink up to 16 mA, enough to drive an LED or a small relay directly. Two open-collector outputs can also be wired together for a “wired-OR” — any comparator going low pulls the shared line low.
Hysteresis
Without feedback, a slow or noisy input crossing the threshold makes the output chatter. Add a few millivolts of hysteresis with a resistor from the output back to IN+: the threshold shifts after each transition, giving the input a clean snap. This is standard practice for any real-world comparator wired to a noisy sensor.
Example circuit (threshold LED)
Hold one input at a fixed reference, drive the other from a sensor, and light an LED when the sensor crosses the threshold:
VCC (5 V) ─┬─ R1 ──┬── IN- (2) reference divider (R1/R2 sets the threshold)
│ R2 ── GND
│
├─ Rtop ─┬── IN+ (3) sensor divider (Rtop in series with the sensor)
│ sensor ── GND
│
├─ 10k ───── OUT1 (1) pull-up (open-collector output)
│
└─ 330 Ω ─ LED ─ OUT1 (1) LED anode to 330 Ω, cathode to OUT1
VCC (8) ── 5 V GND (4) ── GNDThe reference divider holds IN- at a fixed threshold while the sensor drives IN+. While IN+ stays above the threshold, OUT1 floats high (pulled up) and the LED is off; when the sensor pulls IN+ below the threshold, OUT1 sinks to ground and current flows VCC → 330 Ω → LED → OUT1, lighting the LED. Add a little hysteresis (above) so a noisy sensor snaps cleanly instead of flickering at the boundary. Common uses: threshold detection, window comparators, and zero-crossing detection.
TL431 shunt voltage reference
The TL431 is a programmable precision shunt reference in a TO-92 package. It behaves like an adjustable zener diode: it holds its REF pin at an internal 2.495 V (±0.5%) bandgap reference by sinking current through the cathode-to-anode path.
Pinout
| Pin | Label | Description |
|---|---|---|
| REF | REF | Reference / feedback input (compares against 2.495 V) |
| A | Anode | Ground-side terminal |
| K | Cathode | Supply-side terminal (the regulated node) |
Pin order varies between manufacturers — verify against your batch’s datasheet. With the flat face forward, a common order is REF (left), ANODE (centre), CATHODE (right).
How it works
The part watches REF. When REF rises above 2.495 V it sinks more current through K→A; when REF drops below it sinks less. Wrap that around a resistor divider and it regulates an output voltage:
Vout = Vref × (1 + R1/R2), where Vref = 2.495 VR1 sits between cathode and REF; R2 between REF and anode. Because the REF pin draws only ~2 µA of bias current, the divider can use fairly high resistor values without much error. Tie REF directly to the cathode and you get a fixed 2.495 V reference with no divider at all.
Adjustable shunt regulator
As a shunt regulator the TL431 always sits in parallel with the load, so it needs a series resistor from the supply to the cathode to set the standing current:
- Cathode current must stay between 1 mA and 100 mA.
- The cathode voltage must stay at or above ~2 V (and above Vref).
- Maximum dissipation is 500 mW — watch the cathode current times cathode voltage.
Pick the series resistor so the TL431 still gets its minimum 1 mA at the lowest supply voltage and highest load, and never exceeds 100 mA at the highest supply with no load.
Example circuit (3.3 V reference)
Supply (5 V)
│
Rs (series, sets shunt current)
│
├──────── K (cathode) ── Vout (3.3 V)
│ │
R1 (load)
│
├──────── REF
│
R2
│
A (anode) ─── GNDFor 3.3 V out, R1/R2 must satisfy 3.3 = 2.495 × (1 + R1/R2), so R1/R2 ≈ 0.32 (for example R1 = 3.2 kΩ, R2 = 10 kΩ). The TL431 is the workhorse behind switching-supply feedback loops, precision references, and constant-current LED drivers.