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.
Comments
No comments yet. Share your experience or ask a question.