Quick Fix: Record the ESP32 chip, ADC pin and attenuation setting. Confirm the input is within a safe, stable range, then compare the measured voltage with raw and calibrated readings. Check wiring and supply before adding filtering.

The ESP32 ADC is not a laboratory voltmeter. Its measurable range, pin mapping, calibration support, and interaction with Wi-Fi vary by chip family and software core. A 12-bit reading does not promise 12-bit accuracy. This guide provides a repeatable method for analog sensors and explains what each correction can and cannot fix.

Separate a real signal change from ADC noise

Start with the sensor disconnected from the application logic but still connected to its intended low-voltage supply. Watch whether the symptom appears only when Wi-Fi, a display, or another digital load is active. If the sensor output itself changes, investigate the sensor, supply, reference, ground, and wiring. If the pin voltage is stable on a multimeter but the ADC code moves, investigate sampling, attenuation, source impedance, calibration, and the conversion path.

A multimeter averages over time and can hide fast fluctuations; the ADC samples at particular instants and can reveal them. Conversely, a slowly changing sensor may be responding correctly to light, temperature, motion, or a changing battery. Record a short series of values under one fixed condition before changing the circuit.

ESP32 board connected to a potentiometer on a breadboard.
ESP32 board and potentiometer connected on a breadboard.

Check the pin, input voltage, and attenuation

Use the pinout for your exact ESP32 variant and development board. Some GPIOs are input-only, some are reserved for flash or other functions, and the available ADC channels differ across ESP32, S2, S3, C3, C6, and other families. On the original ESP32, ADC2 shares resources with Wi-Fi in some software paths; this can block or disrupt particular ADC2 reads. Do not apply that rule blindly to every newer chip or driver. Prefer a documented, available ADC pin and confirm the behavior for the core and driver you actually use.

Attenuation expands the measurable ADC range, but the range is chip-specific. Espressif's Arduino documentation, for example, lists different millivolt ranges for original ESP32, S2/C3, and S3 at the same setting. These are measurement ranges, not permission to exceed the GPIO's absolute maximum voltage. Never apply 5 V to an ESP32 input. Check both the board schematic and the chip datasheet, including the divider or sensor output at its highest possible value.

Compare the configured attenuation with the signal range. A low signal may sit near the bottom of a range where noise is a larger fraction of the reading; a high signal may clip near the top. Clipping can look like a stuck sensor rather than ordinary noise. Change only one setting at a time and note the raw and converted result.

Make the first measurement reproducible

  1. Record the board model, chip variant, Arduino-ESP32 or ESP-IDF version, GPIO number, attenuation, and sensor supply.
  2. Keep the sensor and ADC ground connected to the board's documented ground. Shorten long jumper wires and move the analog wire away from switching or radio wiring.
  3. Use a steady input such as a correctly wired potentiometer or a fixed sensor condition. Do not leave an ADC pin floating; a floating input can pick up nearby electrical fields.
  4. Log at a modest, fixed rate. Capture enough samples to see minimum, maximum, and a typical value, but do not interpret a large sample count as proof of accuracy.
  5. Measure the pin relative to board ground with a multimeter while the circuit is operating. If the input is outside the chip's permitted range, disconnect it before continuing.
Short analog sensor wiring and a small bypass capacitor near the ESP32 board
Keep the analog path short; a bypass capacitor is an option to evaluate for a slowly varying input, not a universal fix.

Raw counts, calibrated millivolts, and filtering

On Arduino-ESP32, analogRead() returns an ADC code according to the configured resolution; analogReadMilliVolts() returns a calibrated millivolt estimate where supported. Calibration can reduce conversion error using chip-specific calibration information. It does not remove noise already present on the pin, make every point equally linear, or turn the ADC into a precision instrument. If millivolts look wrong, confirm that you selected the correct pin and attenuation and that the measurement is within the documented range.

For a slowly varying quantity, average a small fixed group of samples. Averaging reduces uncorrelated random noise but also slows the response and does not correct a wrong voltage divider, ground offset, clipping, periodic interference, or a biased ADC. A median can reject an occasional spike, but may conceal a real short event. Choose the filter to match how quickly the sensor is allowed to change.

const int sensorPin = YOUR_DOCUMENTED_ADC_PIN;
uint32_t totalMv = 0;
const unsigned samples = 16;
for (unsigned i = 0; i < samples; ++i) {
  totalMv += analogReadMilliVolts(sensorPin);
  delay(2);
}
uint32_t meanPinMv = totalMv / samples;

This is an illustrative Arduino-ESP32 pattern, not a universal pin example. Replace the placeholder with a valid ADC GPIO for the exact board, then verify the function signature and calibration behavior for your installed core. The reported value is the voltage at the ADC pin, not automatically the original sensor or battery voltage.

ESP32 sensor circuit beside a laptop with a blurred code editor.
ESP32 board and potentiometer beside a blurred code editor on a laptop.

When a capacitor helps, and when it hurts

