For a standard 120V RMS mains signal stepped down via a 100:1 ratio into a 12-bit ADC with a 3.3V reference, the peak digital count is 2106 (representing 1.697V peak). The exact formula used is: Count = (V_RMS × √2 / Divider_Ratio) / V_Ref × (2^n - 1). Substituting our baseline values: Count = (120 × 1.414 / 100) / 3.3 × 4095 = 2106. This is the foundational math for any analog to digital converter application targeting AC grid monitoring, but getting from this raw number to a reliable IoT energy monitor requires navigating transformer phase shifts, clipping headroom, and resolution limits.

The Core Conversion Formula and Assumptions

The math above assumes you are sampling the instantaneous AC waveform to calculate RMS in software. To make that 2106 count meaningful, three rigid assumptions fix the answer:

  1. Pure Sine Wave: The √2 (1.414) multiplier only holds true for a perfect sine wave.
  2. Resistive Step-Down: The 100:1 divider is purely resistive, introducing zero phase delay.
  3. Unity Power Factor Sensor: If using an inductive potential transformer (like the common ZMPT101B module), its own phase shift must be calibrated out in software.
When is this conversion meaningless?
If the local grid has high Total Harmonic Distortion (THD > 8%) from heavy VFD or solar inverter loading, or if you are measuring a modified square-wave UPS output, the √2 peak-to-RMS assumption collapses. In these cases, peak-counting is useless; you must use a true-RMS ADC IC (like the ADE9000) or sample at >4kHz and calculate the square root of the mean of the squares in firmware.

Resolution Table: Neighboring Mains Voltages (±20%)

Grid voltage fluctuates. A robust firmware implementation must handle the full ±20% tolerance band without clipping the ADC rail. Here is how the digital counts shift across the standard 120V nominal tolerance window, assuming our 12-bit, 3.3V, 100:1 baseline.

Mains RMS (V) Grid Condition Peak Voltage (V) Scaled Peak (V) 12-Bit ADC Count
96V Brownout (-20%) 135.7 1.357 1684
108V Sag (-10%) 152.7 1.527 1895
120V Nominal 169.7 1.697 2106
132V Swell (+10%) 186.7 1.867 2316
144V Surge (+20%) 203.6 2.036 2527

Note: At 144V, you are only using ~61% of the 3.3V ADC range. To maximize resolution, you would ideally scale the divider so 144V peak maps closer to 3.1V (leaving 0.2V headroom for op-amp saturation limits).

How the Math Shifts: 120V vs 230V vs 3-Phase

Treating a 120V calculation as universal will brick your measurement headroom when deployed internationally or in industrial panels.

The 230V Clipping Danger

If you deploy the exact same 100:1 hardware to a European 230V nominal grid, the math shifts dramatically: (230 × 1.414 / 100) / 3.3 × 4095 = 4036. A count of 4036 leaves only 59 counts of headroom before hitting the 4095 rail. A minor grid swell or appliance switching transient will clip the waveform, resulting in a falsely low RMS calculation in your firmware. Fix: Change the divider ratio to 180:1 for 230V systems.

3-Phase Line-to-Line Measurements

Measuring 3-phase isn't just about reading three channels; it's about the voltage potential. If you are measuring Line-to-Line (e.g., 208V in North America or 400V in Europe) rather than Line-to-Neutral, the voltage is higher by a factor of √3 (1.732). A 208V L-L signal yields a peak count of 3648 on our 100:1 baseline. You must scale your front-end resistors to handle the L-L peak, not the L-N peak, or your isolation amplifiers will saturate.

Decision Tree: Picking Your ADC and Front-End

Don't default to your microcontroller's internal ADC for mains sensing. Use this decision matrix to select the right silicon for your analog to digital converter application.

Application Requirement If True... Then Choose...
Basic trend monitoring (is voltage above/below 115V?) Cost is primary, precision is secondary ESP32 internal 12-bit ADC + ZMPT101B module
Energy metering (calculating kWh with < 1% error) Need high resolution & low noise External 16-bit I2C ADC + Precision Op-Amp
UL/CE certified commercial product Requires galvanic isolation from mains Sigma-Delta Isolated ADC + Shunt/Divider
The Concrete Pick for Prosumer IoT:
If you are building a high-accuracy home energy monitor in 2026 and want to bypass the ESP32's notorious ADC non-linearity, terminate your decision path here: Use the Texas Instruments ADS1115 (16-bit, I2C, 4.096V internal reference) paired with the TI AMC1301 isolated amplifier for the front end. The AMC1301 provides the mandatory galvanic isolation (reinforced isolation rating) while outputting a clean differential signal that the ADS1115 can digitize with 0.1% accuracy.

FAQ: Edge Cases in Mains ADC Sensing

Why does my RMS calculation read 5% low on a bench variac?

You are likely calculating RMS by simply dividing the peak ADC count by √2. This only works for perfect sine waves. If your variac has wiper noise or your grid has flat-topping from rectifier loads, you must sample at least 64 times per cycle (e.g., 3840 Hz for 60Hz) and compute the true root-mean-square in code. See the Espressif ADC oneshot documentation for configuring high-speed DMA sampling on the ESP32.

Can I use a simple resistive divider without an isolation amplifier?

For bench testing, yes, if you use high-value megohm resistors to limit fault current. For any permanent installation, absolutely not. A failed resistor or a wiring mistake will feed 120V/230V directly into your microcontroller's GPIO, destroying the chip and creating a severe shock hazard via the USB cable. Always use an isolation IC like the AMC1301 or an optocoupler-based linear isolator in permanent mains-facing gear.

How do I handle the DC offset in AC voltage transformers?

Small PCB-mount AC transformers (like the ZMPT101B) output a bipolar AC signal (e.g., ±1.5V). Since single-supply ADCs cannot read negative voltages, you must add a DC bias circuit (a voltage divider from VCC to GND, buffered by an op-amp) to shift the signal to VCC/2 (1.65V). In firmware, you subtract this 1.65V offset (approx. ADC count 2048 on a 12-bit system) from every sample before squaring it for the RMS calculation.