If you are measuring 2.50V using a standard 12-bit A to D converter with a 5.0V reference, the direct converted digital output is 2048. The exact formula used to derive this is D = (Vin / Vref) × (2^n - 1). Substituting your specific values: D = (2.50 / 5.0) × (2^12 - 1) = 0.5 × 4095 = 2047.5, which the ADC rounds to a raw integer count of 2048.
Core Voltage-to-Count Conversion Table
The table below maps the ±20% voltage range around our 2.50V baseline (2.0V to 3.0V). It demonstrates how the raw digital count shifts depending on the bit-depth of your A to D converter, assuming a fixed 5.0V Vref. This is critical when deciding whether to use a basic 10-bit microcontroller internal ADC or an external 16-bit module like the TI ADS1115.
| Analog Input (Vin) | 10-Bit Count (Max 1023) | 12-Bit Count (Max 4095) | 16-Bit Count (Max 65535) | Resolution (mV/bit @ 12-bit) |
|---|---|---|---|---|
| 2.00V (-20%) | 409 | 1638 | 26214 | 1.22 mV |
| 2.25V (-10%) | 460 | 1843 | 29491 | 1.22 mV |
| 2.50V (Baseline) | 511 | 2048 | 32768 | 1.22 mV |
| 2.75V (+10%) | 563 | 2252 | 36044 | 1.22 mV |
| 3.00V (+20%) | 614 | 2457 | 39321 | 1.22 mV |
What Assumptions Fix the Answer (and Mains Scaling)
The numeric answer above is entirely dependent on two fixed assumptions: your Voltage Reference (Vref) and your Bit-Depth (n). If your Vref sags from 5.0V to 4.8V due to USB power droop, that same 2.50V input will suddenly read as 2133 instead of 2048. This is why precision designs use a dedicated external voltage reference IC rather than relying on the microcontroller's 3.3V or 5V rail.
How the Scaling Shifts for 120V vs 230V vs 3-Phase Mains
An A to D converter cannot physically measure 120V or 230V AC; doing so will instantly destroy the silicon. To measure mains voltage, you must use an analog front-end (a step-down transformer or a high-impedance voltage divider) to scale the AC waveform down to the ADC's 0–3.3V or 0–5V range. Here is how the scaling math shifts across global standards:
- 120V RMS (North America): The peak voltage is ~170V. If scaling to a 3.3V ADC, your front-end divider ratio must be 51.5:1. A raw ADC count of 2048 (on a 12-bit, 3.3V system) represents exactly 1.65V at the pin, which translates back to 85V RMS at the mains.
- 230V RMS (EU/UK/AU): The peak voltage is ~325V. Your divider ratio must shift to 98.5:1 to keep the peak within a 3.3V ADC limit. The same raw count of 2048 now represents 1.65V at the pin, but translates to 162V RMS at the mains.
- 3-Phase Systems: You cannot use a single-channel ADC. You must use a simultaneous-sampling multi-channel A to D converter (like the TI ADS131M04) to capture all three line-to-neutral waveforms at the exact same microsecond, preventing phase-angle calculation errors in your firmware.
When the Conversion Becomes Meaningless
Math assumes an ideal world. On the bench, three specific hardware realities will render your A to D converter math completely meaningless:
- Source Impedance Exceeds 10kΩ: Successive Approximation Register (SAR) ADCs, like the Microchip MCP3008, use an internal sampling capacitor. If your analog source (like a high-value voltage divider) has too much resistance, the capacitor cannot charge fully during the microsecond sampling window. The result? The digital count reads artificially low. Always buffer high-impedance sources with an op-amp voltage follower.
- Noise Floor Exceeds the LSB: A 16-bit ADC on a 5V rail has a Least Significant Bit (LSB) resolution of 0.076 mV. If your breadboard has 5 mV of switching noise from a nearby buck converter, your bottom 6 bits are just measuring random noise. Your 16-bit ADC is effectively functioning as a 10-bit ADC. Use hardware RC low-pass filters before the ADC pin.
- Internal ADC Non-Linearity: The internal 12-bit ADC on original ESP32 chips is notoriously non-linear, especially near the 0V and 3.3V rails. A 2.50V input might not reliably yield 3106 (the theoretical 3.3V-referenced count). For precision work on ESP32 or Raspberry Pi Pico, bypass the internal A to D converter entirely and use an external I2C/SPI ADC module.
Frequently Asked Questions
Why does my ADC read 4095 when I only apply 4.8V?
This happens when your input voltage exceeds the ADC's configured Full-Scale Range (FSR). If your ADC is configured for a ±2.048V programmable gain amplifier (PGA) range, applying 4.8V will saturate the internal comparator, clipping the output at the maximum digital code (e.g., 32767 for a 16-bit signed integer).
How do I convert the raw ADC count back to voltage in code?
Reverse the formula: Vin = (Raw_Count × Vref) / (2^n - 1). For a 12-bit ADC with a 3.3V reference reading a raw count of 1500, the math is (1500 × 3.3) / 4095 = 1.208V. Always cast your variables to float in C/C++ before dividing to avoid integer truncation errors.
Does a higher bit-depth always mean better accuracy?
No. Bit-depth dictates resolution (how small a step you can see), not accuracy (how close the step is to reality). A cheap 16-bit ADC with ±0.1% gain error might be less accurate than a precision 12-bit ADC with ±0.01% gain error. Always check the Total Unadjusted Error (TUE) in the datasheet.






