Learn / Semiconductors / Op-amps

Op-Amp Basics and Comparators

ReviewedIntermediate MakerAbout 6 min
In short

Op-Amp Basics and Comparators: the short answer

An op-amp (operational amplifier) amplifies the difference between its two inputs, + (non-inverting) and − (inverting), by a huge amount, often 100,000 times or more. On its own, that means the output slams to one supply rail or the other: if + is even slightly higher than −, the output goes high; if − is higher, it goes low.

Level
Intermediate
Time
About 6 min
Topic
Semiconductors
You will learn to

Understand what an op-amp does, use one as a comparator with hysteresis, and build a buffer for a weak signal.

Before this: LEDs and Current Limiting, Sensor Interfaces

An op-amp (operational amplifier) amplifies the difference between its two inputs, + (non-inverting) and − (inverting), by a huge amount, often 100,000 times or more. On its own, that means the output slams to one supply rail or the other: if + is even slightly higher than −, the output goes high; if − is higher, it goes low. Used this way, with no feedback, it is a comparator, and it answers one question: is this voltage above or below that one?

A common example is a light or temperature switch. Feed an LDR divider to the + input and a potentiometer's set point to the − input. When light rises above the set point, the output goes high and can drive a transistor and relay. The problem is noise: near the threshold the input wobbles and the output chatters on and off. Fix it with hysteresis by feeding a little of the output back to the + input through a large resistor (positive feedback). Now the switch-on point is slightly higher than the switch-off point, and the output changes cleanly. Dedicated comparator ICs such as the LM393 switch faster and have open-collector outputs, so they need a pull-up resistor.

With negative feedback (output connected back to the − input) the op-amp behaves completely differently: it adjusts its output until the two inputs are equal. The simplest case is the voltage follower, output tied to −, signal into +. The output copies the input but can supply current, so it buffers a high-resistance sensor or divider without loading it. Check the supply range: an LM358 on 5 V cannot output higher than about 3.5 V, while rail-to-rail parts such as the MCP6002 reach close to both rails.

With feedback and without

With negative feedback, an op-amp adjusts its output until its two inputs are at nearly the same voltage. That gives predictable gain: a non-inverting amplifier has gain 1 + Rf ÷ Rg. Without feedback the gain is huge, so the output swings to one supply rail or the other depending on which input is higher, and the op-amp acts as a comparator.

A dedicated comparator chip such as the LM393 is faster and designed for that job, but it usually has an open-collector output that needs a pull-up resistor.

Hysteresis stops chatter

A slow or noisy input near the threshold makes a comparator output flicker. Positive feedback through a resistor adds hysteresis, so the switching point depends on the present output: one threshold going up and another going down. That is a Schmitt trigger, and it gives a clean digital edge from a slow signal such as a light sensor.

Check the supply and the range

Many op-amps cannot swing to the rails or work with inputs close to them, and a 5 V circuit may need a rail-to-rail part such as the MCP6002. Check the supply range, the input range and the output swing in the datasheet, especially on a single supply.

Common mistakes
  • Leaving out the pull-up on an open-collector comparator output.
  • Using an op-amp near its input limits on a single 5 V supply.
  • Not adding hysteresis to a noisy threshold.
Key formulas
Gain = 1 + Rf ÷ Rg
non-inverting amplifier
Gain = − Rf ÷ Rin
inverting amplifier
Intermediate lesson · Maker plan

Practise this lesson with Maker

The explanation above is free for everyone. The practice for Intermediate lessons in every domain are part of the Maker plan at ₹499 a month, and Pro includes them too.

With Maker you also get: a worked example, a hands-on task, a 3-question check.

Common questions

What will I learn in "Op-Amp Basics and Comparators"?

Understand what an op-amp does, use one as a comparator with hysteresis, and build a buffer for a weak signal.