Blog
ESP32 ADC: Analog Input, Resolution, Attenuation
Does esp32 have analog pins? Yes — 18 on the classic chip, and none behave like an Arduino’s. Attenuation, resolution, and the ADC2-versus-Wi-Fi fight, in practice.
Does ESP32 Have Analog Pins?
Yes — 18 analog channels across two SAR ADCs, multiplexed onto ordinary GPIOs, not a dedicated analog header. Range is 0-3.3V at most, and what you can reach depends on the board. Two gotchas shape everything: usable range is set by attenuation, and one ADC block fights Wi-Fi — both below.
How Many Analog Pins in ESP32?
18 channels: ADC1 owns GPIO32-39 (8 pins), ADC2 owns GPIO0, 2, 4, 12-15, 25-27 (10 pins). A 38-pin DevKitC reaches all of them; 30-pin boards drop 37/38. Newer families differ — S3 has 20, C3 has 6 — so count what your board exposes.
How to Read Analog Input in ESP32?
One call: analogRead(pin) returns 0-4095 on current cores (12-bit, 11dB attenuation by default). If you searched “how to read the adc on esp32”, that’s the API — plus analogReadMilliVolts(pin) for calibrated millivolts, which is what you want for real voltage.
How to Set ESP32 ADC Resolution?
analogReadResolution(bits) — 9 to 12 bits; 12 means 0-4095. Effective resolution lands around 10-11 bits because of noise — average 16-64 samples instead of chasing the last bit. The “how to use adc in esp32” version: set resolution once, attenuation per pin, then read. analogSetPinAttenuation(pin, ADC_11db) widens to ~3.1V; ADC_2_5db suits 0-1V sensors.
Which ESP32 Pins to Use for Analog Input?
Prefer ADC1 — GPIO32-39 — because ADC2 shares silicon with the radio: once Wi-Fi connects, ADC2 reads go quiet and return stale values. My water-level logger froze at a fixed reading the day I added Wi-Fi — that trap isn’t loud enough in the docs. GPIO34-39 are also input-only. Never exceed 3.3V on an ADC pin; the power FAQ has voltage rules.
What exactly is the ADC measuring?
A successive-approximation converter: sample the pin, compare against an internal reference, write a 12-bit number. People typing “what is adc esp32” get datasheet-speak; the practical version is a 0-3.3V window chopped into 4096 steps, with error growing fastest at the bottom ~150mV and top ~500mV. Hardware details: the under-the-hood FAQ.
Why are my readings noisy or off?
Four usual causes, in order of how often I’ve seen them: attenuation unset, Wi-Fi ground noise, long leads, and the ADC’s own nonlinearity. The honest answer to how to increase the accuracy of analog read on esp32: oversample — 32-64 reads averaged — and trust analogReadMilliVolts() over raw counts; it applies the factory efuse calibration. Short wires and a 100nF cap help; at 11dB the top saturates around 3.1V.
Can I use ADC pins as digital pins?
Yes, both ways — “can analog pins be used as digital esp32” is a common worry, and ADC pins are just GPIOs with an extra converter attached; digitalRead() doesn’t hurt the ADC. Can ESP32 ADC pins be digital? Same answer, one wall: GPIO34-39 stay input-only.
How fast can the ESP32 sample?
The ADC hardware samples around 2M times per second; analogRead() and your loop are the bottleneck, landing practical rates in the tens of kHz. For steady 20kHz — the “how to set a 20khz analog read in the esp32” crowd — use a timer ISR reading every 50µs, or IDF continuous ADC mode with DMA.
Which pins are analog on a NodeMCU-style board?
On 30-pin NodeMCU-style boards, the ADC1 pins are labeled VP (GPIO36, ADC0), VN (GPIO39, ADC3) and D32-D35 (ADC4-7). If you searched “which pin are analog on esp32 nodemcu”, that’s the set; the right header holds ADC2 (D25-27, D12-15, D0, D2, D4), which shares with Wi-Fi.
See ADC Resolution and Attenuation Live — In Your Browser
Two free simulator examples make the spec sheet tangible:
- Dual-channel ADC — two analog pins read side by side, printed as volts:
CH1=1.653V CH2=0.827V
Turn either virtual pot and watch the conversion track it — roughly half the supply reads about half the volts, exactly as the attenuation math predicts.
- Joystick — the same ADC blocks, reported as raw counts and percentage:
X= 512( 50%) Y=2048( 99%) BTN=---
Same pins, same 12-bit converter — one sketch shows you the engineering units, the other the counts underneath.