Contents [show]
You will need that Op Amp or one similar, along with a resistor and a capacitor.
Now, Ive attempted to give you a functional description of the circuit, not only to a
you in understanding, but also so that you get a sense for how you may wish to
tweak it.
Get an LM358
eBay Amazon Bang Good IC Station
It also uses resistor and capacitor in series to form an RC time constant that charges to the desired voltage.
You could omit the op amp, but it has some advantages. For one, it has a nice high output impedance.
Second, it offers a degree of protection for your Arduino.
http://henrysbench.capnfatz.com/henrys-bench/arduino-projects-tips-and-more/arduino-lm358-op-amp-pwm-to-voltage-converter/ 1/8
11/11/2017 Arduino PWM to DC Voltage Op Amp Converter | Henry's Bench
http://henrysbench.capnfatz.com/henrys-bench/arduino-projects-tips-and-more/arduino-lm358-op-amp-pwm-to-voltage-converter/ 2/8
11/11/2017 Arduino PWM to DC Voltage Op Amp Converter | Henry's Bench
1) A PWM signal is applied to the input of the circuit. Pulse width modulation has few characteristics that a
important to us.
The rst is the period of the signal. That is two say, how frequently the PWM signal repeats itself
Next were interested in the amplitude, or how high the signal goes in volts.
Finally, we want to know the percentage of time the signal is on.
Sections
2) Next, the
capacitor C1 charges through R1 to the average value of the capacitor. The time it takes to
charge to this value is determined by the RC time constant. The values for the capacitor and resistor are
largely driven by the time period of the PWM. Another consideration in resistor selection has to do with
maximum current handling capability of the Arduino Output. The capacitor should also have a voltage rating
that is higher than the voltage it is expected to charge to.
One time constant in seconds = Value of Resistor in Ohms x Value of Capacitor in Farads.
It takes ve time constants for the capacitor to charge very close to 100 percent.
3) Finally the Op Amp responds by raising or lowering its output until the value at pin 2 ( the inverting input) is
equal to the value at pin 3 ( the non-inverting input).
When super imposed on a classical RC time constant curve (with a value of 5 volts), it will look something lik
this:
http://henrysbench.capnfatz.com/henrys-bench/arduino-projects-tips-and-more/arduino-lm358-op-amp-pwm-to-voltage-converter/ 3/8
11/11/2017 Arduino PWM to DC Voltage Op Amp Converter | Henry's Bench
If we select a 50% duty cycle, the timing will look something like this:
http://henrysbench.capnfatz.com/henrys-bench/arduino-projects-tips-and-more/arduino-lm358-op-amp-pwm-to-voltage-converter/ 4/8
11/11/2017 Arduino PWM to DC Voltage Op Amp Converter | Henry's Bench
Notice how the output of the PWM falls low after 1 mSec. At this point in time, the capacitor begins
discharging.
In that millisecond of time, lets estimate what the capacitor will charge to.
Lets cheat. Go to the online calculator found HERE. Insert the resistance and capacitor values, enter 5 for th
supply voltage and enter 1 mSec for the time.
You will see that after this rst millisecond the the capacitor will have charged to 0.1053 volts. (about 2.1
percent of).
Now when we start the discharge cycle, we have 0.1053 volts across it; not ve volts.
Lets go to another online calculator found HERE. Enter the 0.1053 volts and the other values. Be sure to en
the time.
You will see that in that the capacitor has only lost about two percent and is sitting at about 0.103 volts.
In the second charge cycle the voltage across the cap starts where the rst discharge cycle left of or about
0.103 volts.
Go back to the online calculator for charging caps. Set your supply voltage to 5.0 0.103 volts ( or 4.897
volts). You will see a result of 0.103 volts.
http://henrysbench.capnfatz.com/henrys-bench/arduino-projects-tips-and-more/arduino-lm358-op-amp-pwm-to-voltage-converter/ 5/8
11/11/2017 Arduino PWM to DC Voltage Op Amp Converter | Henry's Bench
This value is what is added to the 0.103 volts that we already have. Thus at the end of this charge cycle we w
have about 0.206 volts.
Go back to your discharge calculator and you will see that you lost another 2 percent.. putting the value acros
the capacitor at about 0.201 volts.
This step process continues until the capacitor charges to about 2.5 volts. It will take about ten RC time
constants to get there ( about half a second).
When it gets there, the small charge and discharge cycles will continue. Using an oscilloscope, you will see
them riding across the top of the DC value. My set up yielded about 50 mV of ripple. Ill show you how to cle
that up in another tutorial.
http://henrysbench.capnfatz.com/henrys-bench/arduino-projects-tips-and-more/arduino-lm358-op-amp-pwm-to-voltage-converter/ 6/8
11/11/2017 Arduino PWM to DC Voltage Op Amp Converter | Henry's Bench
Copy Paste and Up Load the Arduino PWM to Voltage Out Converter
Sketch
The sketch is really basic. Youre going to cycle through various voltages in three second intervals.
int pwmOut = 3; // The output to the transistor that drives the motor
void setup()
{
pinMode(pwmOut, OUTPUT);
}
void loop()
{
analogWrite(pwmOut, 0); // about zero volts
delay(3000);
analogWrite(pwmOut, 51); // about 1 volt
delay(3000);
analogWrite(pwmOut, 102); // about 2 volts
delay(3000);
analogWrite(pwmOut, 128); // about 2.5 volts
delay(3000);
http://henrysbench.capnfatz.com/henrys-bench/arduino-projects-tips-and-more/arduino-lm358-op-amp-pwm-to-voltage-converter/ 7/8
11/11/2017 Arduino PWM to DC Voltage Op Amp Converter | Henry's Bench
Share this:
http://henrysbench.capnfatz.com/henrys-bench/arduino-projects-tips-and-more/arduino-lm358-op-amp-pwm-to-voltage-converter/ 8/8