import math
R_PULLUP = 4700
ADC_MAX = 4095
TOPOLOGY = "ntc-low"
R25 = 100000
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 210 C -> ADC ~ 482
print(f"{adc_to_temp_c(482):.2f} C")
Choose a bias resistor near the NTC resistance at your most critical temperature to maximize mV/°C sensitivity and minimize quantization error.
Why 3D printer boards pair a 100 kΩ NTC with a 4.7 kΩ pull-up
A 100 kΩ NTC drops dramatically to roughly 400–600 Ω at 200–220 °C printing temperatures. Using a 100 kΩ pull-up would crush the hotend voltage down near 15 mV with terrible ADC resolution; swapping to a 4.7 kΩ bias resistor shifts maximum voltage sensitivity up into the 150–250 °C nozzle band.
Use the 65-point or 129-point LUT setting to maintain tight temperature resolution across both bed-heating (60 °C) and hotend-extrusion (210–250 °C) regions.
Formulas
At 210 °C (483.15 K): R_ntc ≈ 512 Ω
V_adc = 3.3 V × R_ntc ÷ (4,700 + R_ntc)
Self-heating = V_adc² ÷ R_ntc
Worked example
At 210 °C, a 100 kΩ B3950 thermistor drops to ~512 Ω. With a 4.7 kΩ pull-up on 3.3 V, V_adc is ~0.324 V (12-bit code ~402) with −4.9 mV/°C sensitivity and ~0.16 °C/LSB resolution.
Frequently asked questions
Why does room-temperature resolution look coarse with a 4.7 kΩ pull-up on a 100 kΩ NTC?
At 25 °C the 100 kΩ thermistor dwarfs the 4.7 kΩ resistor, pushing V_adc to 95.5% of Vref. That trade-off is intentional to maximize precision at 200 °C.
Should I use 12-bit or 16-bit oversampling for a hotend thermistor?
Software oversampling (averaging 16–64 12-bit samples) smooths PWM heater switching noise and improves PID derivative stability without changing hardware.
What happens if a hotend thermistor wire opens or shorts?
In NTC-low wiring, an open wire pulls ADC to 4095 (clamped cold) while a dead short pulls ADC to 0 (clamped hot); firmware must trigger thermal-runaway mintemp/maxtemp faults on both rails.