# Subtracting two voltages using an op-amp

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.

• The drawn circuit does not produce the difference between the two voltages V3 − V5. It produces 2⋅V3 − V5. You need the divider on pin 12 to make them equal. What voltages out do you get for the voltages you put in? – endolith Aug 15 '11 at 20:20
• If you fix the circuit as outlined below, you will have succeeded in creating an instrumentation amplifier with a gain of 1. – Mike DeSimone Aug 16 '11 at 0:09
• @davidcary then I used my iPhone to take a picture of it so I could post it After I did my edit, with the modified circuit, rather than drawing a new one (since I no longer had the original) I used copy and paste in Paint to add the offset resistor going down to 2.5v. – tcrosley May 22 '12 at 16:11

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!