Skip to content

Tutorial

ESP32 ADC Pins: analogRead, ADC1 vs ADC2, Attenuation and Calibration

Why ESP32 analogRead stops working with WiFi, which pins belong to ADC1 and ADC2, how attenuation sets your voltage range, why readings are non-linear, and how to get accurate millivolt values with calibration and averaging.

  • 7 min read
  • Updated October 31, 2026
ESP32 ADC Pins: analogRead, ADC1 vs ADC2, Attenuation and Calibration

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.

ADCChannelGPIONotes
ADC1CH036 (VP)Input-only
CH339 (VN)Input-only
CH432
CH533
CH634Input-only
CH735Input-only
ADC2CH04
CH10Strapping pin (BOOT button)
CH22Strapping pin; onboard LED on many boards
CH315Strapping pin
CH413
CH512Strapping pin (flash voltage)
CH614
CH727
CH825Also DAC1
CH926Also 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:

sketch.ino
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:

sketch.ino
analogReadResolution(10); // now returns 0 to 1023

Wire 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:

SettingConstantAccurate range
0 dBADC_0db100 – 950 mV
2.5 dBADC_2_5db100 – 1250 mV
6 dBADC_6db150 – 1750 mV
11 dBADC_11db150 – 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.

sketch.ino
analogSetPinAttenuation(34, ADC_11db); // sensors up to ~2.45 V accurately

Choose 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:

sketch.ino
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.

sketch.ino
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.

sketch.ino
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.

Output
Vin --- R1 ---+--- ADC pin
              |
              R2
              |
             GND

The 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.

sketch.ino
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.

SourceMax voltageR1 (top)R2 (bottom)Pin voltage at maxRatio
1-cell Li-ion / LiPo4.2 V100 kΩ100 kΩ2.10 V2.00
USB / 5 V rail5.25 V100 kΩ68 kΩ2.13 V2.47
2-cell Li-ion8.4 V100 kΩ39 kΩ2.36 V3.56
12 V lead-acid (charging)14.4 V100 kΩ18 kΩ2.20 V6.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

SensorWiringNotes
Potentiometer3.3V, GND, wiper to ADC1 pinIdeal first test
LDR (light)Voltage divider with a 10 kΩ resistorReads brightness; calibrate by observation
Soil moisture (analog)3.3V supply, signal to ADC1 pinPower from 3.3V, not 5V, so the signal stays within range
MQ gas sensorsOften 5V poweredUse a divider on the analog output
ThermistorDivider with a fixed resistorNeeds the Steinhart-Hart equation for degrees
TMP363.3V supplyOutput 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:

ChipADC1 pinsADC2 pinsADC2 with Wi-Fi
ESP3232–39 (6 on dev boards)0, 2, 4, 12–15, 25–27Not usable
ESP32-S2GPIO 1–10GPIO 11–20Shared; reads can fail
ESP32-S3GPIO 1–10GPIO 11–20Shared; reads can fail
ESP32-C3GPIO 0–4GPIO 5Avoid ADC2 entirely (errata)
ESP32-C6GPIO 0–6None—

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:

main.py
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

SymptomCauseFix
Reads 0 or garbage once Wi-Fi connectsPin is on ADC2Move to GPIO 32, 33, 34, 35, 36 or 39
Stuck at 4095Input above ~3.1 V, or above the range for the attenuation you setAdd a divider, or use 11 dB
Reads 0 for small voltagesBelow ~100–150 mV the ESP32 ADC doesn't respondLower attenuation, offset the signal, or use an ADS1115
Readings jump aroundNoise from Wi-Fi, long wires or a high-impedance sourceAverage samples, 100 nF capacitor to GND, shorter wires
Differs from the multimeterRaw counts used, or chip toleranceUse analogReadMilliVolts(); trim the divider ratio
Random values with nothing connectedFloating inputNormal. Connect the source or a pull-down resistor
Board won't boot with a sensor attachedSensor on GPIO 0, 2, 12 or 15Move it to an ADC1 pin
Odd glitches on GPIO 36 or 39These pins are tied to internal circuits that can inject brief pulsesUse 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.

Continue learning

Related articles

All articles

Signal In

Built from what makers search for

The lookups piling up in SolderHub's search bar every day shape what we publish next — new component pages, board guides, and firmware notes, sent out as they go live.

By subscribing you agree to our Privacy Policy. Unsubscribe anytime.