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.

How to complete this Wokwi lab

Your task: Capture two references and validate a calibration

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

Open the simulator · Read the full text instructions

Use this checklist as you work. Checks last only on this page and do not submit or record completion.

  1. Details for step 1
  2. Details for step 2
  3. Details for step 3
  4. Details for step 4
  5. Details for step 5
  6. Details for step 6
  7. Details for step 7
Simulator unavailable? Use the text fallback

Follow the checklist using the recorded results below. Predict each change, compare it with the recorded result, and explain why it matters. These are the lab's recorded results, not measurements you have made. Run the simulator later to test your predictions.

  1. Recorded result for step 1

    LED anode connects to ESP32 GPIO2 (diagram.json line 55). LED cathode returns through ledR to ESP32 ground (diagram.json lines 61, 67). The LED’s series resistor ledR is 220 Ω (diagram.json line 24). Power: potentiometer VCC connects to ESP32 3.3 V; GND returns to ground (diagram.json lines 73, 79). Potentiometer signal connects to ESP32 GPIO34 (diagram.json line 85).

    Why it matters: GPIO34 supplies the raw ADC endpoints used later for calibration. The status LED on GPIO2 reports the procedure state through a current-limited path.

  2. Recorded result for step 2

    Input: supplied potentiometer midpoint. Observed: "RAW: 50.1% | FILTERED: 50.1% | CALIBRATED: 50.1% | CORRECTION: 0.00%". Observed: the same row repeats before calibration. Expected: uncalibrated midpoint has zero correction.

    Why it matters: The raw and filtered readings agree at 50.1%. The calibrated value begins at the same value. The correction is zero before reference capture. This is the baseline for the next two points.

  3. Recorded result for step 3

    Input: send c. Observed: "CALIBRATION PROCEDURE STARTED". Observed: "Step 1: Set the potentiometer to the LOW reference point". Observed: "(This represents 10% actual value)".

    Why it matters: The sketch enters its calibration procedure. It requests the low reference first. The declared actual value is 10%. A reference must be captured before the gain is computed.

  4. Recorded result for step 4

    Input: potentiometer control 153, then command l. Observed: "LOW POINT CAPTURED: Raw = 14.9% (Actual = 10%)". Observed: the monitor next requests the HIGH reference. Expected: store 14.9% raw as the 10% actual reference.

    Why it matters: The sensor model reads above the declared actual low point. The command records both raw and actual values. The later high point is still needed for a two-point fit. The 14.9% value matches the real screenshot.

  5. Recorded result for step 5

    Input: potentiometer control 870, then command h. Observed: "HIGH POINT CAPTURED: Raw = 85.1% (Actual = 90%)". Observed: "Low point: Raw=14.9% -> Calibrated=10.0% (Expected: 10.0%)". Observed: "High point: Raw=85.1% -> Calibrated=90.0% (Expected: 90.0%)".

    Why it matters: The high raw value falls below its declared actual reference. The two captured pairs define a linear correction. Verification maps the low reference to 10.0%. Verification maps the high reference to 90.0%.

  6. Recorded result for step 6

    Input: potentiometer control restored to 512. Observed: "RAW: 50.1% | FILTERED: 50.1% | CALIBRATED: 50.1% | CORRECTION: 0.01%". Observed: the settled row repeats. Expected: midpoint returns with a small correction.

    Why it matters: The raw and filtered readings settle together. The calibrated reading is 50.1%. The residual correction is 0.01%. This midpoint checks interpolation between references.

  7. Recorded result for step 7

    Input: send r after midpoint has settled. Observed: "Calibration RESET to defaults (gain=1.0, offset=0.0)". Observed: "RAW: 50.1% | FILTERED: 50.1% | CALIBRATED: 50.1% | CORRECTION: 0.00%". Expected: default gain and offset remove the correction.

    Why it matters: The gain returns to one. The offset returns to zero. The displayed correction returns to 0.00%. The midpoint remains the same controlled input.

