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.

Comparator schematic symbol with a signal input, a reference input and a two-level digital output
The comparator: output = HIGH when Vin > Vref, LOW otherwise — running open-loop.
2 in
Signal + reference
HIGH/LOW
Digital output
open-loop
No feedback
fast
Snaps to a rail

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.

Comparator basic operation: as the input crosses the reference the output switches between high and low
As Vin crosses Vref, the output snaps between HIGH and LOW.
Vout = HIGH if Vin > Vref,   LOW if Vin < Vref
The huge open-loop gain means even a tiny difference drives the output fully to one rail or the other.

Inverting vs Non-Inverting

Which way the output goes depends on which input carries the signal.

Non-inverting comparator outputs high when input exceeds reference; inverting comparator outputs high when input is below reference
Non-inverting: HIGH when Vin > Vref. Inverting: HIGH when Vin < Vref.

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.

Comparison of a comparator and an op-amp by feedback, output type, speed and output stage
A comparator is built for open-loop, fast, two-level output; an op-amp for linear, feedback operation.

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.

Comparator with positive feedback forming a Schmitt trigger with two switching thresholds
Positive feedback through R2 makes a Schmitt trigger — two thresholds instead of one.
Hysteresis loop showing the output switches high at the upper threshold and low at the lower threshold
The hysteresis loop: switch up at VUT (rising), down at VLT (falling).
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 comparator using two comparators and a reference divider to detect if the input is within a voltage window
One comparator flags “too high” (> VHI), the other “too low” (< VLO) — combine to detect in-range.

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.

Open-collector comparator output with an external pull-up resistor to the supply
Add a pull-up (e.g. 10 kΩ) from the output to VCC so it can go HIGH.
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 8-pin DIP pinout with two independent comparators and open-collector outputs
The LM393: two comparators in one 8-pin chip, open-collector, single-supply.

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).

Comparator light or dark detector project with an LDR divider, a threshold potentiometer, a comparator and an LED
LDR divider → comparator → LED, with a pot to set the switching light level.

Parts & steps

Parts: comparator (LM393) · LDR · fixed resistor · potentiometer · 470 Ω · LED · pull-up resistor.

  1. LDR + fixed resistor between VCC and GND — the junction is the light-sensing voltage.
  2. Potentiometer as a divider → adjustable threshold voltage.
  3. Sensor voltage to one input, threshold to the other (swap them for light- vs dark-triggered).
  4. 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.

Comparator applications: level detection, zero-crossing, Schmitt trigger, oscillators, ADCs and monitoring
From threshold alarms to ADCs — comparators turn analog into digital decisions.
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

TermMeaning
ComparatorCompares two voltages; gives a two-level (digital) output.
Reference (Vref)The fixed voltage the input is compared against.
Open-loopNo feedback — the normal comparator mode.
HysteresisTwo switching thresholds (VUT, VLT) set by positive feedback.
Schmitt triggerA comparator with hysteresis.
Window comparatorTwo comparators detecting if the input is within a range.
Open-collectorOutput that only pulls low; needs a pull-up resistor.
Pull-up resistorResistor to VCC that lets an open-collector output go high.
LM393 / LM339Popular 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.

Continue Learning