To get decent repeatability out of ESP32 ADC use code below as the starting point. The capacitor is also a must.
/* Analog read for ESP32
To minimize the noise connect 100nF capacitor between ADC pin and GND as per https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/adc.html#minimizing-noise
Code below multisample ADC on sensPin and average the results.
The result is printed on Serial port
*/
const int sensPin = 34;
int sensValue = 0;
void setup() {
Serial.begin(115200);
delay(1000);
analogReadResolution(10); //set ADC resolution to 10bits
}
void loop() {
// Reading sensor value
sensValue = AvgAnalogRead(sensPin, 1024); //Average 1024 reads to make good readings
Serial.print((sensValue*3.3)/1024);//convert to Volts
Serial.print("V ADC:");
Serial.println(sensValue);
delay(500);
}
int AvgAnalogRead(int adcToRead, int samples){
long x=0;
int i = samples;
while(i){
x+= analogRead(adcToRead);
i--;
}
return (x/samples);
}