## Introduction: R2R Digital-Analog-Converter (DAC)

Hi,

in this instructable, I want to show you, how you can create your own Digital-Analog-Converter (DAC) by simply using a R2R Resistor ladder. But at first, I want to show you for what Applications a DAC is used for.

For example, if you want to create an analog voltage of 3V with your Arduino you will definitely run into problems, because the Arduino isn't able to create this kind of voltage. The Arduino could only output different kinds of voltages: 0V (LOW) and 5V (HIGH). So the variety of possible voltages on the Arduino is limited.

The answer to this problem is a simple circuit, which will convert an digital Voltage to a Analog voltage. The simplest way to do so, is a R2R-Resistor ledder. This schematic is for an 4Bit DAC connected to an Arduino at Pin D0, D1, D2 and D3. For this circuit you need two types of resistors: R and the double value of R (2R). For example 1k and 2k .

Now we want to analyze this simple linear circuit, how the Output voltage will change while changing the applied voltages on the digital pins. For example we set D0 to 5V, D1 to 0V , D2 to 5V and D3 to 0V. You can also read this as " 0101 " in binary, but on this I will come later again. The circuit is now changed to this:

At this point you need to consider, how you could analyze this circuit. From the first look you will see two voltage sources (5V). One of the simplest ways to analyze a circuit with two voltage sources is to use superposition. If using superposition, you first consider only about the first voltage source and the second will be pulled to ground. In the next step the first will be pulled to ground and the second will kept on. After you have calculated the voltage V_OUT in both cases, you can simply sum up the voltages and you will have the resulting voltage.

So let's start with the first case: D0 is connected to 5V and D2 is pulled to ground:

Here you will see two resistors (2R) connected in parallel followed by one resistor (R) in series . So the resulting value will be 2R/2 + R = R . The voltage source can be divided by two, if you consider the two 2R resistors which are connected in series. The resulting circuit will look like:

Now it is rather simple. As you can see there are two 2R resistors connected in parallel, followed by one R resistor in series, so the resulting resistor will be 2R. The Voltage source needs to be divided by two again. The result will look like that:

Now you need to repeat the simplification from the step above two times and you will come to this simplified circuit

As you can see the resulting voltage will be 5V/16V or in decimal 0,3125V.

Now we have completed the analysis for the first power source. For the second we will start from this point and will use the same simplifications like in the steps above:

Once you have finished the analysis you will come to this simplified circuit:

Now the output voltage will be 5V/4V or 1,25V in decimal.

**Conclusion:**

**Conclusion:**

The last step is to sum up both voltages to get the real voltage on the V_OUT pin. In this case this will be

0,3125V + 1,25V = **1,5625 V **

But the main message of this calculation is how the applied voltage to the R2R network will affect the output voltage V_OUT. As you can see, when D0 is set to HIGH, the resulting voltage will be divided by 16, but when D3 is set to HIGH, the out_put voltage is only divided by 4. And that is the trick of the R2R network, if you control your pins with binary values, the voltage will directly follow the binary number.

For example:

A 4bit number is directly connected to the Pins, so the first bit is connected to Pin D3 , the second to Pin D2 , the third to pin D1 and the last to Pin D0.

If the number has a value of "0101", the affected voltage will be 1,5625V, which is exactly the calculated voltage above. **The voltage V_OUT will change linear to the assigned binary number!** Now you can simply extend your R2R network to 8bit to create a more accurate DAC.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?

Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: The Simulation in Tinkercad-Circuits

For a simple simulation of this R2R DAC I haved used Tinkercad circuits.

This time I have extended the R2R DAC to an resolution of 8bit. You can simply press the "Simulation" button in the Tinkercad project to start the simulation and see an sawtooth function on the oscilloscope. The Tinkercad-Circuit project can be accessed by this link: https://www.tinkercad.com/things/bXuK4iUc6im . I have also implemented **rectangle**, **triangle **and **sawtooth **functions. The functions needs to be comment out, then you can start your simulation again. This code uses portmanipulation which makes the thing a lot easier than using arduino functions like digitalwrite().

uint8_t level = 0; void setup() { DDRD = B11111111; // set all Digital Pins on PORTD to OUTPUT } void loop() { //Rectangle //PORTD = 255; // 255 is 11111111 in binary //delay(1); //PORTD = 0; // 0 is 00000000 in binary //delay(1); //Sawtooth level %= 255; PORTD = level++; //Triangle //for(int i = -255 ; i < 255 ; i++){ //PORTD = abs(i); //} }

## Step 2: From Simulation to Reality

After the simulation it is always a good choice to build a prototype and test it in reality. For this test have created the small circuit on a bread board and connected it to an old oscilloscope.

Here are some pictures of the circuit in action:

**Rectangle:**

**Sawtooth:**

**Triangle:**

**Conclusion:**

For me this projects was a success, I have learned a lot about how DAC works. But please remember, if you consider to use this as a function generator, you will definitely need to use an operation amplifier connected as an impedance changer. This will make your circuit more stable to different loads and different impedances.

Runner Up in the

Electronics Tips & Tricks Challenge

## Discussions

1 year ago

Your explanations are quite precise. Of course outputs never go to 0.0000V or 5.0000V and looking at the sawtooth and triangle curves, we can see the highest bit layer is slightly different than others. Such layers need very precise resistors, and they definitely exist on the market for decades now, not that expensive.