The Comparator
The circuit that answers one question — “is this voltage bigger than that one?” A comparator compares an input to a reference and snaps its output HIGH or LOW. Learn the symbol, how it differs from an op-amp, hysteresis (the Schmitt trigger), window and open-collector types, the LM393 IC, and a light-sensor you can build.
Complete Learning Path — Comparator
From the symbol and basic operation, to inverting/non-inverting, comparator vs op-amp, hysteresis, the window comparator, open-collector outputs, ICs, a project and applications
What is a Comparator?
A comparator compares two voltages — an input and a reference — and gives a two-level (digital) output that tells you which is bigger. If the input is above the reference, the output is HIGH; below it, the output is LOW.
It shares the triangle symbol of the op-amp, but it is built to run open-loop and switch fast and cleanly — ideal for turning an analog level into a yes/no decision.
Basic Operation
Feed a changing signal to one input and a fixed reference to the other. Every time the signal crosses the reference, the output flips.
Inverting vs Non-Inverting
Which way the output goes depends on which input carries the signal.
Comparator vs Op-Amp
They look identical, but they are optimised for opposite jobs. A general op-amp can work as a comparator, but a real comparator is faster and better behaved open-loop.
Hysteresis — the Schmitt Trigger
A slow or noisy input hovering near the reference makes the output chatter. The cure is hysteresis: a little positive feedback that sets two switching thresholds.
Rule of thumb
The gap VUT − VLT is the hysteresis. Make it a bit wider than your worst-case noise and the output stays clean and glitch-free.
Window Comparator
Need to know if a voltage is between two limits? A window comparator uses two comparators and a reference divider.
Window comparators are perfect for go/no-go tests: is a supply within tolerance, is a sensor reading in a safe band, is a signal valid?
Open-Collector Output
Many comparators (like the LM393) have an open-collector output. It can only pull the pin LOW — so you must add a pull-up resistor.
A hidden advantage
Open-collector lets you set the HIGH level by choosing the pull-up supply (e.g. pull up to 3.3 V to talk to a 3.3 V microcontroller), and lets several outputs share one line (wired-OR).
Comparator ICs
A few chips cover almost every hobby and industrial need. The LM393 (dual) is the classic.
LM393
Dual comparator, open-collector, single supply — the go-to part.
LM339
Quad (four) comparators, same family, 14-pin.
LM311
Single, fast, flexible output with a strobe pin.
Project: Light / Dark Detector
A classic comparator build: an LDR senses light, a potentiometer sets the threshold, and an LED turns on when it gets dark (or bright).
Parts & steps
Parts: comparator (LM393) · LDR · fixed resistor · potentiometer · 470 Ω · LED · pull-up resistor.
- LDR + fixed resistor between VCC and GND — the junction is the light-sensing voltage.
- Potentiometer as a divider → adjustable threshold voltage.
- Sensor voltage to one input, threshold to the other (swap them for light- vs dark-triggered).
- Output (with pull-up) → 470 Ω → LED → GND. Turn the pot to set when it switches.
Applications
Anywhere an analog level needs to become a decision, a comparator is at work.
Level detection
Over/under-voltage, temperature, light alarms.
Zero-crossing
Detect where a waveform changes sign.
Schmitt trigger
Square up and clean noisy signals.
Oscillators
Relaxation oscillators with an RC.
ADCs
The core of flash and SAR converters.
Monitoring
Battery, current and temperature limits.
Key Terms — Glossary
| Term | Meaning |
|---|---|
| Comparator | Compares two voltages; gives a two-level (digital) output. |
| Reference (Vref) | The fixed voltage the input is compared against. |
| Open-loop | No feedback — the normal comparator mode. |
| Hysteresis | Two switching thresholds (VUT, VLT) set by positive feedback. |
| Schmitt trigger | A comparator with hysteresis. |
| Window comparator | Two comparators detecting if the input is within a range. |
| Open-collector | Output that only pulls low; needs a pull-up resistor. |
| Pull-up resistor | Resistor to VCC that lets an open-collector output go high. |
| LM393 / LM339 | Popular dual / quad comparator ICs. |
Frequently Asked Questions
Quick, expert answers to the questions people ask most about comparators.
What is a comparator?
A circuit that compares two voltages and outputs a two-level (digital) signal showing which is larger. If the non-inverting input is above the reference, the output goes high; otherwise low. It normally runs open-loop and switches quickly.
What is the difference between a comparator and an op-amp?
An op-amp is built for linear operation with negative feedback and a push-pull output; a comparator is built to run open-loop with a fast two-level output, often open-collector. A general op-amp can work as a comparator but is slower and may misbehave.
What is hysteresis / a Schmitt trigger?
Hysteresis adds a little positive feedback so the comparator switches at a higher threshold rising and a lower threshold falling. The gap stops the output chattering on slow or noisy inputs; that circuit is a Schmitt trigger.
What is an inverting vs non-inverting comparator?
Non-inverting: signal on the + input, output high when input > reference. Inverting: signal on the − input, output high when input < reference.
What is an open-collector output and why the pull-up?
An open-collector output can only pull its pin low, not drive it high. A pull-up resistor from the output to the supply makes the pin go high when the internal transistor is off, sets the high level, and allows wired-OR of several outputs.
What is a window comparator?
Two comparators plus a reference divider that check whether the input is between a lower and upper limit — one flags “too high”, the other “too low”, so together they detect in-range.
What are common comparator ICs?
The LM393 (dual), LM339 (quad) and LM311 (single). The LM393 and LM339 are open-collector, single-supply parts and are extremely common.
What are comparators used for?
Threshold and level detection, zero-crossing detection, squaring noisy signals (Schmitt trigger), relaxation oscillators, ADCs, and monitoring battery voltage or temperature against limits.
Conclusion & Key Takeaways
A comparator is the bridge from the analog world to a digital decision — and with hysteresis it does it cleanly, even with noise.
Compares 2 Vs
Input vs reference.
Digital out
HIGH or LOW.
Open-loop
Unlike an op-amp.
Hysteresis
Schmitt trigger beats noise.
Open-collector
Needs a pull-up.
LM393
The classic chip.