Build it step by step
0 of 7 doneBuild the ladder from 13 resistors
Three spine resistors and five 20 kilohm pairs.
Wire D2 to D5 to the four bit inputs
D2 is the smallest bit.
Upload and open the serial monitor at 9600
The stepping starts.
Measure the output at each step
Write down all sixteen voltages.
Compare with the expected values
Find the steps that are uneven.
Wait for the sine wave
The meter settles near 2.5 V.
Optionally listen through the 1 kilohm resistor
A low volume tone.
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
- Development BoardsBuyArduino Nano × 1
- PassivesBuyResistor 10 kΩ × 13
- PassivesBuyResistor 1 kΩ × 1
- Tools & InstrumentsBuy
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Bit 0 pin D2 | 20 kilohm (two 10 kilohm in series) to node 0 | Least significant bit |
| Node 0 | 20 kilohm to GND | The ladder's end resistor |
| Node 0 | 10 kilohm to node 1 | First spine resistor |
| Bit 1 pin D3 | 20 kilohm to node 1 | Second bit |
| Node 1 | 10 kilohm to node 2 | Second spine resistor |
| Bit 2 pin D4 | 20 kilohm to node 2 | Third bit |
| Node 2 | 10 kilohm to node 3 | Third spine resistor |
| Bit 3 pin D5 | 20 kilohm to node 3 | Most significant bit |
| Node 3 | Meter red probe, meter black probe on GND | The 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.
| Check | Expected |
|---|---|
| Code 0 | Output near 0 V |
| Code 8 | Output near 2.5 V |
| Code 15 | Output near 4.7 V |
| Each step | About 0.31 V higher than the last |
| Sine playing | Meter 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 →
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.
