Analog Circuits

Op Amp Comparator Circuits: Threshold Detection Explained

How op amp comparator circuits detect a voltage threshold: inverting and non-inverting setups, a divider reference, LM393 outputs and when to add hysteresis.

On this page
  1. Short answer
  2. How a comparator differs from an amplifier
  3. Basic inverting and non-inverting comparators
  4. Setting the threshold with a divider (worked example)
  5. Dedicated comparators (LM393, LM339) and open-collector outputs
  6. Window comparator
  7. When noise causes chatter: hysteresis
  8. Practical checks

Short answer

An op amp comparator compares two voltages and switches its output between two levels, high or low, depending on which input is larger. It runs without feedback, so the output swings almost to a supply rail rather than settling at a precise analog value. That makes it useful for threshold detection, such as “is this sensor above 2.5 V?”

How a comparator differs from an amplifier

An amplifier uses negative feedback to set a precise gain and produces an output that follows the input. A comparator has no feedback loop. Its open-loop gain is very large, often tens of thousands or more, so even a small difference between the inputs drives the output into saturation near the positive or negative supply.

The output is therefore a digital-style high or low, not an analog copy of the input.

Basic inverting and non-inverting comparators

  • Non-inverting comparator: the signal goes to the + input and the reference goes to the − input. The output goes high when the signal is above the reference, and low when it is below.
  • Inverting comparator: the signal goes to the − input and the reference goes to the + input. The output behaves the other way round.

Use the non-inverting form for “high when above the threshold.” Use the inverting form when your logic needs the opposite sense.

Setting the threshold with a divider (worked example)

The reference is usually a fixed voltage. A simple resistor divider makes one from the supply.

Take a 5 V supply and two 10 kΩ resistors in series from 5 V to ground. The midpoint sits at:

V_REF = 5 V × 10 kΩ / (10 kΩ + 10 kΩ) = 2.5 V

Connect the midpoint to the − input, and the signal to the + input. The output goes high when the signal rises above 2.5 V.

Two practical notes:

  • The divider’s output is only as stable as the supply and the resistor tolerances. A 1% resistor pair or a dedicated reference gives a steadier threshold.
  • The divider draws current from the supply all the time. Choose resistor values that give an acceptable current draw, for example in the kilohm range.

Dedicated comparators (LM393, LM339) and open-collector outputs

General-purpose op amps work for slow, low-precision jobs. Dedicated comparator ICs are built for switching. Common examples are the LM393 (two comparators in one package), the LM339 (four comparators) and the LM311 (one comparator). Many of them have an open-collector output.

An open-collector output can only pull the line low. To get a high level, add a pull-up resistor from the output to the logic supply. A 10 kΩ pull-up to 5 V is a common starting value. Check the datasheet for the output’s voltage and current limits.

Window comparator

A window comparator uses two comparators with different thresholds, one high and one low. Their outputs are combined with simple logic, so the output indicates whether the input is inside a chosen range. It is a common way to flag a voltage that has drifted out of tolerance.

When noise causes chatter: hysteresis

If the input hovers near the threshold, noise can make the output flip back and forth quickly. Adding positive feedback gives the comparator two thresholds, one for rising and one for falling signals. This is called hysteresis, and it is the basis of the Schmitt trigger.

Practical checks

  • Check the common-mode input range. The inputs must stay within the range the comparator allows, including at the supply rails for some devices.
  • Check whether the output can reach the rails. Many op amps used as comparators cannot swing fully to the supply, while rail-to-rail or dedicated comparator outputs can.
  • Add a small capacitor across the supply pins of the comparator to reduce noise, and keep the reference and signal wiring short.
  • Test with a slow ramp on the input and watch the output on a scope, so you can see the switching point and any chatter.

The complete guide to analog circuits

Amplifier and Signal Circuits: Feedback Amplifier Types Explained
Read the guide

Keep exploring

Guides from other topics

All topics →