Skip to content

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., your practice guide

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 Tool

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

Tier 1 · Web · No account

Version tested: Compiled and booted by the Wokwi gate (ESP32 Arduino core 3.3.11); captured in the Wokwi web editor on 2026-09-09. Date: 2026-09-09.

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

1,245 bytes · Circuit connections

Download

sketch.ino

10,859 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 and booted by the Wokwi gate (ESP32 Arduino core 3.3.11); captured in the Wokwi web editor on 2026-09-09 on 2026-09-09; the tool may have moved on — the text steps are the contract.

  1. 1 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: The potentiometer feeds GPIO 34. 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
    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: RAW: 50.1% | FILTERED: 50.1% | CALIBRATED: 50.1% | CORRECTION: 0.00%. The ring marks the unchanged midpoint reading.
    Step 2 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  3. 3 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: The low-reference instructions specify 10% actual. The ring marks the reference instructions.
    Step 3 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  4. 4 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: LOW POINT CAPTURED: Raw = 14.9% (Actual = 10%). The ring marks the captured low reference.
    Step 4 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  5. 5 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.
    Step 5: Low point: Raw=14.9% - width= 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)
  6. 6 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: RAW: 50.1% | FILTERED: 50.1% | CALIBRATED: 50.1% | CORRECTION: 0.01%. The ring marks the fresh midpoint reading.
    Step 6 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  7. 7 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: RAW: 50.1% | FILTERED: 50.1% | CALIBRATED: 50.1% | CORRECTION: 0.00%. The ring marks the zero correction after reset.
    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. 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 check
  2. In the lab code, why is the moving average filter applied BEFORE calibration, not after?

    Return to the chapter’s knowledge check

Caution

Keep the 220 ohm LED resistor and the potentiometer on 3.3 V. Wait for the ten-sample filter to settle before l or h; separated references are required. The knob is an ideal test input, not a traceable reference sensor. This unchanged firmware has no EEPROM persistence or nonlinear ADC correction; do not infer physical accuracy from its endpoint verification.

Return to Sensor Calibration: Math and Validation · Browse Labs