Review the detailed text steps and cautions below.

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

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
    In Wokwi's project editor, paste diagram.json and sketch.ino into a new Wokwi ESP32 project; inspect the potentiometer and status LED connections.
    You will see
    LED anode connects to ESP32 GPIO2 (diagram.json line 55). LED cathode returns through ledR to ESP32 ground (diagram.json lines 61, 67). The LED’s series resistor ledR is 220 Ω (diagram.json line 24). Power: potentiometer VCC connects to ESP32 3.3 V; GND returns to ground (diagram.json lines 73, 79). Potentiometer signal connects to ESP32 GPIO34 (diagram.json line 85).
    Why it matters
    GPIO34 supplies the raw ADC endpoints used later for calibration. The status LED on GPIO2 reports the procedure state through a current-limited path.
    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
    In the Simulation toolbar, start the run; read steady midpoint values in Serial Monitor.
    You will see
    Input: supplied potentiometer midpoint. Observed: "RAW: 50.1% | FILTERED: 50.1% | CALIBRATED: 50.1% | CORRECTION: 0.00%". Observed: the same row repeats before calibration. Expected: uncalibrated midpoint has zero correction.
    Why it matters
    The raw and filtered readings agree at 50.1%. The calibrated value begins at the same value. The correction is zero before reference capture. This is the baseline for the next two points.
    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
    In the Serial Monitor input field, send c to start the calibration procedure.
    You will see
    Input: send c. Observed: "CALIBRATION PROCEDURE STARTED". Observed: "Step 1: Set the potentiometer to the LOW reference point". Observed: "(This represents 10% actual value)".
    Why it matters
    The sketch enters its calibration procedure. It requests the low reference first. The declared actual value is 10%. A reference must be captured before the gain is computed.
    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
    In the potentiometer control panel, set 153 of 1023; then send l in Serial Monitor.
    You will see
    Input: potentiometer control 153, then command l. Observed: "LOW POINT CAPTURED: Raw = 14.9% (Actual = 10%)". Observed: the monitor next requests the HIGH reference. Expected: store 14.9% raw as the 10% actual reference.
    Why it matters
    The sensor model reads above the declared actual low point. The command records both raw and actual values. The later high point is still needed for a two-point fit. The 14.9% value matches the real screenshot.
    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
    In the potentiometer control panel, set 870 of 1023; then send h in Serial Monitor.
    You will see
    Input: potentiometer control 870, then command h. Observed: "HIGH POINT CAPTURED: Raw = 85.1% (Actual = 90%)". Observed: "Low point: Raw=14.9% -> Calibrated=10.0% (Expected: 10.0%)". Observed: "High point: Raw=85.1% -> Calibrated=90.0% (Expected: 90.0%)".
    Why it matters
    The high raw value falls below its declared actual reference. The two captured pairs define a linear correction. Verification maps the low reference to 10.0%. Verification maps the high reference to 90.0%.
    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
    In the potentiometer control panel, restore 512 and read settled Serial Monitor rows.
    You will see
    Input: potentiometer control restored to 512. Observed: "RAW: 50.1% | FILTERED: 50.1% | CALIBRATED: 50.1% | CORRECTION: 0.01%". Observed: the settled row repeats. Expected: midpoint returns with a small correction.
    Why it matters
    The raw and filtered readings settle together. The calibrated reading is 50.1%. The residual correction is 0.01%. This midpoint checks interpolation between references.
    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
    In the Serial Monitor input field, send r and read the next steady row.
    You will see
    Input: send r after midpoint has settled. Observed: "Calibration RESET to defaults (gain=1.0, offset=0.0)". Observed: "RAW: 50.1% | FILTERED: 50.1% | CALIBRATED: 50.1% | CORRECTION: 0.00%". Expected: default gain and offset remove the correction.
    Why it matters
    The gain returns to one. The offset returns to zero. The displayed correction returns to 0.00%. The midpoint remains the same controlled input.
    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