If you've wired a potentiometer to an ESP32, seen it work perfectly, then watched it return zeros the moment you added Wi-Fi, you've met the most famous quirk of this chip: the analog-to-digital converter is split in two, and one half belongs to the Wi-Fi driver while it's running.
Quick answer: on the original ESP32, read analog sensors on the ADC1 pins: GPIO 32, 33, 34, 35, 36 and 39. They work with Wi-Fi on. Use analogReadMilliVolts() instead of analogRead() to get calibrated millivolts. At the default 11 dB attenuation the accurate range is about 0.15–2.45 V, and the pin must never see more than 3.3 V, so divide anything bigger (a battery, 5 V or 12 V) with two resistors first.
That's the short version. The rest of this guide covers the full pin map, attenuation, calibration, noise, battery and 12 V dividers, the differences on the S3, C3 and C6, and MicroPython code.
ADC1 vs ADC2: The Rule You Must Know
The original ESP32 has two 12-bit SAR ADCs with 18 channels between them, and they are not equal.
| ADC | Channel | GPIO | Notes |
|---|---|---|---|
| ADC1 | CH0 | 36 (VP) | Input-only |
| CH3 | 39 (VN) | Input-only | |
| CH4 | 32 | ||
| CH5 | 33 | ||
| CH6 | 34 | Input-only | |
| CH7 | 35 | Input-only | |
| ADC2 | CH0 | 4 | |
| CH1 | 0 | Strapping pin (BOOT button) | |
| CH2 | 2 | Strapping pin; onboard LED on many boards | |
| CH3 | 15 | Strapping pin | |
| CH4 | 13 | ||
| CH5 | 12 | Strapping pin (flash voltage) | |
| CH6 | 14 | ||
| CH7 | 27 | ||
| CH8 | 25 | Also DAC1 | |
| CH9 | 26 | Also DAC2 |
ADC1 CH1 and CH2 (GPIO 37 and 38) exist on the chip but aren't broken out on common dev boards.
ADC2 is shared with the Wi-Fi driver. From WiFi.begin() (or WiFi.mode()) until Wi-Fi is switched off, the radio owns ADC2 and analogRead() on an ADC2 pin fails or returns junk. Bluetooth alone doesn't cause this. If you really need an ADC2 pin, call WiFi.mode(WIFI_OFF) before reading and reconnect afterwards; for anything connected, it's much simpler to pick ADC1.
The practical rule: projects with Wi-Fi, MQTT, a web server or ESP-NOW read analog sensors on GPIO 32, 33, 34, 35, 36 or 39. ADC2 pins are fine for analog only in sketches that never start Wi-Fi, and four of them (0, 2, 12, 15) are strapping pins that a sensor can upset at boot anyway.
GPIO 34, 35, 36 and 39 are input-only and have no internal pull-up or pull-down, which suits analog inputs well.
Reading an Analog Value
The simplest reading is one line:
const int SENSOR_PIN = 34; // ADC1 channel 6
void setup() {
Serial.begin(115200);
}
void loop() {
int raw = analogRead(SENSOR_PIN); // 0 to 4095
Serial.println(raw);
delay(200);
}The default resolution is 12 bits, so the output ranges from 0 to 4095, unlike the 10-bit 0 to 1023 range on an Arduino Uno. You can ask for a different width, and the core scales the 12-bit result to fit:
analogReadResolution(10); // now returns 0 to 1023Wire a 10 kΩ potentiometer with the outer legs to 3.3V and GND and the middle leg to GPIO 34. The raw value should run from near 0 to near 4095 as you turn it.
Never connect more than 3.3V to an ADC pin. The inputs are not 5V tolerant, and exceeding about 3.6V can damage the chip.
Each analogRead() takes in the order of tens of microseconds, which is plenty for sensors. For audio-rate sampling, use the continuous (DMA) mode, analogContinuous() in Arduino-ESP32 core 3.x, instead of calling analogRead() in a fast loop.
Attenuation: Choosing Your Voltage Range
The ADC core itself measures only about 0–1.1 V. An input attenuator scales larger signals down first, and you choose how much with analogSetAttenuation() (all pins) or analogSetPinAttenuation() (one pin). These are Espressif's recommended ranges for the original ESP32, where readings are accurate:
| Setting | Constant | Accurate range |
|---|---|---|
| 0 dB | ADC_0db | 100 – 950 mV |
| 2.5 dB | ADC_2_5db | 100 – 1250 mV |
| 6 dB | ADC_6db | 150 – 1750 mV |
| 11 dB | ADC_11db | 150 – 2450 mV |
The Arduino core defaults to 11 dB (called 12 dB in newer ESP-IDF documentation; it's the same setting). Above about 2.45 V the reading still rises, but less accurately, and it hits 4095 at roughly 3.1 V. Anything from 3.1 V to 3.3 V reads the same. Below about 150 mV the reading sticks near 0.
analogSetPinAttenuation(34, ADC_11db); // sensors up to ~2.45 V accuratelyChoose the smallest attenuation that covers your signal. A sensor that only swings between 0 and 1 V reads more accurately at 2.5 dB than at 11 dB, and design dividers so the important values fall inside the accurate range, not near the ends.
Getting Real Voltages: analogReadMilliVolts
Raw counts are not volts, and the relationship is not a straight line. The ESP32 ADC is noticeably non-linear near 0V and near the top of the range. A reading of 2048 does not mean exactly half scale.
Espressif calibrates each chip at the factory and stores correction data in eFuse. The Arduino function analogReadMilliVolts() uses that data and returns a calibrated value directly in millivolts:
const int SENSOR_PIN = 34;
void setup() {
Serial.begin(115200);
analogSetPinAttenuation(SENSOR_PIN, ADC_11db);
}
void loop() {
int mv = analogReadMilliVolts(SENSOR_PIN);
Serial.printf("%d mV (%.2f V)\n", mv, mv / 1000.0);
delay(500);
}Compare it with a multimeter reading on a known voltage. A difference of tens of millivolts is normal on this chip. If you need better than about 1 to 2 percent accuracy, add an external ADC such as the ADS1115 over I2C, which offers 16 bits and a stable reference.
On the original ESP32 the ends of the range are the weak point, so avoid designing a circuit whose important values sit below about 150 mV or above about 2.45V at 11 dB. Some very early ESP32 chips (2016 and before) have no calibration data in eFuse; on those, analogReadMilliVolts() falls back to a generic curve and is less accurate.
Cleaning Up a Noisy Reading
ESP32 analog readings jitter, often by 10 to 50 counts even on a steady voltage. Three fixes work well together.
1. Average multiple samples.
int readAveraged(int pin, int samples = 32) {
long sum = 0;
for (int i = 0; i < samples; i++) {
sum += analogReadMilliVolts(pin);
delayMicroseconds(100);
}
return sum / samples;
}2. Add a small capacitor. A 100 nF ceramic capacitor between the ADC pin and GND filters high-frequency noise, especially on a long wire or a high-impedance source.
3. Smooth over time with an exponential filter.
float smoothed = 0;
const float ALPHA = 0.1; // lower = smoother but slower
void loop() {
int mv = analogReadMilliVolts(34);
smoothed = ALPHA * mv + (1 - ALPHA) * smoothed;
Serial.println(smoothed);
delay(50);
}Also keep analog wires short, route them away from the WiFi antenna and away from motor or relay wiring, and power the sensor from the stable 3.3V pin rather than from a noisy supply.
Measuring Higher Voltages With a Voltage Divider
To read a battery or any source above 3.3V, scale it down with two resistors before it reaches the pin.
Vin --- R1 ---+--- ADC pin
|
R2
|
GNDThe voltage at the pin is Vout = Vin × R2 / (R1 + R2).
Example: monitoring a single-cell lithium battery (4.2V full, 3.0V empty) with two equal 100 kΩ resistors halves the voltage to a safe 2.1V at full charge.
const int BATT_PIN = 35;
const float DIVIDER_RATIO = 2.0; // (R1 + R2) / R2 with 100k + 100k
float readBatteryVoltage() {
int mv = analogReadMilliVolts(BATT_PIN);
return (mv * DIVIDER_RATIO) / 1000.0;
}
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.printf("Battery: %.2f V\n", readBatteryVoltage());
delay(2000);
}A 100 k + 100 k divider draws 4.2 V / 200 kΩ = 21 µA all the time. That's negligible while the ESP32 is awake, but in deep sleep it's as much as the chip itself, so on a deep-sleep project either use 1 MΩ + 1 MΩ (about 2 µA) or switch the divider's ground through a small MOSFET and turn it on only to take a reading. Whatever values you use, and add a 100 nF capacitor from the ADC pin to GND so the high-impedance divider has a stable source for the sampling capacitor. Higher resistor values give more noise, so adjust to your needs.
For a 12V system, plan for the highest voltage it will really reach. A lead-acid battery on charge sits around 14.4 V. With 100 kΩ on top and 18 kΩ on the bottom, 14.4 V becomes 14.4 × 18 / 118 = 2.20 V, and a resting 12.6 V becomes 1.92 V, both inside the accurate 11 dB range. Set DIVIDER_RATIO to 118 / 18 = 6.56.
| Source | Max voltage | R1 (top) | R2 (bottom) | Pin voltage at max | Ratio |
|---|---|---|---|---|---|
| 1-cell Li-ion / LiPo | 4.2 V | 100 kΩ | 100 kΩ | 2.10 V | 2.00 |
| USB / 5 V rail | 5.25 V | 100 kΩ | 68 kΩ | 2.13 V | 2.47 |
| 2-cell Li-ion | 8.4 V | 100 kΩ | 39 kΩ | 2.36 V | 3.56 |
| 12 V lead-acid (charging) | 14.4 V | 100 kΩ | 18 kΩ | 2.20 V | 6.56 |
For calibration, measure the source with a multimeter, compare it with the ESP32's reading, and adjust DIVIDER_RATIO slightly to absorb resistor tolerance.
Common Sensors on the ESP32 ADC
| Sensor | Wiring | Notes |
|---|---|---|
| Potentiometer | 3.3V, GND, wiper to ADC1 pin | Ideal first test |
| LDR (light) | Voltage divider with a 10 kΩ resistor | Reads brightness; calibrate by observation |
| Soil moisture (analog) | 3.3V supply, signal to ADC1 pin | Power from 3.3V, not 5V, so the signal stays within range |
| MQ gas sensors | Often 5V powered | Use a divider on the analog output |
| Thermistor | Divider with a fixed resistor | Needs the Steinhart-Hart equation for degrees |
| TMP36 | 3.3V supply | Output is 10 mV per degree plus a 500 mV offset |
Always power analog modules from 3.3V, or divide their output if they run on 5V. A 5V module outputting 4.5V into an ESP32 pin will damage it.
ADC on the ESP32-S2, S3, C3 and C6
Newer chips use different pins, and the ADC2 story changes:
| Chip | ADC1 pins | ADC2 pins | ADC2 with Wi-Fi |
|---|---|---|---|
| ESP32 | 32–39 (6 on dev boards) | 0, 2, 4, 12–15, 25–27 | Not usable |
| ESP32-S2 | GPIO 1–10 | GPIO 11–20 | Shared; reads can fail |
| ESP32-S3 | GPIO 1–10 | GPIO 11–20 | Shared; reads can fail |
| ESP32-C3 | GPIO 0–4 | GPIO 5 | Avoid ADC2 entirely (errata) |
| ESP32-C6 | GPIO 0–6 | None | — |
The same rule works everywhere: put analog sensors on ADC1. The newer chips also have better factory calibration, and their usable ranges differ (about 0–3.1 V at the highest attenuation on the S3, about 0–2.5 V on the C3), so check your chip's pinout guide: ESP32-S3, ESP32-C3, ESP32-C6.
Reading the ADC in MicroPython
MicroPython's ADC class does the same job, and read_uv() returns a calibrated value in microvolts:
from machine import ADC, Pin
from time import sleep
adc = ADC(Pin(34), atten=ADC.ATTN_11DB) # ADC1, ~0.15–2.45 V accurate
while True:
mv = adc.read_uv() // 1000
print(mv, "mV")
sleep(0.5)Use read_u16() for a raw 0–65535 value. The same ADC1/ADC2 rule applies: with network.WLAN active, stick to GPIO 32–39. New to MicroPython? Start with installing MicroPython on the ESP32.
Common Problems and Fixes
| Symptom | Cause | Fix |
|---|---|---|
| Reads 0 or garbage once Wi-Fi connects | Pin is on ADC2 | Move to GPIO 32, 33, 34, 35, 36 or 39 |
| Stuck at 4095 | Input above ~3.1 V, or above the range for the attenuation you set | Add a divider, or use 11 dB |
| Reads 0 for small voltages | Below ~100–150 mV the ESP32 ADC doesn't respond | Lower attenuation, offset the signal, or use an ADS1115 |
| Readings jump around | Noise from Wi-Fi, long wires or a high-impedance source | Average samples, 100 nF capacitor to GND, shorter wires |
| Differs from the multimeter | Raw counts used, or chip tolerance | Use analogReadMilliVolts(); trim the divider ratio |
| Random values with nothing connected | Floating input | Normal. Connect the source or a pull-down resistor |
| Board won't boot with a sensor attached | Sensor on GPIO 0, 2, 12 or 15 | Move it to an ADC1 pin |
| Odd glitches on GPIO 36 or 39 | These pins are tied to internal circuits that can inject brief pulses | Use GPIO 32–35 first |
For more accuracy than the ESP32 can give, the ADS1115 is the usual upgrade: 16-bit, four channels, I2C on the same two pins as your other sensors.
Frequently Asked Questions
How many analog pins does the ESP32 have? 18 channels on the chip. A common 30-pin board exposes 15: six on ADC1 and nine on ADC2. Only the six ADC1 pins work while Wi-Fi is on.
Which ESP32 pin is best for analog input? GPIO 34 or 35: ADC1, input-only, no boot function, and on every common dev board.
Is the ESP32 ADC accurate? Within a few percent with analogReadMilliVolts() inside the recommended range. Good enough for batteries, potentiometers and most hobby sensors; use an external ADC for measurement work.
Can I use ADC2 at all? Yes, in sketches that never start Wi-Fi, or by turning Wi-Fi off before each reading. For connected projects, use ADC1.
What is the maximum input voltage? 3.3 V absolute on the pin. Readings are accurate up to about 2.45 V at the default attenuation and saturate around 3.1 V.
Can the ESP32 read 5 V sensors? Not directly. Power the sensor from 3.3 V if it allows, or divide its output (100 kΩ over 68 kΩ for 5 V).
analogRead or analogReadMilliVolts? analogReadMilliVolts() almost always. It applies the chip's calibration, so 1,500 means 1.5 V.
For the full map of every pin, see the ESP32 pinout guide. For battery projects that sleep between readings, the ESP32 deep sleep and battery life guide shows how to make one cell last months.




