Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.
ADC · ESP32

Fix ESP32 analogRead always returning 4095

4095 is the top of the ESP32 ADC: the pin is at or above ~3.1 V, wired to a 5 V sensor output, or floating. Divide 5 V signals and use an ADC1 pin.

ESP32ESP32-S3ESP32-C3Updated 3 Nov 2026

Community draft — report a mistake

What you see

OutputOutput
raw 4095  3142 mV  <- top of range: input above ~3.1 V, wired to 5 V, or floating
raw 4095  3142 mV  <- top of range: input above ~3.1 V, wired to 5 V, or floating
raw 4095  3142 mV  <- top of range: input above ~3.1 V, wired to 5 V, or floating

The ESP32 ADC is 12-bit: 0 to 4095. A constant 4095 means the input is at (or beyond) the top of the measurable range — usually because a 5 V sensor is connected directly. The diagnostic below prints the raw value and calibrated millivolts side by side.

const int PIN = 34;   // ADC1, input-only

void setup() {
  Serial.begin(115200);
  analogSetPinAttenuation(PIN, ADC_11db);
}

void loop() {
  Serial.printf("raw %d  %d mV\n", analogRead(PIN), analogReadMilliVolts(PIN));
  delay(500);
}

Quick fix — try in order

  1. 1

    Measure the pin voltage

    Multimeter between the ADC pin and GND. Anything above about 3.1 V reads 4095 at the default 11 dB attenuation.

  2. 2

    Divide 5 V sensor outputs

    MQ-2/MQ-135 modules, many soil-moisture probes and potentiometers on 5 V output up to 5 V. Use a divider (e.g. 10 kΩ top, 20 kΩ bottom → 5 V becomes 3.3 V) — and never feed more than 3.3 V into a GPIO.

  3. 3

    Or power the sensor from 3.3 V

    Capacitive soil sensors and pots work at 3.3 V, so their output can’t exceed it. MQ gas sensors need 5 V for the heater — divide their AO instead.

  4. 4

    Check it isn’t floating

    A disconnected or wrong pin can sit at the top. Touching the pin should change the reading; a 100 kΩ resistor to GND pulls a floating pin down.

  5. 5

    Use an ADC1 pin with Wi-Fi

    GPIO 32–39 are ADC1. ADC2 pins (0, 2, 4, 12–15, 25–27) misbehave once Wi-Fi is on — see ADC2 with Wi-Fi.

Diagnostic sketch

Verified — core esp32 3.3.12, 3 Nov 2026Compile-only
fix-analogread-esp32.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// ESP32 ADC check: prints the raw value and the calibrated millivolts on GPIO34 every 0.5 s.
// 4095 means the pin is at or above about 3.1 V (or floating) - not "a broken ADC".
const int PIN = 34;  // ADC1 pin: keeps working with Wi-Fi on (ADC2 pins do not)

void setup() {
  Serial.begin(115200);
  analogReadResolution(12);                 // 0..4095
  analogSetPinAttenuation(PIN, ADC_11db);   // full range, roughly 0..3.1 V
}

void loop() {
  int raw = analogRead(PIN);
  int mv = analogReadMilliVolts(PIN);
  Serial.printf("raw %4d  %4d mV", raw, mv);
  if (raw >= 4095) Serial.print("  <- top of range: input above ~3.1 V, wired to 5 V, or floating");
  else if (raw == 0) Serial.print("  <- 0: input at GND, or the sensor has no power");
  Serial.println();
  delay(500);
}

Why it happens

Why ~3.1 V and not 3.3 V?

At 11 dB (the default) the ESP32’s ADC tops out around 3.1 V; above that it saturates at 4095. Lower attenuations saturate even earlier (6 dB ≈ 1.75 V).

analogSetAttenuation was changed

If code sets ADC_0db or ADC_2_5db, 1–1.3 V already reads 4095. Use analogSetPinAttenuation(pin, ADC_11db) for full range.

Readings are noisy, not stuck

Normal for the ESP32 ADC. Average 16 readings, add 100 nF from pin to GND, and use analogReadMilliVolts() for calibrated values.

Board-specific notes

ESP32: GPIO 34–39 are input-only and ideal for analog inputs. Pin map: ESP32 DevKit V1.

ESP32-C3: ADC1 is GPIO 0–4; GPIO5 (ADC2) is unreliable with Wi-Fi on.

Parts: MQ-2 and capacitive soil sensor — output voltage notes.

↑↓ to move · Enter to open