Converting a 2.5V DC analog signal using a 10-bit analog digital converter (ADC) with a 5.0V reference voltage yields a digital integer of 512. The universal formula for this conversion is Digital Value = (V_in / V_ref) × (2^n - 1). Substituting our baseline values: (2.5V / 5.0V) × (2^10 - 1) = 0.5 × 1023 = 511.5, which the microcontroller truncates or rounds to 512. This baseline calculation assumes a stable DC input, a perfect 5.0V reference, and a 10-bit resolution. If your reference voltage or bit-depth changes, the integer output shifts proportionally.
The Core Conversion Formula and Neighboring Values
Every ADC maps an analog voltage window (from 0V to the reference voltage, V_ref) into a discrete number of digital steps. The total number of steps is dictated by the bit resolution (n). A 10-bit ADC has 2^10 = 1024 steps (0 to 1023), while a 12-bit ADC has 4096 steps (0 to 4095).
V_ref / (2^n). For a 5.0V 10-bit ADC, 1 LSB = 4.88mV. For a 3.3V 12-bit ADC, 1 LSB = 0.80mV.
Below is a reference table showing how the digital output shifts across a ±20% range around our 2.5V baseline, assuming a standard 10-bit ADC with a 5.0V reference (like the classic MCP3008).
| Analog Input (V_in) | Variance from Baseline | 10-Bit Digital Output (5.0V V_ref) | Voltage per Step (LSB) |
|---|---|---|---|
| 2.00V | -20% | 409 | 4.88 mV |
| 2.25V | -10% | 460 | 4.88 mV |
| 2.50V | Baseline | 512 | 4.88 mV |
| 2.75V | +10% | 563 | 4.88 mV |
| 3.00V | +20% | 614 | 4.88 mV |
Scaling 120V, 230V, and 3-Phase Mains for ADC Input
A common point of confusion for DIY energy monitor builders is how the answer shifts for 120V vs 230V vs 3-phase systems. An ADC does not natively understand RMS voltage, AC frequencies, or phase angles; it only measures instantaneous DC voltage at the exact microsecond the sample-and-hold circuit triggers.
Therefore, to measure AC mains, you must first step the voltage down to fit within your ADC's V_ref window using a voltage divider or an isolation transformer (like the ZMPT101B module). Here is how the physical scaling shifts based on your grid:
- 120V AC (North America): The nominal 120V RMS actually swings to a 170V peak. Your voltage divider must scale 170V down to your ADC's maximum (e.g., 3.3V). A 100kΩ / 2.2kΩ resistor divider achieves this safely.
- 230V AC (Europe/UK/AU): Nominal 230V RMS hits a 325V peak. You need a much more aggressive divider ratio, such as 220kΩ / 2.2kΩ, to keep the peak voltage under 3.3V.
- 3-Phase 400V (Industrial): Line-to-line 400V RMS yields a terrifying 565V peak. Resistor dividers become dangerous here due to high-side power dissipation and fault risks. For 3-phase, always use galvanically isolated voltage sensors rated for CAT III/IV, scaling the isolated secondary output to your ADC's 0-3.3V range.
V_rms × I_rms to get Watts on inductive loads (like motors). You must sample voltage and current simultaneously at high speeds, calculate the instantaneous power at every step, and integrate it over time to find Real Power.
Hardware Assumptions: Internal vs. External References
The formula (V_in / V_ref) × (2^n - 1) assumes V_ref is perfectly stable. In practice, the hardware you choose dictates your real-world accuracy.
If you are using the internal ADC on an ESP32 (12-bit, 3.3V nominal), you must account for silicon-level non-linearities. The ESP32's internal ADC is notorious for a ~100mV deadzone at the bottom of the scale and compressing values near the 3.3V ceiling. According to Espressif's official ESP32 ADC documentation, the usable linear range is effectively 0.15V to 2.5V. If you feed it 3.0V, the formula breaks down because the internal amplifier saturates.
For precision work, bypass the microcontroller's internal ADC and use an external I2C chip like the TI ADS1115 (16-bit). The ADS1115 features an internal Programmable Gain Amplifier (PGA). If you set the PGA to the ±4.096V range, your V_ref becomes exactly 4.096V, and your LSB drops to a highly precise 0.125mV. The Texas Instruments ADS1115 Datasheet guarantees this linearity, making the math perfectly reliable across the entire scale.
Frequently Asked Questions
How does an analog digital converter handle negative AC voltages?
Standard single-supply ADCs (like those inside Arduinos and ESP32s) cannot read negative voltages; applying a negative voltage to the GPIO pin will fry the internal ESD protection diodes and permanently damage the silicon. To measure AC waveforms that swing below 0V, you must add a DC bias (offset) circuit. This typically involves using an op-amp or a simple resistor network to shift the AC waveform up by half of your V_ref (e.g., shifting a ±1.65V AC signal to swing between 0V and 3.3V), allowing the ADC to read the entire wave. You then subtract this DC offset in your firmware.
Why is my ESP32 analog digital converter reading fluctuating values?
Fluctuating ADC readings (jitter) on an ESP32 or Arduino are almost always caused by high-impedance voltage dividers or missing bypass capacitors. The ADC's internal sample-and-hold capacitor needs a quick burst of current to charge up before the conversion happens. If your source impedance is too high (e.g., using 1MΩ resistors in your divider), the capacitor can't charge in time, resulting in random noise. Fix this by keeping your divider's Thevenin equivalent resistance under 10kΩ, and solder a 100nF ceramic capacitor directly between the ADC input pin and GND to filter high-frequency noise.
What sample rate do I need for 50Hz vs 60Hz AC mains?
The Nyquist-Shannon sampling theorem dictates that you must sample at least twice the highest frequency component of your signal. For a pure 60Hz sine wave, the absolute minimum is 120 Hz. However, to accurately reconstruct the waveform and calculate RMS voltage without aliasing errors, you need a minimum of 16 to 32 samples per AC cycle. For 60Hz mains, aim for a sample rate of at least 1,920 Hz (32 samples × 60Hz). For 50Hz mains, 1,600 Hz is sufficient. If you are measuring non-linear loads (like LED drivers or VFDs) that inject 3rd and 5th harmonics (up to 300Hz), push your ADC sample rate above 10 kHz.