Espressif documents the ADC's sensitivity to noise and notes that a bypass capacitor, such as 100 nF at the ADC input pad, and multisampling may help in some scenarios. Treat this as a design option, not an automatic recipe. A capacitor forms a low-pass network with the source resistance. That can reduce high-frequency noise, but it also delays changes. A high-impedance sensor may need a buffer or a carefully selected time constant; a fast signal may be distorted by the added capacitance.

Place any capacitor near the ADC input and its return ground as the circuit design requires. Test with and without it under the same conditions. If the output becomes stable but reacts too slowly, the filter is not suitable for the required response. Do not use a capacitor to hide an unstable power rail, a poor ground, a loose connector, or a sensor fault.

Decision table

What a changing ADC reading suggests
ObservationLikely explanationNext check
Pin voltage changes on the meter and ADC followsThe sensor, reference, or supply is changingMeasure sensor supply and output; test with a fixed input
Pin voltage looks steady but counts scatterADC noise, source impedance, sampling, or measurement bandwidthUse the correct attenuation; shorten wiring; compare calibrated millivolts and a small sample average
Reading sticks at a low or high valueWrong pin, clipping, open wiring, or an out-of-range inputCheck pin mapping, continuity while unpowered, input range, and attenuation
Reading fails only with Wi-Fi onPossibly ADC2 resource conflict on affected chip/software combinationsCheck the exact variant and driver; test a documented ADC1 or other supported channel
Capacitor stabilizes value but makes response sluggishLow-pass time constant is too long for the signalChoose a smaller time constant or buffer the source

Common mistakes and stopping criteria

Do not map a reading directly to volts using only the nominal resolution and a presumed 3.3 V full scale. The actual ADC transfer curve and range depend on the chip, attenuation, calibration, and board. Do not connect an unknown sensor until its maximum output and ground reference are known. Do not measure resistance or continuity on an energized circuit.

If readings remain unstable with a fixed, safe input, short wiring, and a known-good board supply, test another documented ADC pin and compare with a second board of the same family. Stop if the board or sensor overheats, the input may exceed its allowed voltage, or the measured ground is not the circuit reference you expect. For battery monitoring with a divider, see the separate guide on calculating the divider and reconstructing the battery voltage.

Frequently asked questions

Does a 12-bit ADC provide 4096 accurate voltage steps?

No. Resolution describes output codes, not absolute accuracy or linearity. Reference variation, attenuation, calibration, noise, and the board's analog layout affect the useful measurement.

Should I always use ADC1 when Wi-Fi is enabled?

That is an important check for the original ESP32 and some legacy paths, but chip families and drivers differ. Verify the current documentation for your specific target rather than assuming a single rule applies to all ESP32 devices.

Will averaging fix a noisy sensor?

It can reduce uncorrelated sample variation for a slow signal. It cannot correct an unstable sensor supply, wrong pin, clipping, ground error, or a real changing input.

Can I use the ADC as a battery percentage meter?

The ADC can estimate a divided battery voltage when designed within the pin limits and calibrated for the board. Battery state of charge is not a linear function of voltage for many chemistries, so voltage alone may be a rough estimate rather than an exact percentage.

Compare variation instead of judging one sample

For each controlled condition, collect a short series and record the minimum, median or mean, and maximum in the same units. The spread describes repeatability for that setup; it is not the ADC’s absolute accuracy. Repeat the series with a stable fixed input, then with the real sensor. If both vary similarly, inspect the analog path and board supply. If only the sensor varies, investigate its output, excitation and physical environment.

Next, change one variable: Wi-Fi on or off, a shorter signal lead, a different documented ADC pin, or the recommended attenuation. Keep the sample rate and sensor condition constant. A repeatable change after one modification is useful evidence, but it does not prove that every other possible cause is absent. Restore the original setting before the next comparison so that several changes do not become entangled.

For a slow sensor, an exponential filter can smooth display noise while responding more quickly than a long block average. A simple form is filtered = filtered + alpha × (sample − filtered), where a smaller alpha gives more smoothing but slower response. Choose alpha from the application’s response time, not by trying to make the serial monitor look perfectly still. For alarms or control loops, preserve enough raw samples to detect short events instead of filtering away a condition that matters.

Why the same ADC pin may not repeat exactly

The ADC input is not an ideal voltmeter. Its conversion circuit samples the pin, so a high-impedance source may not charge the internal sampling network quickly enough. Nearby switching signals can couple into a long analog lead, and changes in board ground can appear as changes at the sensor. The ADC reference and transfer curve also vary between chips. These mechanisms can coexist, so a noisy-looking number is not a component diagnosis by itself.

Use the sensor datasheet to learn its output impedance and required load. If the sensor expects a high-impedance input but the ADC behaves poorly, a suitable buffer amplifier may be preferable to lowering divider resistance blindly. Check that the amplifier input common-mode range and output swing suit both the sensor and the selected ESP32 variant. A capacitor can help only when its time constant and the signal bandwidth fit the application.

When comparing raw codes with millivolts, remember that the two representations answer different questions. Raw codes show the conversion output; calibrated millivolts estimate the pin voltage using the available calibration scheme. Neither automatically reconstructs a sensor quantity. Apply the sensor’s own transfer equation only after the electrical pin voltage is credible, and include its offset, gain, and operating conditions.

Technical sources