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 ToolRelate a potentiometer setting to a 12-bit ADC reading.
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.
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 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 · 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
- 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · 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
- 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · 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