# Electronic – Subtracting two voltages using an op-amp

operational-amplifier

I'm essentially a digital guy, and am used to using a comparator to compare two voltages and give a high or low depending on their relative values.

Now instead I want to subtract one voltage from another, and have the difference be available as an output.

I breadboarded the following circuit, but it doesn't seem to work right: I am using two op-amps as voltage-followers, and feeding them into the inverting and non-inverting inputs of another amp-amp. The quad op-amp chip (LM324) has a single supply (9v).

EDIT: see my comment to the accepted answer — I was on the right track, but had a bent pin on one of the output pins.

Now, since I do not have a negative supply, so the output cannot go negative, what I really want is for the output to be biased by +2.5 volts, so that if both pots are set midway the output will be 2.5v, not zero. Instead of adding the resistor from pin 12 to ground, I tried putting a 4.7K resistor from the non-inverting input (pin 12) to a 2.5v reference, and that seems to add in the offset I wanted. So it now appears to do what I want.

This should work, but usually there's also a resistor from the non-inverting input to ground: If \$\dfrac{R4}{R2} = \dfrac{R3}{R1}\$ then:

\$V_{OUT} = \dfrac{R_{3}}{R_{1}} \times (V_{IN+} - V_{IN-})\$

To minimize offset error both inputs have to see the same impedance, and therefore \$R1 = R2\$ and \$R3 = R4\$.
Omitting R4 will only give a scaling factor for the voltage on the non-inverting input, namely:

\$V_{OUT} = 2 \times V_{IN+} - V_{IN-}\$

but changing the setting for the lower potmeter should definitely have a result in the output. Did you measure the voltages on both inputs?

What happens if you set the lower voltage to 2.5V and the upper to 1V? The inverting input should also be 2.5V, and the output 4V. What do you measure?

Note: especially the lower voltage follower is not necessary in your version; the opamp's input current is low enough to be negligible for most uses, and by the way, you're connecting the potmeter's wiper to an exactly same input!