The op-amp is one of the chips you meet most often in analogue circuits: it amplifies microphone signals, reads sensors, and builds filters and comparators. It looks intimidating at first, but if you understand just two rules, you can work out most op-amp circuits yourself.
The two golden rules
When there's negative feedback (a connection from the output to the inverting input):
- No current flows into either input (+ or −). The input resistance is very high.
- The output does whatever it can to make the two inputs equal in voltage.
Every formula that follows comes from these two rules.
The non-inverting amplifier
The signal goes into the + input, and there are two resistors: Rf from the output to the − input, and Rin from the − input to ground.
G = 1 + Rf ÷ Rin
Example: Rin = 10 kΩ, Rf = 100 kΩ:
- G = 1 + 100 ÷ 10 = 11
- A 10 mV signal → 110 mV.
The output is in phase with the input, and the gain is at least 1 (if you remove Rf).
The inverting amplifier
The signal goes through Rin into the − input, and the + input goes to ground (or to a reference voltage).
G = − Rf ÷ Rin
Example: the same resistors → G = −10. The signal is amplified 10 times and inverted (when the input rises, the output falls).
The important difference: here the input resistance the source sees is only Rin, so if the source is weak (like a high-resistance sensor), the non-inverting amplifier is the better fit.
The voltage follower (buffer)
Connect the output straight to the − input and the signal to +. The gain is 1. So what's the point? Isolation: its input resistance is very high so it doesn't load the source, and its output can supply current. A classic example: after a voltage divider, so you can take a voltage from it without the load affecting it.
Worked example: amplifying a temperature sensor before the ADC
An LM35 sensor outputs 10 mV per degree Celsius, so from 0 to 100 °C its output only spans 0 to 1 V. Read it directly on an ESP32 (3.3 V range) and you use less than a third of the ADC's range, losing resolution.
The fix is a non-inverting amplifier with a gain of 3:
- Rin = 10 kΩ, Rf = 20 kΩ → G = 1 + 20 ÷ 10 = 3.
- 100 °C → 1 × 3 = 3 V, below 3.3 V with margin.
- The op-amp runs on 5 V. An LM358's output reaches about 3.5 V on a 5 V supply, so 3 V is within its range.
And since the non-inverting amplifier has a very high input resistance, it doesn't load the sensor. In code you divide the voltage by 3 and then by 0.01 to get back to temperature. If you want to understand why resolution matters, read the ADC article.
Worked example: a microphone on a single supply
A microphone signal swings above and below zero by a few millivolts, and the op-amp has only a 5 V supply, with no negative rail. Amplify it as it is and the half of the wave below zero gets clipped.
The fix in 3 steps:
- A capacitor at the input (say 1 µF) blocks any DC from the microphone and passes only the signal.
- A bias voltage on the + input: two 10 kΩ resistors from 5 V to ground make 2.5 V, so the signal swings around 2.5 V instead of zero. Put a 10 µF capacitor on that point to keep it steady.
- An inverting amplifier with a gain of, say, 100: Rin = 1 kΩ, Rf = 100 kΩ, with the + input at 2.5 V.
The output is an amplified signal swinging around 2.5 V, ready for an ADC or another stage. If there's high-frequency noise, a simple RC filter on the output helps.
Which chip?
| Chip | Supply | Notes |
|---|---|---|
| LM358 | 3 to 32 V, single or dual | Two op-amps per chip, cheap and everywhere, output not rail-to-rail |
| LM324 | Same as LM358 | Four op-amps in one chip |
| MCP6002 | 1.8 to 6 V | Rail-to-rail input and output, excellent with 3.3 V |
| TL072 | Usually dual (±15 V) | Low noise, popular in audio, but not suited to low single supplies |
| NE5532 | Dual | High-quality audio |
For Arduino and ESP32 projects on a single supply: the LM358 if you don't need the output to reach the rails, and the MCP6002 if you're on 3.3 V and need the full range.
Real-world limits
- The output can't exceed the supply: an op-amp powered from 5 V can never output 8 V. And most older chips like the LM358 don't even reach the top rail (they stop about 1.5 V short). If you need the output to reach both rails, look for a rail-to-rail output.
- Single supply: without a negative rail, a varying signal (like audio) has to be lifted to half the supply (bias) so it isn't clipped.
- Bandwidth: every op-amp has a roughly constant gain-bandwidth product (GBW). The LM358 is about 1 MHz, so at a gain of 11 it amplifies well only up to about 90 kHz.
- Sensible resistor values: 1 kΩ to 1 MΩ. Very small ones load the output, very large ones add noise.
Common problems and fixes
- Output stuck at the top or bottom rail: usually the feedback isn't connected correctly, or the input is outside the allowed range (common-mode range). On the LM358, for example, the input must stay about 1.5 V below the supply.
- Output oscillating or strangely noisy: put a 100 nF capacitor from the supply pin to ground right next to the chip. Explained in the decoupling capacitors article.
- The second op-amp in the package is unused: don't leave its pins floating. Wire it as a voltage follower with its + input at half the supply so it doesn't oscillate and disturb its neighbour.
- Gain doesn't match the calculation: make sure you're not asking for high gain at high frequency (GBW limits), and that the resistors aren't so small they load the output.
FAQ
Can an op-amp be used as a comparator? For slow signals, yes, but dedicated comparator chips such as the LM393 are faster and better suited. The difference is in the comparator article.
Why do people talk about an "ideal op-amp"? Because the two golden rules assume infinite gain and no input current. Real chips come very close to that at low frequencies, so the formulas work in practice.
Calculate it in a second
The op-amp calculator works out the gain from the two resistors for inverting and non-inverting amplifiers, or you give it the gain you want and it suggests Rf from standard values.