Picture of Analog Output - Convert PWM to Voltage
Arduino's and other microcontrollers provide analog to digital (ADC) conversion to convert an input voltage to a digital value. You might think that they also provide the converse which is digital to analog (DAC) conversion. This is not the case. Instead they provide pulse-width modulated (PWM) outputs (see second photo). The Arduino library provides this functionality with a function called analogWrite(). The name seems to imply DAC functionality, but it just controls the PWM output. For many applications, such as the case of motor control, PWM is sufficient. For other applications, such as creating a linear voltage or current driver, a real DAC is needed.

Creating a real DAC
Fortunately, it is easy to convert a PWM output to an analog voltage level, producing a true DAC. All that is needed is a simple low-pass filter made from a resistor and a ceramic capacitor. The simple RC low-pass filter shown in the third photo converts the PWM signal to a voltage proportional to the duty cycle. For the Arduino, an R value = 3.9K and a C value = 0.1uF works well for most applications.

For more details on this subject as well as calculating R & C values more suitable for your application, please consult this article.

Was this a useful electronics tip?  If so, please cast your vote for it in the Electronics Tips & Tricks Contest.
How to vote: The voting button can be found at the top of this instructable. You can also visit the contest page and vote for other instructables as well. Multiple votes can be cast in each contest. If you see a tip you like, please show your gratitude with a vote.
AmritS5 days ago
why do i need the resistor
bdraško1 year ago

Can you make it quicker? I mean can you make time necessary for capacitor to charge smaller?

In this case you would need to increase PWM frequency, meaning you will have to "get your hands dirty" and modify analogWrite() library or even create your own "softPWM". totally doable both ways

AleixM bdraško9 months ago

Maybe with a coil in series with the resistor and a very small cap....

Just speculating

To improve this add a second filter to remove most of the output ripple followed by an OPAmp as a buffer or with a gain if you want to control a larger voltage. The OPAmp will let you draw more current than directly off a pin of a micro-controller.

alan0007 months ago
Can you make it reverse. Voltage to pwm signal

A simple microcontroller circuit would also be very easy to use... use the ADC to measure the analog voltage input, and adjust the output PWM duty cycle accordingly.

I believe a 555 timer would work for that. It's not as simple as this circuit. Here's an example of using it as a PWM light dimmer.


Do remember that the 'RC-circuit" provided hereover will only provide you with a given voltaic output LEVEL, i.e. for driving a given high-impedance controller. If you want to provide real power to your application via your "analogue" output, you will have to consider the current drawn by your load, and take that into account when chosing resistor and capacitor -values.

deeen1 year ago
Thanks a lot!!
roughly2 years ago
this is gonna be super helpful -- thanx so much
YakAttack3 years ago
Thanks for a quick and useful Ible...should be just what I need!
great tip! I find myself using it often.