Converting a 2.50V analog signal using a standard 10-bit A/D converter (like the ATmega328P on an Arduino Uno) with a 5.0V reference yields a digital code of exactly 512. Converting that 512 code back to an analog voltage via a 10-bit D/A converter outputs 2.50V. The governing formula is Code = (Vin ÷ Vref) × (2^n - 1). Substituting our exact values: Code = (2.50 ÷ 5.0) × (2^10 - 1) = 0.5 × 1023 = 511.5, which the microcontroller rounds to the nearest integer, 512. Conversely, the D/A formula is Vout = (Code ÷ (2^n - 1)) × Vref, yielding (512 ÷ 1023) × 5.0 = 2.502V.
The Core Assumptions That Fix Your Conversion
The numeric answer above is entirely fixed by two hardware assumptions: the reference voltage (Vref)bit-depth (n). If either of these shifts, your conversion factor changes. For example, if you move from a 5.0V Arduino to a 3.3V ESP32 utilizing its internal 12-bit ADC, the math shifts drastically. A 2.50V input on a 12-bit, 3.3V system yields (2.50 ÷ 3.3) × 4095 = 3102. The step size (Least Significant Bit, or LSB) shrinks from 4.88mV on the 10-bit/5V system to 0.80mV on the 12-bit/3.3V system, granting finer resolution but requiring a stable, low-noise Vref to be useful.
How the Answer Shifts for 120V vs 230V vs 3-Phase
A common point of confusion for beginners transitioning from DC bench projects to home energy monitoring is how an A/D converter handles mains voltages like 120V AC, 230V AC, or 3-phase power. You never feed these voltages directly into an A/D converter. Doing so will instantly destroy the silicon and pose a lethal shock hazard. Microcontroller GPIO and dedicated ADC pins have absolute maximum ratings typically between 3.6V and 5.5V.
To measure 120V or 230V AC, you must use a voltage transformer (like a ZMPT101B) or a precision resistive divider to step the mains down to a safe 0–3.3V DC envelope. Because AC swings negative, the signal is usually biased at a mid-point (e.g., 1.65V) so the ADC can capture the full sine wave. The conversion math then applies only to this scaled-down, isolated DC representation. Your firmware must then apply a secondary multiplication factor (the transformer turns ratio or divider ratio) and calculate the RMS value to map the ADC codes back to the original 120V/230V AC value. For 3-phase systems, this process is simply replicated across three isolated ADC channels with precise phase-shift timing.
When the Conversion is Meaningless
The volts-to-bits conversion becomes entirely meaningless under two conditions:
- Floating or Noisy Vref: If your ADC is configured to use the microcontroller's VCC line as its reference, and that VCC is supplied by an unregulated USB port that sags from 5.0V to 4.6V under load, your calculated voltage will be wildly inaccurate. The math assumes a fixed divisor; if the divisor moves, the answer is garbage.
- Uncalibrated Offset and Noise Floors: If your input signal is 2mV, but your ADC has an inherent offset error of ±3 LSBs (common on internal microcontroller ADCs), the digital code you read is dominated by silicon imperfections, not the actual signal.
Neighboring Values Reference Table (±20% Range)
When debugging sensor circuits, it helps to have a quick-reference table for expected ADC codes around your target voltage. Below is the conversion matrix for a target of 2.50V, showing a ±20% range (2.00V to 3.00V) across three common microcontroller and external IC configurations.
| Analog Input (Vin) | 10-Bit ADC (5.0V Vref) e.g., Arduino Uno |
12-Bit ADC (3.3V Vref) e.g., ESP32 Internal |
16-Bit ADC (5.0V Vref) e.g., TI ADS1115 |
|---|---|---|---|
| 2.00V (-20%) | 409 | 2482 | 26214 |
| 2.10V | 430 | 2606 | 27525 |
| 2.25V | 460 | 2792 | 29491 |
| 2.50V (Target) | 512 | 3102 | 32768 |
| 2.75V | 563 | 3412 | 36045 |
| 2.90V | 593 | 3598 | 38011 |
| 3.00V (+20%) | 614 | 3722 | 39321 |
Real-World IC Gotchas: Internal vs. External Converters
While the math is clean on paper, physical silicon introduces edge cases that will break your D/A to A/D converter logic if ignored. The ESP32’s internal ADC is notorious for its non-linearity, particularly above 2.5V, where the step sizes compress and the actual voltage-to-code curve deviates from the ideal straight line. If you need precision better than ±50mV on an ESP32, bypass the internal ADC entirely and use an external I2C module like the TI ADS1115, which offers true 16-bit resolution and an internal precision voltage reference.
On the output side, D/A converters introduce their own hardware realities. If you are using a dedicated DAC like the DAC8562 to generate a 0-5V control signal for a motor driver, remember that the DAC output has a finite drive capability (often limited to a few milliamps). If your load draws more current than the DAC's output buffer can source, the voltage will droop, and your D/A conversion will read low on a multimeter. Always buffer DAC outputs with an op-amp (like an LM358 or MCP6001) when driving inductive loads or long cable runs.
Frequently Asked Questions
How does an A/D to D/A converter handle negative voltages?
Standard single-supply microcontrollers (like the Arduino or ESP32) cannot read negative voltages; applying -1V to an ADC pin will forward-bias internal protection diodes and potentially destroy the chip. To measure negative voltages, you must use a differential amplifier circuit to shift and scale the bipolar signal into a unipolar 0–Vref range, or use a dedicated bipolar ADC (like the ADS1115 configured in differential mode) which can natively measure positive and negative differences between two input pins.
Why does my D/A converter output read 0.1V when the digital code is 0?
This is caused by the DAC's "zero-scale error" or output amplifier offset voltage. No physical D/A converter can pull its output perfectly to 0.000V due to internal transistor saturation limits and op-amp input offset voltages. High-quality DAC datasheets will specify this zero-scale error in millivolts. If your application requires a true 0.0V output (like turning off a laser or a valve), you must use a MOSFET switch on the DAC output or select a DAC with a built-in rail-to-rail output stage and hardware ground-switching capability.
What is the difference between resolution and accuracy in A/D conversion?
Resolution is the theoretical math we covered above: a 16-bit ADC has 65,536 steps, meaning it can theoretically resolve changes of 76µV on a 5V scale. Accuracy, however, is how close the measured code is to the true physical voltage. A cheap 16-bit ADC might have high resolution but suffer from ±4 LSBs of integral non-linearity (INL) and gain error, meaning its actual accuracy is closer to 14 bits. Always check the datasheet's INL and offset error specifications, not just the bit-depth, when selecting an A/D converter for precision metrology.






