ESP32 analogRead returns 0 or garbage when Wi-Fi is on

On the original ESP32, the ADC2 pins cannot be read while Wi-Fi is active. The radio uses ADC2 internally. Move the sensor to an ADC1 pin and the problem goes away.

What the message means

The ESP32 has two analogue converters. ADC1 works at all times. ADC2 is shared with the Wi-Fi driver, so reads on ADC2 pins fail or return useless values once Wi-Fi starts.

Fix it in this order

  1. Find which GPIO your sensor uses and look up its ADC channel in your board’s pinout.
  2. Move the sensor to an ADC1 pin, GPIO 32 to 39 on the common 30 and 38-pin boards.
  3. Keep GPIO 34 to 39 for input only. They cannot output.
  4. Set the attenuation for your voltage range, for example analogSetAttenuation(ADC_11db), so readings use the full range.
  5. Average several readings. The ESP32 ADC is noisy and not linear near the ends.

Why it happens

On the classic ESP32 the ADC2 pins (GPIO 0, 2, 4, 12 to 15 and 25 to 27) cannot be read while Wi-Fi is on, because the radio uses that converter. analogRead() then returns an error value or zero.

Move the signal to an ADC1 pin, GPIO 32 to 39, which works with Wi-Fi active. Remember that 34, 35, 36 and 39 are input-only.

If you see this, do this

You seeDo this
It works before Wi-Fi starts, then failsYou are on an ADC2 pin. Move to ADC1.
Readings jump aroundAverage samples and add a small capacitor at the input.
The value saturates earlyRaise the attenuation setting.

ESP32 pinout for robotics, MQTT telemetry on the ESP32.

Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.