Convert an NTC ADC reading to temperature
Use the Steinhart–Hart equation to convert thermistor resistance into temperature.

Physics Phoebe
Predict the reading, then compare it with the measurement.
Wokwi ESP32
Third party ToolOpen 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
- In the Simulation panel, inspect the NTC sensor wiring after pasting both supplied files.
- You will see
- The
sensorpart 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · 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 checkA 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
Return to Sensor Calibration: Math and Validation · Browse Labs