ESP32 analog readings are wrong or jumpy

Why analogRead gives odd numbers on an ESP32, which pins you cannot use with Wi-Fi and how to get an honest measurement.

The ESP32 ADC is usable but not a laboratory instrument. Knowing its limits avoids most of the surprises.

Which pins

On the classic ESP32 there are two ADC groups. ADC2 shares hardware with Wi-Fi, so readings on its pins fail or are unreliable whenever Wi-Fi is on. Put analog inputs on ADC1 pins, GPIO 32 to 39, if you use Wi-Fi.

It is not linear

With the default settings the response flattens near the top of the range and is poor near zero. Choose the attenuation to fit your signal, and use analogReadMilliVolts() when it is available, because it applies the calibration stored in the chip.

Reduce the noise

  • Average many samples, for example 32 or 64, and drop the highest and lowest.
  • Add a 100 nF capacitor from the input to ground close to the pin.
  • Keep the divider resistors in the kilo-ohm range so the source can charge the ADC input quickly.
  • Read when the radio is idle, since transmission adds noise.

Measuring a higher voltage

Use a voltage divider so the pin never sees more than about 3.1 V. The calculator page on this site checks the result. Calibrate against a multimeter and write the correction factor into the code.

When it must be accurate

For battery fuel gauges, power monitoring or anything billed, add an external converter such as the ADS1115 over I2C. It costs little and gives stable readings.

Tools that help

  • Pinout — Interactive pinout for ESP32 DevKit V1, ESP32-C3 SuperMini and ESP32-S3 with I2C, SPI, ADC, PWM filters and safe/unsafe boot pins.
  • Calculators — Free planning calculators for blackouts and off-grid power: how long a battery lasts, what capacity and inverter you need, which cable cross-section and how big a generator to buy.

Projects related to this guide

⛔ High risk

High-current battery: a short circuit can start a fire. Put a fuse next to the battery plus, use thick enough wires and respect the BMS limits.

LiFePO4 / battery monitor

Shows voltage, current and power of a battery bank (INA219) so you know the real charge and load during outages.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 1–2 h
Pick parts / kit
⛔ High risk

Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.

Mains voltage monitor

Measures 220 V mains through an isolated ZMPT101B module and warns about sags, surges and blackouts in Telegram or Home Assistant.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 2–3 h
Pick parts / kit

Read next

← All guides

Comments

No comments yet. Share your experience or ask a question.

Comments are moderated.