Digital to Analog Converters (DAC) Tutorial: Using Arduino R-2R Resistor Ladders

Published By

Computers function in a world of zeros and ones, on and off, and black and white. But in the real world, things are rarely that simple. For example, you may prefer your phone to operate at less than 100% brightness. And fully mashing―then releasing―your car's gas pedal is a very inefficient way to drive. To produce a more subtle behavior (e.g., 60% lighting or 20% gas pedal), computers need some way to convert those zeros and ones into an approximation of a linear curve.

Approximating PWM Analog Output Using an R-2R DAC

Image: Jeremy S. Cook

The simplest way to achieve that linear curve is to use a method called pulse-width modulation (PWM). As outlined in my PID Controller Basics post, PWM means that your board sends a series of pulses of varying lengths to a specified output, which averages out to a specific value. PWM is ideal for controlling simple applications like LED lighting and motors.

However, PWM is still a square wave, which means it isn’t appropriate for all applications. In some situations, I recommend another option: the resistor ladder-based digital-to-analog converter (DAC). This component can output voltages in discreet levels that are dictated by a DAC's resolution in bits. Consider the DAC's bits the number of "rungs" on its resistor ladder.

Arduino DAC R-2R Ladders

If you want DAC functionality using an R-2R ladder then the good news is advanced boards like the Arduino Due and the newer MKR series have that capability built in. The Due features two DAC outputs and MKR series boards have one. Resolution varies between boards and software configurations, which we addressed in more detail for the Arduino. On the other hand, more familiar boards—like the Uno and most of the Nano series—don't feature this capability. If you want more than one or two true analog outputs, you'll need a separate DAC module.

Make Your Own DIY R-2R Ladder DAC