Skip to content

Read a potentiometer with the ESP32 ADC

Relate a potentiometer setting to a 12-bit ADC reading.

Physics Phoebe, your practice guide

Physics Phoebe
Predict the reading, then compare it with the measurement.

Wokwi ESP32

Third party Tool

Tier 2 · Web · paste-in setup · Account needed to save a project

Version tested: Compiled with arduino-cli 1.5.2-rc.1 for esp32 core 3.3.11; booted headlessly with wokwi-cli 0.26.1 on 2026-09-07; serial line 'ADC=2050, ideal voltage=1.652 V' seen at 6.617 s (wall time from CLI start; scenario timeout 20 s simulated time); captured in the Wokwi web editor on 2026-09-09. Date: 2026-09-06.

Open the ESP32 editor, paste diagram.json, then paste sketch.ino.

Open Wokwi to paste in the files (new tab)

Get the files

Use both prepared files. This is a paste-in setup; saving a project requires a Wokwi account.

diagram.json

833 bytes · Circuit connections

Download

sketch.ino

185 bytes · ESP32 program

Download

  1. Use the launch button above to open the ESP32 editor in Wokwi.
  2. Select the editor’s diagram.json tab and replace all its text with the supplied diagram.json.
  3. Select the sketch.ino tab, replace all its text with the supplied sketch.ino, then click Start Simulation.

Steps

Screens captured against Wokwi ESP32 Compiled with arduino-cli 1.5.2-rc.1 for esp32 core 3.3.11; booted headlessly with wokwi-cli 0.26.1 on 2026-09-07; serial line 'ADC=2050, ideal voltage=1.652 V' seen at 6.617 s (wall time from CLI start; scenario timeout 20 s simulated time); captured in the Wokwi web editor on 2026-09-09 on 2026-09-06; the tool may have moved on — the text steps are the contract.

  1. 1 Step 1

    Do
    In the Simulation panel, inspect the potentiometer wiring after pasting both supplied files.
    You will see
    The sensor part is a Wokwi potentiometer (diagram.json line 15). Power: potentiometer VCC connects to ESP32 3.3 V (diagram.json line 25). Ground: potentiometer GND connects to ESP32 ground (diagram.json line 34). Wiper signal: potentiometer SIG connects to ESP32 GPIO32 (diagram.json line 43).
    Why it matters
    The potentiometer wiper reaches GPIO32, an ESP32 ADC input. With its outer terminals on 3.3 V and ground, later knob changes can be compared with 12-bit counts.
    Step 1: The potentiometer power, ground, and SIG connect to the ESP32. The ring marks the potentiometer.
    Step 1 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  2. 2 Step 2

    Do
    In the sketch.ino editor tab, find analogRead(32) and the voltage conversion raw*3.3/4095.0.
    You will see
    Open serial at 115200 baud: Serial.begin(115200) (sketch.ino line 1). Set 12-bit ADC resolution: analogReadResolution(12) (sketch.ino line 1). Read ADC GPIO32: int raw=analogRead(32) (sketch.ino line 2). Scale the count to 3.3 V: raw*3.3/4095.0 (sketch.ino line 2).
    Why it matters
    The 12-bit resolution makes 4095 the ideal full-scale count. The later serial readings pair GPIO32 raw counts with a calculated 3.3 V ideal voltage every 500 ms.
    Step 2: The sketch reads GPIO 32 and calculates raw*3.3/4095.0. The ring marks the ADC read and voltage calculation.
    Step 2 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  3. 3 Step 3

    Do
    In the Simulation toolbar, click play and read the Serial Monitor result.
    You will see
    Input: supplied potentiometer midpoint. Observed: "ADC=2050, ideal voltage=1.652 V". Observed: the monitor repeats the line while the control is still. Expected: a count and its ideal-voltage conversion.
    Why it matters
    The sketch exposes the raw count. The voltage is explicitly labelled ideal. Repeated output shows the run is active. The model voltage is not a measured hardware reference.
    Step 3: The simulation is running and Serial Monitor prints ADC and voltage. The ring marks the Stop control.
    Step 3 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  4. 4 Step 4

    Do
    In the Serial Monitor panel, read the supplied potentiometer midpoint.
    You will see
    Input: supplied midpoint control position. Observed: "ADC=2050, ideal voltage=1.652 V". Expected: approximately half of 4095 counts and 3.3 V. This is the baseline before endpoint changes.
    Why it matters
    The live count is 2050. The model voltage is 1.652 V. Both are near their ideal midpoint. One midpoint does not establish accuracy across the range.
    Step 4: The supplied midpoint produces ADC=2050, ideal voltage=1.652 V. The ring marks the baseline reading.
    Step 4 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  5. 5 Step 5

    Do
    In the potentiometer control panel, move the control to minimum.
    You will see
    Input: potentiometer at minimum. Observed: "ADC=0, ideal voltage=0.000 V". Expected: the lower endpoint of the ideal model. The preceding midpoint was ADC=2050 and 1.652 V.
    Why it matters
    The live count reached zero. The derived voltage reached zero. The endpoint differs from the midpoint. The model has no independent physical-voltage check.
    Step 5: At minimum, ADC=0 and ideal voltage=0.000 V. The ring marks the minimum reading.
    Step 5 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  6. 6 Step 6

    Do
    In the potentiometer control panel, move the control to maximum.
    You will see
    Input: potentiometer at maximum. Observed: "ADC=4095, ideal voltage=3.300 V". Expected: the upper endpoint of the ideal model. The preceding minimum was ADC=0 and 0.000 V.
    Why it matters
    The live count reached the stated 12-bit maximum. The derived voltage reached 3.300 V. Both endpoints have now been exercised. This remains a simulation of the conversion.
    Step 6: At maximum, ADC=4095 and ideal voltage=3.300 V. The ring marks the maximum reading.
    Step 6 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  7. 7 Step 7

    Do
    In the potentiometer control panel, restore the midpoint setting of 512.
    You will see
    Input: potentiometer control returned to 512. Observed: "ADC=2050, ideal voltage=1.652 V". Expected: the original midpoint reading returns. The maximum line preceded the restored result.
    Why it matters
    The live count returned to 2050. The ideal voltage returned to 1.652 V. The return checks repeatability in this run. A calibrated reference is still needed for hardware accuracy.
    Step 7: Restoring control value 512 returns ADC=2050 and ideal voltage=1.652 V. The ring marks the restored midpoint.
    Step 7 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)

Chapter checks

These questions refer to the chapter’s examples. Use the return links to review their answers.

  1. For a moving average filter with window size N=10 sampling at 100Hz, what is the approximate latency introduced?

    Return to the chapter’s knowledge check
  2. Your temperature sensor reads 1.2C in an ice bath (should be 0C) and 98.8C in boiling water (should be 100C). What is the calibration slope?

    Return to the chapter’s knowledge check

Caution

Tool versions change and screens may differ. Reopen the supplied setup, check the tool documentation, and use the site feedback control if the problem remains. The screenshots show browser measurements, not hardware calibration; values may vary slightly between runs.

Return to Resistive Dividers and ADC Loading · Browse Labs