Capture two references and validate a calibration
Fit gain and offset from two potentiometer references, then check a fresh midpoint and reset the correction.

Physics Phoebe: I want you to fit the two references, then test a reading you did not use for the fit.
Predict the reading, then compare it with the measurement.
Wokwi ESP32
Third party ToolFit gain and offset from two potentiometer references, then check a fresh midpoint and reset the correction.
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
- Paste diagram.json and sketch.ino into a new Wokwi ESP32 project; inspect the potentiometer and status LED connections.
- You will see
- The potentiometer wiper goes to GPIO 34, with 3.3 V and ground on its outer pins; GPIO 2 drives the status LED through 220 ohms.
- Why it matters
- One measured input and one status output keep the reference capture visible.

Step 1 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 2
- Do
- Start the simulation and wait for the readings to settle with the potentiometer near its midpoint.
- You will see
- RAW, FILTERED and CALIBRATED are about 50%; CORRECTION is 0.00% before calibration.
- Why it matters
- Default gain 1 and offset 0 leave the filtered input unchanged.

Step 2 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 3
- Do
- Send c in Serial Monitor to start calibration.
- You will see
- CALIBRATION PROCEDURE STARTED is followed by the low-reference instructions for 10% actual value.
- Why it matters
- The state machine separates the known reference value from the raw sensor reading.

Step 3 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 4
- Do
- Set the potentiometer near 15% (control value 153 of 1023), wait 2–3 seconds, then send l. Treat this as a sensor that reads about 15% at a known 10% reference.
- You will see
- LOW POINT CAPTURED reports about 15% raw and Actual = 10%; instructions ask for the high reference.
- Why it matters
- Stable filtered readings reduce noise in the captured reference; the known value is not inferred from the knob.

Step 4 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 5
- Do
- Set the potentiometer near 85% (control value 870), wait 2–3 seconds and send h, representing a known 90% reference.
- You will see
- The verification maps the captured low point to 10.0% and the high point to 90.0%.
- Why it matters
- Two separated pairs determine both gain and offset. Rechecking the fitted endpoints verifies arithmetic but does not independently prove linearity.
Calibrated=10.0% (Expected: 10.0%) High point: Raw=85.1% -> Calibrated=90.0% (Expected: 90.0%). The ring marks the endpoint verification." loading="lazy">Step 5 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 6
- Do
- Move the potentiometer back near its midpoint (control value 512) and wait 2–3 seconds.
- You will see
- RAW, FILTERED and CALIBRATED settle near 50%, with the small correction shown in the final column.
- Why it matters
- A fresh midpoint tests interpolation away from the fit points. This ideal potentiometer does not prove physical ESP32 ADC linearity.

Step 6 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 7
- Do
- Send r, then wait for the next steady reading.
- You will see
- Calibration RESET to defaults (gain=1.0, offset=0.0) appears; CORRECTION returns to 0.00%.
- Why it matters
- The supplied firmware keeps coefficients in memory; reset or restart loses them, unlike the host chapter’s EEPROM extension.

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.
A sensor reads 20% when the true value is 10%, and reads 80% when the true value is 90%. What is the gain (slope) coefficient?
Return to the chapter’s knowledge checkIn the lab code, why is the moving average filter applied BEFORE calibration, not after?
Return to the chapter’s knowledge check
Return to Sensor Calibration: Math and Validation · Browse Labs