Fix: ESP32 analogRead not working with Wi-Fi on (ADC2)
analogRead() on GPIO 0, 2, 4, 12–15 or 25–27 returns 0 or garbage once Wi-Fi starts. Those are ADC2 pins; move the sensor to ADC1 (GPIO 32–39).
Community draft — report a mistake
What you see
Soil raw: 2310 (before WiFi.begin)
Connecting to Wi-Fi... connected
Soil raw: 0
Soil raw: 0
Soil raw: 0Soil raw: 2310 (before WiFi.begin) Connecting to Wi-Fi... connected Soil raw: 0 Soil raw: 0 Soil raw: 0
This is a hardware limitation of the original ESP32, not a bug in your code: the ADC2 converter is shared with the Wi-Fi radio. The fix is simply to use an ADC1 pin.
Quick fix — try in order
- 1
Move the sensor to an ADC1 pin
On the ESP32 DevKit V1 use GPIO 32, 33, 34, 35, 36 (VP) or 39 (VN). They keep working with Wi-Fi on.
- 2
Change the pin in your sketch
Update the #define or const for the analog pin and re-upload.
- 3
Remember 34–39 are input-only
They are ideal for analog sensors but cannot drive outputs.
Why it happens
Why does Wi-Fi block ADC2?
On the original ESP32 the Wi-Fi driver uses the ADC2 hardware. While Wi-Fi is active, ADC2 reads fail and Arduino returns 0 or an error value.
Which pins are ADC2?
GPIO 0, 2, 4, 12, 13, 14, 15, 25, 26, 27. Filter the interactive pinout by ADC to see them.
Does this affect ESP32-S3 / C3?
Newer chips share the ADC differently, but ADC1 is still the safe choice for anything read while Wi-Fi runs.
Board-specific notes
ESP32 DevKit V1: Our pin checker warns about ADC2 pins when you tick “Wi-Fi used”.
Parts: Capacitive soil sensor · LDR module — pinout, voltage and library notes.
Did this fix it?
Thanks — that helps us keep this page right.