import math
R_PULLUP = 10000
ADC_MAX = 4095
TOPOLOGY = "ntc-low"
R25 = 10000
BETA = 3950
def adc_to_temp_c(adc: int) -> float:
if adc <= 0 or adc >= ADC_MAX:
raise ValueError("ADC reading saturated at rail")
ratio = adc / ADC_MAX
r_ntc = R_PULLUP * ratio / (1.0 - ratio) if TOPOLOGY == "ntc-low" else R_PULLUP * (1.0 - ratio) / ratio
inv_t = (1.0 / 298.15) + math.log(r_ntc / R25) / BETA
return (1.0 / inv_t) - 273.15
# Example spot check at 25 C -> ADC ~ 2048
print(f"{adc_to_temp_c(2048):.2f} C")
Choose a bias resistor near the NTC resistance at your most critical temperature to maximize mV/°C sensitivity and minimize quantization error.
Build a zero-float firmware LUT for a 10 kΩ B3950 NTC thermistor
The 10 kΩ (R25) B3950 NTC paired with a 10 kΩ 1% pull-up resistor is the universal baseline temperature sensor across battery packs, power supplies and IoT hardware. At 25 °C the divider sits right at mid-scale (Vref / 2), giving maximum sensitivity across ambient and warm operating temperatures.
Switch between the Beta model and three-term Steinhart-Hart coefficients, inspect the R-T curve SVG, and copy the generated 33-point or 65-point C99 lookup table directly into your embedded firmware.
At 25 °C, R_ntc = 10.00 kΩ, V_adc = 1.650 V (ADC 2,048), sensitivity is −36.5 mV/°C and each 12-bit LSB resolves ~0.022 °C.
Frequently asked questions
How accurate is a 33-point C99 linear-interpolated LUT for a 10 kΩ NTC?
Between 0 °C and 85 °C, a 33-point power-of-two LUT typically interpolates within ±0.15 °C of the continuous equation; choose 65 points to stay within ±0.04 °C.
Why store temperatures as int16_t tenths of °C (c_x10)?
Fixed-point tenths of °C cover −3,276.8 °C to +3,276.7 °C in just 2 bytes per entry without pulling floating-point math libraries into flash.
Does Vref accuracy affect a ratiometric NTC voltage divider?
No! Because both the NTC pull-up and the ADC reference share the same Vref rail, supply voltage variations cancel out completely in the ADC count.