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.
<p>can someone post some parameters if i want to do it 2nd order RLC low pass filter with extremely low output ripples</p>
<p>I am trying to change a pulse signal from a pulse water metering device to a 4/20mA signal so I can convert that with the use of a 250 ohm resister to a 0 to 5 v dc voltage to use as a input to the little bit cloud bit to monitor water usage on my irrigation system</p>
why do i need the resistor <br>
<p>The resistor is part of the low pass filter. If you understand how a voltage divider works, the low pass filter works in the same way with signal frequencies, except the second resistance changes (it's actually what's called the reactance of the capacitor). It acts like a big voltage divider for high frequencies, reducing them a bunch, and it acts like a small voltage divider for low frequencies, keeping them the same amplitude. It does this because the capacitors &quot;resistance&quot; (actually the reactance, this is a somewhat complicated subject for beginners I suggest you look it up) changes with frequency. It is a small resistance at high frequencies, and a large resistance at low frequencies. When the second resistor in a voltage divider is bigger than the first the output will approach the original input voltage. When the second resistor is smaller the output approaches 0V. That's whats happening with the capacitor. Without the resistor there, it wouldn't be a voltage divider, and it wouldn't filter things predictably! You can look at the math behind RC low pass filters to understand more about why.</p>
<p>Can you make it<strong> quicker</strong>? I mean can you make time necessary for capacitor to charge smaller?</p>
<p>In this case you would need to increase PWM frequency, meaning you will have to &quot;get your hands dirty&quot; and modify analogWrite() library or even create your own &quot;softPWM&quot;. totally doable both ways</p>
<p>Maybe with a coil in series with the resistor and a very small cap....</p><p>Just speculating</p>
<p>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.</p>
Can you make it reverse. Voltage to pwm signal
<p>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.</p>
<p>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. </p><p>http://www.instructables.com/id/PWM-Lamp-Dimmer-using-NE555-Timer/</p>
<p>Do remember that the 'RC-circuit&quot; 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 &quot;analogue&quot; output, you will have to consider the current drawn by your load, and take that into account when chosing resistor and capacitor -values.</p>
Thanks a lot!!
this is gonna be super helpful -- thanx so much
Thanks for a quick and useful Ible...should be just what I need!
great tip! I find myself using it often.

About This Instructable




Bio: ProvideYourOwn.com is a website devoted to people who want to make their own things and provide for their own needs. We provide information, encouragement ... More »
More by ProvideYourOwn:Using an LED for a Light SensorAnalog Output - Convert PWM to VoltageHidden Arduino Thermometer
Add instructable to: