How to use an op-amp as a buffer

Posted by Nick Gammon on Sat 29 Oct 2011 04:23 AM — 3 posts, 34,218 views.

Australia Forum Administrator #0
The circuit below demonstrates how you can use an op-amp to buffer output from an Arduino.

This example is to demonstrate taking the PWM (Pulse Width Modulation) output from an Arduino and convert it into a DC voltage (more or less).

This simple sketch shows how you can read a potentiometer and depending on its position, output a PWM signal:


void setup () { }

void loop () {
  analogWrite (3, analogRead (A0) / 4);
}


The PWM output is a square wave, where the 5V output is turned on and off at around 490 Hz. The smaller the value passed to analogWrite the lower the duty cycle is (that is, it is off more often than on).

To convert that into a voltage level that varies we can use an RC filter. This uses a capacitor to smooth out the pulses into a fairly level voltage.



However the RC filter is somewhat sensitive to load. That is, the more load you place on it, the lower the voltage is.

So we can add on a "unity gain" op-amp circuit as a buffer. Now the output of the op-amp does not vary much regardless of load (within the specs of the op-amp).

In order to keep the output in the range 0V to 5V, the op-amp needs a slightly higher supply voltage (pin 8) because it cannot output 5V if its supply voltage is 5V. In fact, it outputs a maximum of about 3.4V with a 5V supply voltage. Something in the order of 7V to 12V would be suitable.

Alternatively, use a "rail to rail" op-amp such as the TS922IN.
Amended on Sun 30 Aug 2015 02:04 AM by Nick Gammon
#1
Great post Nick. Will it work for other things besides Arduino?
Australia Forum Administrator #2
Absolutely. It is just a general circuit. See Dave Jones talking about something similar on his blog:

http://www.eevblog.com/2011/12/07/eevblog-225-lab-power-supply-design-part-4-pwm-control/

He describes using PWM to get a reference voltage for a lab power supply. He describes a more sophisticated filter than mine where he does two lots of filtering before the op-amp.