Projects / R-2R ladder converter

R-2R ladder converter

Intermediate1.5 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANO

    Build the ladder from 13 resistors

    Three spine resistors and five 20 kilohm pairs.

  2. NANO

    Wire D2 to D5 to the four bit inputs

    D2 is the smallest bit.

  3. NANO

    Upload and open the serial monitor at 9600

    The stepping starts.

  4. NANO

    Measure the output at each step

    Write down all sixteen voltages.

  5. NANO

    Compare with the expected values

    Find the steps that are uneven.

  6. NANO

    Wait for the sine wave

    The meter settles near 2.5 V.

  7. NANO

    Optionally listen through the 1 kilohm resistor

    A low volume tone.

In short

How do you build a r-2R ladder converter?

Build a four-bit digital-to-analog converter from thirteen ordinary resistors, drive it from four Nano pins, and step through all sixteen values with a meter. Then play a rough sine wave through it. It shows how digital numbers become voltages. You need Arduino Nano, Resistor 10 kΩ × 13, Resistor 1 kΩ, Digital multimeter, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 90 minutes.

Level
Intermediate
Time
About 90 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Bit 0 pin D220 kilohm (two 10 kilohm in series) to node 0Least significant bit
Node 020 kilohm to GNDThe ladder's end resistor
Node 010 kilohm to node 1First spine resistor
Bit 1 pin D320 kilohm to node 1Second bit
Node 110 kilohm to node 2Second spine resistor
Bit 2 pin D420 kilohm to node 2Third bit
Node 210 kilohm to node 3Third spine resistor
Bit 3 pin D520 kilohm to node 3Most significant bit
Node 3Meter red probe, meter black probe on GNDThe analog output

Code

An R-2R ladder is a clever network of just two resistor values that turns a row of digital pins into a voltage. Each pin adds a share of the supply that is half as big as the pin before it, so four pins give sixteen steps. Use 10 kilohms for the single resistors, and make each 20 kilohm resistor from two 10 kilohm resistors in series, which is how thirteen resistors build the whole ladder. Measure the output at node 3 for each of the sixteen codes and compare with the expected value, which is five volts times the code divided by sixteen. The sketch steps through all sixteen with a two second pause, then plays a sine table fast enough to make a tone of about 600 hertz. A meter then shows only the average, about 2.5 volts. To listen, take the output through the 1 kilohm resistor into the line input of a small powered speaker, at a low volume, and never into headphones. Resistor errors make the steps slightly uneven, which is the lesson in why precise converters need matched resistors.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// R-2R ladder on D2 (bit 0) to D5 (bit 3). Output voltage is about 5 V x code / 16.
const uint8_t SINE[16] = {8, 11, 13, 15, 15, 15, 13, 11, 8, 5, 3, 1, 0, 1, 3, 5};

void writeCode(uint8_t code) {
  PORTD = (PORTD & 0b11000011) | ((code & 0x0F) << 2);   // pins D2 to D5 together
}

void setup() {
  DDRD |= 0b00111100;                     // D2 to D5 as outputs
  Serial.begin(9600);
  Serial.println("Stepping through all 16 codes, one per 2 seconds.");
  for (uint8_t code = 0; code < 16; code++) {
    writeCode(code);
    Serial.print("code ");
    Serial.print(code);
    Serial.print("   expected ");
    Serial.print(5.0 * code / 16.0, 2);
    Serial.println(" V  (measure it now)");
    delay(2000);
  }
  Serial.println("Now playing a sine wave. The meter shows the average, about 2.5 V.");
}

void loop() {
  for (uint8_t i = 0; i < 16; i++) {
    writeCode(SINE[i]);
    delayMicroseconds(100);               // 16 steps x 100 us gives about 600 Hz
  }
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

Stepping through all 16 codes, one per 2 seconds.
code 0   expected 0.00 V  (measure it now)
code 1   expected 0.31 V  (measure it now)
code 2   expected 0.63 V  (measure it now)
code 3   expected 0.94 V  (measure it now)

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Code 0Output near 0 V
Code 8Output near 2.5 V
Code 15Output near 4.7 V
Each stepAbout 0.31 V higher than the last
Sine playingMeter shows about 2.5 V average

If it does not work

Output stuck at one value

Check the bit wires reach D2 to D5.

Steps are far from expected

Check each 20 kilohm is really two 10 kilohm in series.

Output stays near 0

Check the ground end resistor.

Steps uneven

Resistor tolerance, try other resistors from the bag.

Upload fails

Choose the Old Bootloader option.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the r-2R ladder converter?

Arduino Nano, Resistor 10 kΩ × 13, Resistor 1 kΩ, Digital multimeter, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the r-2R ladder converter take to build?

About 90 minutes for a intermediate maker, in 7 steps.

How do I know the r-2R ladder converter works?

Code 0: Output near 0 V. Code 8: Output near 2.5 V. Code 15: Output near 4.7 V.

Output stuck at one value: what should I check?

Check the bit wires reach D2 to D5.

Steps are far from expected: what should I check?

Check each 20 kilohm is really two 10 kilohm in series.

Output stays near 0: what should I check?

Check the ground end resistor.

Steps uneven: what should I check?

Resistor tolerance, try other resistors from the bag.