Skip to content

Convert an NTC ADC reading to temperature

Use the Steinhart–Hart equation to convert thermistor resistance into temperature.

Physics Phoebe, your practice guide

Physics Phoebe
Predict the reading, then compare it with the measurement.

Wokwi ESP32

Third party Tool

Use the Steinhart–Hart equation to convert thermistor resistance into temperature.

Tier 2 · Web · paste-in setup · Account needed to save a project

Version tested: Compiled with arduino-cli 1.5.2-rc.1 for esp32 core 3.3.11; booted headlessly with wokwi-cli 0.26.1 on 2026-09-07; serial line 'ADC=2048, R=10005 ohm, T=24.99 C' seen at 3.187 s (wall time from CLI start; scenario timeout 20 s simulated time); captured in the Wokwi web editor on 2026-09-09. Date: 2026-09-06.

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

871 bytes · Circuit connections

Download

sketch.ino

601 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 with arduino-cli 1.5.2-rc.1 for esp32 core 3.3.11; booted headlessly with wokwi-cli 0.26.1 on 2026-09-07; serial line 'ADC=2048, R=10005 ohm, T=24.99 C' seen at 3.187 s (wall time from CLI start; scenario timeout 20 s simulated time); captured in the Wokwi web editor on 2026-09-09 on 2026-09-06; the tool may have moved on — the text steps are the contract.

  1. 1 Step 1

    Do
    In the Simulation panel, inspect the NTC sensor wiring after pasting both supplied files.
    You will see
    The NTC sensor has power and ground connections, with OUT connected to ESP32 pin 32.
    Why it matters
    A calibration equation needs a named input before its result can be checked. Following OUT identifies the raw channel used by this setup.
    Step 1: The NTC sensor power, ground, and OUT connect to the ESP32. The ring marks the sensor.
    Step 1 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  2. 2 Step 2

    Do
    In the sketch.ino editor tab, find analogRead(32) and the raw-value range check.
    You will see
    The sketch reads 12-bit counts and rejects values at 0 or 4095 before calculating resistance.
    Why it matters
    The chapter distinguishes calculating a value from validating it. Range guards keep an invalid input from becoming a plausible corrected result.
    Step 2: The code reads GPIO 32 as a 12-bit ADC and rejects the endpoint counts. The ring marks the ADC read and range check.
    Step 2 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  3. 3 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 opens with ADC, resistance, and temperature results.
    Why it matters
    Fresh readings test the equation’s claim. Keeping raw and corrected values together makes the conversion open to review.
    Step 3: The simulation is running with ADC, resistance, and temperature output. The ring marks the Stop control.
    Step 3 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  4. 4 Step 4

    Do
    In the Serial Monitor panel, read ADC, resistance, and temperature at the initial 25 °C setting.
    You will see
    The 25 °C setting produces 2048 counts, 10005 Ω, and 24.99 °C in the recorded run.
    Why it matters
    Residual error compares a corrected result with its reference. Here the model setting provides that comparison, rather than an independent temperature standard.
    Step 4: At the initial 25 C setting, ADC=2048, R=10005 ohm, T=24.99 C. The ring marks the measured baseline.
    Step 4 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  5. 5 Step 5

    Do
    In the sketch.ino editor tab, find the resistance calculation 10000.0*raw/(4095.0-raw).
    You will see
    The line uses a 10000 Ω reference value and the raw ADC count to reconstruct resistance.
    Why it matters
    The chapter keeps conversion coefficients with their input and output units. Here the intermediate resistance makes the path from counts to temperature visible.
    Step 5: The resistance calculation uses 10000.0*raw/(4095.0-raw). The ring marks that calculation.
    Step 5 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  6. 6 Step 6

    Do
    In the Simulation panel, select the NTC sensor and set its temperature control to 35 °C.
    You will see
    The 35 °C setting produces 1614 counts, 6505 Ω, and 35.00 °C in the recorded run.
    Why it matters
    A second input tests the conversion away from its starting point. The chapter warns that a straight calibration line can leave errors in a curved response.
    Step 6: At the 35 C control setting, ADC=1614, R=6505 ohm, T=35.00 C. The ring marks the warmer-sensor reading.
    Step 6 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  7. 7 Step 7

    Do
    In the NTC control panel, restore temperature to 25 °C.
    You will see
    The Serial Monitor returns to 2048 counts, 10005 Ω, and 24.99 °C in the recorded run.
    Why it matters
    Repeating a known value checks whether the result returns. The chapter still calls for reference standards across the range and recorded recalibration conditions.
    Step 7: After restoring 25 C, ADC=2048, R=10005 ohm, T=24.99 C. The ring marks the restored baseline.
    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. A deployed outdoor temperature sensor gradually shows readings 1.5C higher than a reference thermometer after 6 months. The sensor worked correctly when first installed. What is the most likely cause and solution?

    Return to the chapter’s knowledge check

Caution

Tool versions change and screens may differ. Reopen the supplied setup, check the tool documentation, and use the site feedback control if the problem remains. The screenshots show browser measurements, not hardware calibration; values may vary slightly between runs.

Return to Sensor Calibration: Math and Validation · Browse Labs