A Digital-to-Analog Converter (DAC) is an electronic component that translates discrete digital binary numbers from a microcontroller into a continuous, proportional analog voltage or current output. In a real circuit, a DAC changes abstract logic states (1s and 0s) into physical electrical potential, allowing your code to directly bias a transistor, drive an audio amplifier, or set the reference threshold for a comparator. The most common point of confusion for embedded beginners is assuming that any 'analog' output from a microcontroller is a true DAC, when in reality, most basic boards are just faking it with Pulse Width Modulation (PWM).
analogWrite(), you are generating a digital square wave (PWM), not a true analog voltage. To get a real DC voltage, you must either add an external DAC IC or filter the PWM with a resistor-capacitor (RC) network.
Resolution, Step Size, and the Math That Matters
The 'meaning of DAC' resolution is defined by its bit-depth, which dictates how many discrete voltage steps it can produce between 0V and its reference voltage (VREF). Think of DAC resolution like a staircase: an 8-bit DAC has 256 steps, while a 16-bit DAC has 65,536 steps. The smaller the step, the closer the output mimics a perfectly smooth analog ramp, reducing quantization error.
Here is how bit-depth translates to real-world voltage steps across common microcontroller and external IC configurations:
| Resolution | Total Steps | Step Size (3.3V VREF) | Step Size (5.0V VREF) | Common Hardware Example |
|---|---|---|---|---|
| 8-bit | 256 | 12.94 mV | 19.60 mV | Original ESP32 internal DAC (GPIO 25/26) |
| 10-bit | 1,024 | 3.22 mV | 4.88 mV | Raspberry Pi Pico (RP2040) internal DAC |
| 12-bit | 4,096 | 0.80 mV | 1.22 mV | Microchip MCP4725 (External I2C) |
| 16-bit | 65,536 | 0.05 mV (50 µV) | 0.07 mV (76 µV) | Analog Devices AD5686 (External SPI) |
Worked Numeric Example: 12-Bit DAC Output
Let's say you are using an external 12-bit DAC (like the Microchip MCP4725) powered by a 3.3V reference. You want to output exactly 1.65V to bias an op-amp.
The formula for DAC output is: V_out = (Digital_Value / (2^n - 1)) * V_REF
- n = 12 (so max value is 4095)
- V_REF = 3.3V
- Target V_out = 1.65V
Rearranging to find the Digital Value: Digital_Value = (1.65 / 3.3) * 4095 = 2047.5. Since we must send an integer, we round to 2048. Sending the binary equivalent of 2048 over I2C will yield an output of (2048 / 4095) * 3.3 = 1.6503V. The 0.3mV difference is your quantization error, which is well within the tolerance of most analog stages.
True DAC vs. PWM: The analogWrite() Illusion
Understanding the difference between a true DAC and PWM is critical for embedded debugging. A true DAC outputs a steady, continuous DC voltage. PWM outputs a 0V to 5V (or 3.3V) square wave that switches on and off thousands of times per second. The 'analog' value in PWM is the duty cycle—the percentage of time the pin is HIGH.
If you feed a 50% duty cycle PWM signal directly into an analog multimeter, the meter's internal low-pass filtering will average it out and display roughly 2.5V (on a 5V system). However, if you feed that same signal into an audio amplifier or a fast-responding motor driver, the circuit will see a harsh, high-frequency square wave, resulting in audible buzzing or excessive heat.
Furthermore, newer microcontrollers are dropping internal DACs entirely. While the original ESP32 featured 8-bit DACs on GPIO 25 and 26, the Espressif ESP32-S3 and C3 variants omitted them to save silicon area and reduce noise, forcing designers to rely on PWM or external I2C/SPI DAC chips.
Where You Meet DACs in Practical Embedded Projects
Once you move past basic LED fading, true DACs become mandatory in several specific project categories:
- Audio Synthesis and Playback: Generating sine waves, playing back WAV files, or building digital synthesizers requires updating the output voltage tens of thousands of times per second. An 8kHz audio sample rate requires a DAC that can settle in under 125 microseconds.
- Programmable Power Supplies: If you are building a bench power supply controlled by a microcontroller, you use a DAC to set the feedback reference voltage of a buck converter or linear regulator. A 12-bit or 16-bit DAC allows for precise 10mV or 1mV adjustment steps.
- Analog Synthesizer Control Voltage (CV): Interfacing a digital sequencer with vintage analog synths requires generating the 1V/octave standard. A 12-bit DAC is the minimum requirement here to ensure musical notes stay in tune across a 5-octave span without noticeable quantization 'stepping' in the pitch.
- Electronic Loads and Battery Testers: DACs are used to program the current sink threshold by feeding a precise voltage into the non-inverting input of an op-amp driving a power MOSFET.
Selecting External DAC ICs When Internal Ones Fall Short
When your microcontroller lacks a DAC, or its internal 8-bit DAC is too noisy and imprecise, you must add an external IC. The choice between I2C and SPI protocols dictates your project's performance ceiling.
| Feature | I2C DAC (e.g., MCP4725) | SPI DAC (e.g., MCP4922, AD5686) |
|---|---|---|
| Bus Speed | 400 kHz (Fast Mode) | 20 MHz to 50 MHz |
| Update Rate Limit | ~30,000 samples/sec | 1,000,000+ samples/sec |
| Best Use Case | Setting static DC bias, slow control loops, CV generation | Audio playback, high-speed waveform generation, arbitrary function generators |
| Wiring Complexity | 2 wires (SDA, SCL) + address pins | 4 wires (MOSI, SCK, CS, LDAC) per chip |
For most hobbyist and intermediate DIY projects requiring a true analog output, the MCP4725 I2C breakout remains the gold standard. It includes an internal EEPROM, meaning it can remember its last voltage output even when power is cycled—a massive advantage for programmable power supplies or motor controllers that need to boot into a safe, known state before the microcontroller finishes its initialization routine.






