Skip to content

Convert an NTC ADC reading to temperature

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

How to complete this Wokwi lab

Your task: Convert an NTC ADC reading to temperature

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

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

    The sensor part is a Wokwi NTC temperature sensor (diagram.json line 15). Power: NTC VCC connects to ESP32 3.3 V (diagram.json line 26). Ground: NTC GND connects to ESP32 ground (diagram.json line 35). Analog output: NTC OUT connects to ESP32 GPIO32 (diagram.json line 44).

    Why it matters: GPIO32 is the analog input used by the later range check and resistance calculation. The sensor supply and ground establish the simulated divider reference.

  2. Recorded result for step 2

    Read ADC GPIO32: int raw=analogRead(32); (sketch.ino line 4). Reject the ADC endpoints: raw<=0 || raw>=4095 (sketch.ino line 5). Print an out-of-range warning: Serial.println("Out of range: check wiring") (sketch.ino line 5). Calculate resistance from the ADC count: double resistance=10000.0*raw/(4095.0-raw); (sketch.ino line 6).

    Why it matters: The range guard rejects either saturated ADC endpoint before division. Only an in-range count reaches the resistance calculation used by later temperature estimates.

  3. Recorded result for step 3

    Input: NTC at its supplied 25 C setting. Observed: "ADC=2048, R=10005 ohm, T=24.99 C". Observed: the Serial Monitor repeats the same result. Expected: a fresh ADC count, resistance and temperature line.

    Why it matters: The live line includes the conversion input and intermediate resistance. The displayed temperature is close to the simulator setting. The repeated line shows that the sketch continues sampling. A simulator setting is not an independent calibration standard.

  4. Recorded result for step 4

    Input: NTC at 25 C. Observed: "ADC=2048, R=10005 ohm, T=24.99 C". Expected: a near-25 C converted result. Difference from the setting: 0.01 C in this run.

    Why it matters: The raw count is 2048. The derived resistance is 10005 ohm. The displayed result is 24.99 C. This comparison checks the model output at one setting only.

  5. Recorded result for step 5

    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.

  6. Recorded result for step 6

    Input: NTC control set to 35 C. Observed: "ADC=1614, R=6505 ohm, T=35.00 C". Expected: lower resistance and a 35 C result. The preceding 25 C line used ADC=2048 and R=10005 ohm.

    Why it matters: The controlled input changed by 10 C. The ADC count fell from 2048 to 1614. The derived resistance fell from 10005 to 6505 ohm. The converted temperature follows the 35 C setting.

  7. Recorded result for step 7

    Input: NTC control restored to 25 C. Observed: "ADC=2048, R=10005 ohm, T=24.99 C". Expected: the initial count, resistance and temperature return. The 35 C line appeared before the restored result.

    Why it matters: The live count returned to 2048. The live resistance returned to 10005 ohm. The displayed temperature returned to 24.99 C. This is a repeatability check within the simulator.

Review the detailed text steps and cautions below.

Physics Phoebe, your practice guide

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

Wokwi ESP32

Third party Tool

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 sensor part is a Wokwi NTC temperature sensor (diagram.json line 15). Power: NTC VCC connects to ESP32 3.3 V (diagram.json line 26). Ground: NTC GND connects to ESP32 ground (diagram.json line 35). Analog output: NTC OUT connects to ESP32 GPIO32 (diagram.json line 44).
    Why it matters
    GPIO32 is the analog input used by the later range check and resistance calculation. The sensor supply and ground establish the simulated divider reference.
    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
    Read ADC GPIO32: int raw=analogRead(32); (sketch.ino line 4). Reject the ADC endpoints: raw<=0 || raw>=4095 (sketch.ino line 5). Print an out-of-range warning: Serial.println("Out of range: check wiring") (sketch.ino line 5). Calculate resistance from the ADC count: double resistance=10000.0*raw/(4095.0-raw); (sketch.ino line 6).
    Why it matters
    The range guard rejects either saturated ADC endpoint before division. Only an in-range count reaches the resistance calculation used by later temperature estimates.
    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 play and read the first Serial Monitor result.
    You will see
    Input: NTC at its supplied 25 C setting. Observed: "ADC=2048, R=10005 ohm, T=24.99 C". Observed: the Serial Monitor repeats the same result. Expected: a fresh ADC count, resistance and temperature line.
    Why it matters
    The live line includes the conversion input and intermediate resistance. The displayed temperature is close to the simulator setting. The repeated line shows that the sketch continues sampling. A simulator setting is not an independent calibration standard.
    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 25 C.
    You will see
    Input: NTC at 25 C. Observed: "ADC=2048, R=10005 ohm, T=24.99 C". Expected: a near-25 C converted result. Difference from the setting: 0.01 C in this run.
    Why it matters
    The raw count is 2048. The derived resistance is 10005 ohm. The displayed result is 24.99 C. This comparison checks the model output at one setting only.
    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 NTC control panel, set temperature to 35 C and read Serial Monitor.
    You will see
    Input: NTC control set to 35 C. Observed: "ADC=1614, R=6505 ohm, T=35.00 C". Expected: lower resistance and a 35 C result. The preceding 25 C line used ADC=2048 and R=10005 ohm.
    Why it matters
    The controlled input changed by 10 C. The ADC count fell from 2048 to 1614. The derived resistance fell from 10005 to 6505 ohm. The converted temperature follows the 35 C setting.
    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 25 C and read Serial Monitor again.
    You will see
    Input: NTC control restored to 25 C. Observed: "ADC=2048, R=10005 ohm, T=24.99 C". Expected: the initial count, resistance and temperature return. The 35 C line appeared before the restored result.
    Why it matters
    The live count returned to 2048. The live resistance returned to 10005 ohm. The displayed temperature returned to 24.99 C. This is a repeatability check within the simulator.
    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 reads 1.5C above a traceable reference after 6 months. Checks with a known electrical input show the ADC and wiring path remain stable. What is the most likely cause and next step?

    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