A Digital-to-Analog Converter (DAC) is a hardware component or microcontroller peripheral that translates discrete binary numbers into a continuous, proportional physical voltage or current. When you integrate a DAC into your embedded project, it fundamentally changes the circuit's capabilities by replacing rigid 0V/3.3V digital logic levels with a precise, variable analog voltage that can directly drive op-amps, audio amplifiers, analog meter movements, or programmable power supplies.
The Core Mechanism: Binary to Voltage
To understand how a DAC operates on the bench, we need to look at the math governing its resolution. A DAC takes an integer from your microcontroller's memory and maps it to a voltage between a ground reference (0V) and a positive reference voltage (VREF).
The original ESP32 (non-S2/S3 variants) features a built-in 8-bit DAC tied to GPIO25 and GPIO26, referenced to the chip's 3.3V supply.
Resolution: 8 bits = 2^8 = 256 discrete steps (values 0 through 255).
Step Size (LSB): 3.3V / 255 = 12.94 mV per step.
Calculation: If your Arduino IDE code executes
dacWrite(25, 128);, the hardware outputs 128 * 12.94 mV = 1.656V on pin GPIO25.If you update that value in a loop using a sine lookup table, the pin outputs a smooth analog waveform rather than a static DC level.
The Espressif ESP-IDF DAC documentation notes that this internal 8-bit peripheral is highly susceptible to power rail noise. If your 3.3V rail has a 50mV ripple from a switching regulator, your analog output will inherit that ripple, making the internal DAC unsuitable for high-fidelity audio or precision measurement without heavy external RC filtering and linear voltage regulation.
Where You Meet This In Practice
While digital communication (I2C, SPI, UART) handles data, the physical world is inherently analog. You will reach for a true DAC in specific embedded scenarios where digital toggling fails:
- Programmable Power Supplies: Using a DAC to feed the feedback (FB) pin of a buck converter (like the LM2596) allows your microcontroller to dynamically adjust the output voltage in real-time.
- Analog Audio Synthesis: Generating raw sine, triangle, or custom wavetables for synthesizers. PWM cannot produce clean, multi-frequency audio without massive, expensive analog reconstruction filters.
- Driving Legacy Analog Gauges: Moving a physical 0-10V industrial panel meter using a DAC paired with an op-amp gain stage.
- Function Generators: Sweeping frequencies to test analog filters or audio amplifiers on your workbench.
The Great Confusion: True DAC vs. PWM
The most common mistake hobbyists make is assuming that analogWrite() on an Arduino or ledcWrite() on an ESP32 outputs an analog voltage. It does not. These functions output Pulse Width Modulation (PWM).
| Feature | True DAC (e.g., MCP4725) | PWM (e.g., analogWrite) |
|---|---|---|
| Output Waveform (Static) | Flat, steady DC voltage line | Digital square wave (0V to VCC) |
| Hardware Requirement | Dedicated DAC silicon (internal or external IC) | Standard GPIO timer/counter peripheral |
| Driving Analog Sensors | Directly compatible with ADC inputs | Requires external RC low-pass filter to smooth |
| Current Drive Capability | Very low (usually < 5mA, needs op-amp buffer) | High (can source/sink 10-20mA directly) |
| Frequency Domain | Clean baseband signal | High-frequency switching noise at carrier frequency |
If you attempt to read a PWM pin with another microcontroller's Analog-to-Digital Converter (ADC), the reading will fluctuate wildly between 0 and 1023 (on a 10-bit ADC) depending on the exact microsecond the ADC samples the square wave. A true DAC solves this by holding the voltage steady via a sample-and-hold capacitor inside the silicon.
External DACs: When Built-In Peripherals Fall Short
Internal microcontroller DACs are usually limited to 8-bit or 10-bit resolution and suffer from poor linearity. When your project demands precision, you must move to an external DAC IC communicating over I2C or SPI.
The Microchip MCP4725 is the industry-standard entry-level external DAC. It is a 12-bit I2C device. Let's look at the math for a 12-bit system on a 3.3V reference:
- Steps: 2^12 = 4,096 steps.
- Step Size: 3.3V / 4095 = 0.805 mV per step.
This sub-millivolt resolution is roughly 16 times more precise than the ESP32's internal DAC, making the MCP4725 (which costs around $2.50 on a breakout board) ideal for setting precise bias voltages or controlling lab equipment. For multi-channel, high-speed applications (like dual-channel audio or XY oscilloscope control), SPI-based DACs like the MCP4922 offer faster update rates since SPI clocks can easily run at 10MHz, whereas I2C is typically bottlenecked at 400kHz.
Frequently Asked Questions
Does the Arduino Uno have a built-in DAC?
No, the classic Arduino Uno (ATmega328P) does not have a true Digital-to-Analog Converter peripheral. It only has ADCs (Analog-to-Digital Converters) for reading analog inputs, and PWM timers for analogWrite(). To get true analog voltage output from an Uno, you must wire up an external I2C DAC like the MCP4725 or build a passive R-2R resistor ladder network on a digital port.
What is the difference between a DAC and an ADC in microcontrollers?
They are exact opposites. An ADC (Analog-to-Digital Converter) measures an incoming physical voltage (like from a potentiometer or temperature sensor) and converts it into a binary number your code can read. A DAC takes a binary number generated by your code and converts it into a physical output voltage. Microcontrollers often have multiple ADC channels but rarely have more than one or two DAC channels, as reading the analog world is generally more common than generating analog signals.
Can I just use an RC filter on a PWM pin instead of buying a DAC IC?
Yes, but with severe trade-offs. By placing a resistor (e.g., 10kΩ) in series with the PWM pin and a capacitor (e.g., 1µF) to ground, you create a low-pass filter that averages the square wave into a DC voltage. This is a valid hack for slow-moving signals like setting a DC motor baseline or dimming a high-power LED driver. However, the RC filter drastically limits your bandwidth (you cannot generate audio frequencies this way without severe ripple) and introduces a high output impedance, meaning the voltage will droop as soon as you connect a load. For anything requiring speed, precision, or current drive, a dedicated DAC IC paired with an op-amp buffer is mandatory.






