Why Your ESP32 Analog Sensor Goes Crazy When Wi-Fi Connects

If your analog sensor outputs nonsense as soon as Wi-Fi starts, you wired it to an ADC2 pin. The ESP32's Wi-Fi radio monopolises ADC2; moving your sensor to ADC1 fixes the issue immediately.
Your analog sensor returns clean, believable numbers while testing over USB serial. The moment your code executes WiFi.begin() and establishes a connection, the readings jump erratically, stick at 4095, or drop straight to zero. The sensor is not damaged, your pull-up resistor is not missing, and your board is not defective. You have plugged your sensor into an ADC2 pin.
The Silicon Bottleneck: ADC1 vs ADC2
The standard ESP32 silicon contains two separate 12-bit Analog-to-Digital Converter peripherals: ADC1 and ADC2. Between them, they serve up to 18 analog input pins on bare chips, though development boards break out a subset of these.
ADC1 operates independently. ADC2, however, shares internal hardware resources with the ESP32’s Wi-Fi and Bluetooth radio subsystem. When the Wi-Fi driver activates—whether scanning for an SSID, handling DHCP handshakes, or transmitting an MQTT telemetry packet—the networking stack claims exclusive access to ADC2 for radio frequency calibration and internal power measurements.
If your code calls analogRead() on an ADC2 pin while the Wi-Fi driver is running, the driver interrupts or locks out the reading. In Arduino Core and MicroPython environments, this manifests in one of two ways: the read function fails and returns a null/garbage value, or the radio's RF burst injects severe electrical noise directly into the peripheral, swinging the conversion between saturation (4095) and ground (0).
The Pin Remap: Safe vs Unsafe Pins
The fix requires zero code workarounds: move your sensor's signal wire off ADC2 and onto an ADC1 pin. ADC1 channels are electrically independent of the Wi-Fi baseband and continue converting reliably regardless of network activity.
| ADC Unit | GPIO Numbers | Wi-Fi Safe? | Classroom Notes |
|---|---|---|---|
| ADC1 | GPIO 32, 33, 34, 35, 36 (VP), 39 (VN) | Yes | Safe for any analog sensor while Wi-Fi is transmitting. Note that GPIO 34, 35, 36, and 39 are input-only pins (no internal pull-up/pull-down resistors). |
| ADC2 | GPIO 0, 2, 4, 12, 13, 14, 15, 25, 26, 27 | No | Unusable for analog sampling once WiFi.begin() is called. Many also double as bootstrapping pins. |
GPIO 36 and 39 are often labelled VP and VN on common 30-pin and 38-pin ESP32 NodeMCU/DevKit boards. These, along with GPIO 32, 33, 34, and 35, are your primary analog logging pins.
A Working Pinout Example
Consider a standard school IoT project: an automated plant monitor logging soil moisture or an ambient light sensor. A learner wires an analog soil moisture probe to GPIO 4 (ADC2 Channel 0) because it sits conveniently next to the ground pin. In offline testing, the serial monitor prints smooth values between 1500 and 2800. As soon as the board connects to the school's access point to push data to a dashboard, readings pin to 4095.
To fix the issue:
- Move the signal jumper wire from GPIO 4 to GPIO 34 (or 32, 33, 35).
- Update the pin definition in code:
const int sensorPin = 34;. - Keep GPIO 4 free for digital outputs, such as triggering a relay module or a transistor controlling a 5V submersible pump.
If you are designing multi-sensor stations for environmental monitoring, you can explore structured curriculum hardware and pin maps on Sheen IoT.
Secondary Factor: Power Rail Sag
If you have moved your sensor to ADC1 (e.g., GPIO 32) and you still observe minor erratic spikes during transmission, you are facing a power integrity problem rather than an ADC lock. When the ESP32 powers on its radio transmitter, current consumption spikes abruptly from ~50mA to over 300–400mA for a few milliseconds.
If the board is powered from a noisy USB port on an old classroom laptop trolley, or through thin breadboard jumper wires, the 3.3V power rail dips momentarily. Because analog conversions measure voltage relative to the supply rail (the reference voltage), a dip on the rail makes external analog voltages appear to jump upward. Placing a 100µF electrolytic capacitor across the 3V3 and GND rails on your breadboard smooths these transient radio spikes completely.



