Quick summary
- Convert the ADC reading to thermistor resistance using the exact divider topology.
- Convert resistance to temperature using that component’s R/T table, Beta range, or Steinhart–Hart coefficients—not generic values.
- Check ADC endpoint readings, self-heating, filtering, and system-level calibration before using temperature in control logic.
NTC thermistor measurement in embedded C
An NTC thermistor produces a nonlinear resistance change with temperature. A typical microcontroller circuit uses the thermistor and a fixed resistor as a voltage divider, then reads the divider node with an ADC. Firmware must first convert the ADC code to resistance and then use the selected thermistor’s datasheet curve to estimate temperature. The function below shows the calculation for one explicit topology; it does not configure an ADC peripheral or represent a particular product’s specifications.
Assumed divider: Vref → Rfixed → ADC node → NTC → ground. If the NTC and fixed resistor are reversed, the resistance equation changes. Confirm the actual schematic before using the example.
Portable C example: ADC code to temperature
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
/* Returns true on success. Supply parameters from the schematic and datasheet. */
bool ntc_temperature_c(uint16_t adc_code,
uint16_t adc_max_code,
float r_fixed_ohms,
float r25_ohms,
float beta_kelvin,
float *temperature_c)
{
if (temperature_c == NULL || adc_max_code == 0 ||
adc_code == 0 || adc_code >= adc_max_code ||
r_fixed_ohms <= 0.0f || r25_ohms <= 0.0f ||
beta_kelvin <= 0.0f) {
return false; /* Open/short, invalid input, or ADC endpoint */
}
/* Valid only for the divider topology stated above. */
const float resistance_ohms = r_fixed_ohms *
((float)adc_code / (float)(adc_max_code - adc_code));
const float t25_kelvin = 298.15f;
const float inv_t_kelvin = (1.0f / t25_kelvin) +
(logf(resistance_ohms / r25_ohms) / beta_kelvin);
if (!isfinite(resistance_ohms) || resistance_ohms <= 0.0f ||
!isfinite(inv_t_kelvin) || inv_t_kelvin <= 0.0f) {
return false;
}
*temperature_c = (1.0f / inv_t_kelvin) - 273.15f;
return isfinite(*temperature_c);
}
This is a simplified Beta-model example. Provide adc_max_code as the largest usable ADC code for the specific ADC configuration, and use the datasheet’s R25, Beta value, and stated temperature interval. ADC resolution alone does not guarantee measurement accuracy; reference behavior, resistor tolerance, input settling, noise, and sensor thermal conditions also matter.
Resistance-to-temperature conversion choices
The Beta equation estimates temperature in kelvin from resistance using R25 and a model-specific Beta value. It is convenient for a limited interval but does not reproduce every manufacturer’s full R/T curve. If the datasheet provides a resistance table, interpolate within its specified interval. If it provides Steinhart–Hart coefficients, use all three coefficients with the correct logarithm base and temperature units; do not invent coefficients or substitute another thermistor’s constants.
For a deeper look at divider behavior, R/T curves, and tolerance, see our NTC thermistor circuit design guide. Texas Instruments also describes NTC response, conversion approaches, and the coefficient requirements in its thermistor application report.
Validation checks before control use
- Handle ADC codes at or near zero and full scale as open-circuit, short-circuit, or out-of-range conditions for the chosen divider; do not divide by zero.
- Verify the divider orientation, ADC maximum code, reference configuration, and fixed resistor value against the actual board schematic.
- Use modest excitation and check thermistor self-heating. The measured body temperature can differ from the medium being measured.
- Filter only as needed for the system response time; validate filter delay and fault-detection behavior.
- Compare calculated temperature with a calibrated reference at representative points across the application’s operating range, including assembly and environmental conditions.
- Keep safety-critical shutdowns independent of an unvalidated sensor estimate; define open/short handling and safe-state behavior in the product design.
From firmware example to OEM sensor design
The right thermistor depends on the operating range, R/T curve, tolerance, probe geometry, medium, response time, and controller input. Our custom NTC probe assembly guide covers measurement-assembly considerations. For a specific integration review, send the measurement range, divider topology, ADC/reference details, and mechanical environment through the OEM inquiry form. Any sensor selection and performance target still need validation in the final design.
References
- Texas Instruments: thermistor R/T behavior and Steinhart–Hart calculation.
- Analog Devices CN0545: NTC thermistor measurement and model-specific coefficients.
Free NTC R-T Calculator & Custom OEM Sensors
Generate 2K/10K/50K/100K R-T tables in seconds with our free NTC Thermistor Resistance & B-Value Calculator, explore our custom NTC probe assemblies and NTC thermistors, or request a custom OEM quote.


