Read a potentiometer with the ESP32 ADC
Relate a potentiometer setting to a 12-bit ADC reading.

Physics Phoebe
Predict the reading, then compare it with the measurement.
Wokwi ESP32
Third party ToolOpen 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.
sketch.ino
- Use the launch button above to open the ESP32 editor in Wokwi.
- Select the editor’s diagram.json tab and replace all its text with the supplied diagram.json.
- Select the sketch.ino tab, replace all its text with the supplied sketch.ino, then click Start Simulation.
Steps
Step 1
- Do
- In the Simulation panel, inspect the potentiometer wiring after pasting both supplied files.
- You will see
- The
sensorpart 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · 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.
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 checkYour 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