How does the voltage measured by a microcontroller from the output of a 10K potentiometer differ between a 5v circuit and a 3.3v circuit? How does a change from an Arduino and 5v circuit to an ESP32 and a 3.3v circuit affect the analog values from a potentiometer as seen by a sensing analog pin on the microcontroller?

With a past project using the Arduino UNO and a 10K potentiomter connected to an analog pin on the Arduino in a 5v circuit, the Arduino provided readings in the correct range of 0 to 1023 as I turned the knob. When I changed the set point by rotating the knob, the values reported by the Arduino through the Serial Monitor would also change to follow. When I stopped rotating the knob the reported value would stick without floating.

Attempting the same project with an ESP32 and the same pot but using a 3.3v circuit, the behavior is quite different. The range reported by the ESP32 is greater since it is a 12 bit value so should be between 0 and 4095.

However what the ESP32 is reporting when I turn the knob to a new point are values that will vary, floating about some point in that range even when the knob is not turning. The variation or floating values vary by as much as 40 or sometimes more. With the Arduino the values would change when I rotated the knob and then stick and not float when I stopped twisting the knob.

I've also just removed the 3.3v connector and the ground connector from those pins of the potentiometer leaving only the lead from the sensing pin of the ESP32 to the middle pin on the pot and I still see the reported values change when I would expect them to be zero and stay zero.

I'm referencing this article https://randomnerdtutorials.com/esp32-adc-analog-read-arduino-ide/

The source code for the pin is:

int  myPin = 34;
static int  iPotValSave = 0;

void setup() {

    Serial.println("begin setup()");

    pinMode (myPin, INPUT);
    iPotValSave = analogRead (myPin);
    Serial.print (" pot value initial ");
    Serial.println (iPotValSave);

void loop() {
    int iPotVal = analogRead (myPin);
    if (iPotVal != iPotValSave) {
        Serial.print (" new pot value ");
        Serial.println (iPotValSave);

My question seems to be similar to the following:

esp32-wrover ADC, incorrect values?

How to convert 10K Pot raw output ADC data to voltage and resistance from arduino uno? with an answer which seems to indicate that the ESP32 needs a reference voltage for the ADC built into the pin.


Espressif documentation Analog to Digital Converter, https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/adc.html#adc-api-adc-calibration

The ESP32 ADC can be sensitive to noise leading to large discrepancies in ADC readings. To minimize noise, users may connect a 0.1uF capacitor to the ADC input pad in use. Multisampling may also be used to further mitigate the effects of noise.

and see also this section:

esp_err_t adc1_config_channel_atten(adc1_channel_tchannel, adc_atten_tatten)

Set the attenuation of a particular channel on ADC1, and configure its associated GPIO pin mux.

The default ADC full-scale voltage is 1.1 V. To read higher voltages (up to the pin maximum voltage, usually 3.3 V) requires setting >0 dB signal attenuation for that ADC channel.

How to use ADC of ESP32 – Measuring voltage example https://microcontrollerslab.com/adc-esp32-measuring-voltage-example/

ESP32 Pinout Reference: Which GPIO pins should you use? https://randomnerdtutorials.com/esp32-pinout-reference-gpios/

  • \$\begingroup\$ analog systems have noise, higher resolution ADC's see more of it and some setups have more than others. Add a small capacitor and filter in software. \$\endgroup\$ – Chris Stratton Aug 17 '20 at 0:54
  • \$\begingroup\$ @ChrisStratton Thank you for that insight. I hadn't thought about it that way. I believe I can change the ADC settings to reduce the number of bits. I will check into that and see what I get. I did put a small filter of taking the raw analog value and then adding ten to it then dividing by 20 then multiplying by 20 to create a kind of rounded value and that did reduce the swings as did increasing the delay between reading the value. I will make changes and let you know via a comment what happens. \$\endgroup\$ – Richard Chambers Aug 17 '20 at 2:03
  • \$\begingroup\$ That's not how a filter works. A filter would be something like taking a bunch of readings and averaging them together (perhaps on a basis of overlapping history, ie, average the 32 most recent readings) \$\endgroup\$ – Chris Stratton Aug 17 '20 at 2:11
  • \$\begingroup\$ @ChrisStratton to me the word filter is a fairly generic term that describes some kind of a device that takes an input, makes some kind of a transformation to the signal which is the output of the device. In my case I am using a simple round to the nearest Nth where Nth is nearest multiple of 20. The input is rounded down if below the midpoint between two adjacent multiples of 20 or round up if equal to or above the midpoint. The output of the device is smoothed to filter out the minor variations in the input by folding or pushing similar though slightly different inputs into a single output. \$\endgroup\$ – Richard Chambers Aug 17 '20 at 4:37
  • \$\begingroup\$ @ChrisStratton I found an article indicating a 0.1uF capacitor could be added however I don't have that part. I tried a different pin, pin #15, and the variability seemed to be eliminated after I also tied the potentiometer directly to the 3.3v and GND pins rather than to a common 3.3v and GND source shared by a couple of LEDs that were being blinked. So what it looks like is there is noise, possibly from the pins driving the LEDs. There is also attenuation of a channel. docs.espressif.com/projects/esp-idf/en/latest/esp32/… \$\endgroup\$ – Richard Chambers Aug 17 '20 at 4:50

According to this posted answer, Why do many electronics operate on 5 AND 3.3 Volts?, 5v provides better noise immunity than 3.3v so the Arduino Uno with 5v has less problems with a potentiometer in a 5v circuit than the ESP32 with a potentiometer in a 3.3v circuit.

This article from EE Times, Electrical noise and mitigation – Part 1: Noise definition, categories and measurement, has this to say:

The best illustration that can be given of this condition is to consider where the signal voltage has been and what is happening to it compared to the noise voltage (see Figure 8.5). In years gone by, signal voltages may have been 30 V or more but since then have steadily been decreasing. As long as the signal voltage was high and the noise voltage was only 1 V, then we had what most instrument engineers would call a very high signal to noise ratio, 30:1.

Most engineers would say you have no problem distinguishing the signal as long as you have such a high signal to noise ratio. As the electronic equipment industry advanced, the signal strength went down further, below 10 and then below 5. Today we are fighting 1-, 2- and 3 V signals and still finding ourselves with 1, 2 and 3 V of electrical noise. When this takes place for brief periods of time, the noise signal may be larger than the actual signal. The sensors within the sensitive equipment turn and try to run on the noise signal itself as the predominant voltage.

See this answer Capacitor in circuit for potentiometer?.

From Instructables: Smooth Potentiometer Input

Sometimes, actually in most cases, potentiometers produce a jittery signal. This can be due to low quality material used to make the potentiometers. The jittery signal can be very irritating, especially if you are using the pot to control a sensitive output. That is why you need to look for a way to make the input smooth.

To smooth out the pot input, you should use a low-pass filter. It removes all signals that have a frequency that is above the set cut-off frequency. You determine the cut-off frequency by adjusting the values of capacitance and resistance in the circuit.

See also Wikipedia topic Low-pass filter


schematic of passive low-pass RC filter

See also De-coupling which notes "Once you get more than a handful of active components together you need to de-couple the power supply. What this is, and why, is described here."


See as well The Ultimate Capacitors Guide: Learn How To Use Them


Your Answer

