Skip to content

Electronics

Op-amp comparator explained

An op-amp comparator is an op-amp used with no feedback, so its output tells you which of its two inputs is bigger. If the + input is above the − input, the output goes as high as it can. If it's below, the output goes as low as it can. Wire a sensor to one input and a fixed reference to the other, and the output flips the moment the sensor crosses the reference.

A huge gain

An op-amp has two inputs, + (non-inverting) and − (inverting), and one output. It's powered from two rails, such as +9 V and 0 V, or +12 V and −12 V, and the output's energy comes from those rails, not from the inputs. The output is the difference between the inputs times a huge number, the open-loop gain, A:

Vout = A × (V+ − V−)

A is about 100,000. Inputs just 0.1 mV apart ask for 100,000 × 0.0001 V = 10 V. The output can't pass its limits. On the op-amp in the lessons, like many classic parts, they sit about 1.5 V inside each rail: ±10.5 V on ±12 V rails, or 1.5 V to 7.5 V on a 0 V and 9 V supply. So any real difference slams the output to one limit or the other.

Live experiment

An op-amp tug-of-war

The − input sits at a fixed 3 V reference. Step the + input up and down in half volts and watch the output slam to a limit. Then set the two equal and nudge + by 10 to 150 millionths of a volt.

Try it yourself: free lesson

“Meet the op-amp” is lesson 1 of 6 in Amplifier Peaks, Electronics World 6. Free with an account. Lessons unlock in order, so you’ll do the 35 before it first.

Set the threshold with a divider

To make a decision, compare the sensor with a fixed reference from a voltage divider. An op-amp's inputs draw almost no current, so the divider's voltage holds steady.

Example: an overheat alarm on 12 V. A 10 kΩ and 10 kΩ divider puts a 6 V reference on the − input. A heat sensor's divider gives 5.5 V when cool and 6.5 V when hot, on the + input. The output jumps high as the sensor crosses 6 V.

Which input gets which decides the direction. Sensor on +, reference on −: the output goes high as the sensor rises. Swap them and it goes high as the sensor falls, which is how a dusk switch turns a light on in the dark.

Comparators in the wild

Street lights that come on at dusk, low-battery warnings and smoke alarms all compare a sensor with a reference. Dedicated comparator chips, such as the LM393, switch faster than op-amps and are made for this job.

A slow, noisy sensor can wobble back and forth across the threshold and make the output chatter. Adding hysteresis, a little feedback to the + input, gives two thresholds instead of one and cures it. Add feedback to the − input instead and the op-amp stops being a comparator and becomes a precise amplifier.

Free lesson

Now build it yourself

Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.

Try it yourself: free lesson

“Meet the op-amp” is lesson 1 of 6 in Amplifier Peaks, Electronics World 6. Free with an account. Lessons unlock in order, so you’ll do the 35 before it first.

Or start from the very first lesson, no account needed

Practice questions

Three quick questions from the lessons. Pick an answer to check it.

  1. Question 1 of 3A comparator's output goes high when…
    Show the answer

    Answer: V+ is above V−. The op-amp amplifies V+ − V−. When V+ is higher, the difference is positive, so the output swings high. When V− is higher, it swings low.

    • Why not “V− is above V+”? When V− is above V+, the difference V+ − V− is negative, so the output swings low, not high.
    • Why not “the two inputs are equal”? With equal inputs the difference is zero, so nothing drives the output either way. In practice a tiny offset or noise decides it, which is why outputs chatter there.
  2. Question 2 of 3Feeding an op-amp's output back to its + input gives…
    Show the answer

    Answer: positive feedback. Back to + is positive feedback: it helps the output along, so it snaps to a limit, as in a Schmitt trigger. Back to − is negative feedback, which holds it steady.

    • Why not “no feedback”? Any path from the output back to an input is feedback. Which input it reaches decides whether it's positive or negative.
    • Why not “negative feedback”? Negative feedback goes back to the − input, where it opposes the output's change. Feeding the + input helps the change along instead.
  3. Question 3 of 3A comparator's output always sits near…
    Show the answer

    Answer: one of two levels. A comparator's output slams to one of two levels, near the top or bottom rail, so it has just two levels, like a bit. That's the step from analog to digital.

    • Why not “zero volts”? Near the bottom rail is only one of its two states. When the + input is higher, the output sits near the top rail instead.
    • Why not “one of ten levels”? A comparator has no in-between levels. Its huge gain sends the output to one of two limits, near the top or bottom rail.
Keep practising: free lesson

“Meet the op-amp” is lesson 1 of 6 in Amplifier Peaks, Electronics World 6. Free with an account. Lessons unlock in order, so you’ll do the 35 before it first.

Questions people ask

How does an op-amp work as a comparator?

Its output is about 100,000 times the difference between its + and − inputs. Without feedback, any difference you could measure drives the output to one of its limits: high when the + input is above the − input, low when it's below. So the output says which input is bigger.

What is the difference between an op-amp and a comparator chip?

Both compare two inputs. A dedicated comparator, such as the LM393, is designed to switch quickly and cleanly. Its output only pulls low, so it needs a pull-up resistor. An op-amp is designed for feedback circuits like amplifiers, and is slower when used open-loop. For slow signals, like light or temperature, an op-amp works fine.

Why does my comparator output flicker near the threshold?

A noisy input that hovers near the reference crosses it many times, and the comparator follows every crossing. The fix is hysteresis: a resistor from the output back to the + input gives two thresholds, so the output only flips once the input has moved clearly past.

Every topic