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

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

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 potentiometer has power and ground connections, with SIG connected to ESP32 pin 32.
    Why it matters
    The chapter starts with a measurement record and a checked signal path. Identifying SIG ties each later count to the input you change.
    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
    The sketch prints the raw count and an ideal voltage based on a 3.3 V range.
    Why it matters
    Keeping raw and accepted values together helps explain what the code did. This conversion labels its voltage as ideal, so its assumptions stay visible.
    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 the play button and wait for compilation.
    You will see
    The timer starts and the Serial Monitor begins printing ADC counts and ideal voltage about every 500 ms.
    Why it matters
    The chapter uses Serial Monitor output to inspect intermediate values. A running printout provides evidence for this stage before more processing is added.
    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 count and ideal voltage at the supplied midpoint setting.
    You will see
    The supplied midpoint produces ADC=2050, ideal voltage=1.652 V in the recorded run.
    Why it matters
    Recording a starting value gives later tests a comparison. A believable midpoint alone does not cover the chapter’s missing, stuck, or invalid reading cases.
    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 Simulation panel, select the potentiometer and move its control to minimum.
    You will see
    The Serial Monitor changes to ADC=0, ideal voltage=0.000 V.
    Why it matters
    The chapter calls for a known low point. Testing this end of the range shows whether the code represents the expected minimum.
    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
    The Serial Monitor changes to ADC=4095, ideal voltage=3.300 V.
    Why it matters
    The known high point checks the other end of the useful range. Endpoint tests should accompany the chapter’s tests for values outside allowed limits.
    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 supplied midpoint setting of 512.
    You will see
    The Serial Monitor returns to ADC=2050, ideal voltage=1.652 V in the recorded run.
    Why it matters
    Returning to the starting input checks repeatability. The chapter requires a reference and calibration evidence before a model voltage becomes a trusted measurement.
    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