---
title: "Project: a thermistor thermometer"
heading: Design a sensor divider for an ADC, and find its resolution
eyebrow: C1 · Lesson 28 · Project
xp: 80
---

::: hook
The cheapest accurate thermometer in electronics is a thermistor, a resistor whose resistance falls steeply as it warms, in a divider feeding a microcontroller's analog-to-digital converter. Coffee makers, 3D printers, battery chargers and car engines all use one. The whole design is a DC circuit problem: choose the fixed resistor so the voltage changes as much as possible per degree, check that the converter's smallest step corresponds to a small enough temperature change, and keep the measuring current from warming the sensor. In this project you'll model it in Python and choose the resistor for a given temperature range.
:::

::: play
- A 10 kΩ NTC thermistor (B = 3950 K) on top of a fixed resistor $R_f$, from $V_{cc}$. The curve is the divider's output against temperature.
- The curve is steepest where the thermistor's resistance equals $R_f$. Move $R_f$ and watch the steep part slide along the temperature axis.
- The readouts give the slope at the marked temperature and the temperature step one count of a 12-bit converter represents.
:::
:::

```sim plot
view: graph
x: T = -40..125 °C
y: V = 0..5 V
slider: Vcc = 3.3..5 step 1.7 = 3.3 V
slider: Rf = 1..100 = 10 kΩ log
slider: T0 = -40..125 step 1 = 25 °C
plot: Vcc*Rf*1000/(Rf*1000 + 10000*exp(3950*(1/(T + 273.15) - 1/298.15))) | label: divider output | samples: 400
marker: x = T0 | label: T
readout: thermistor at T, kΩ = 10*exp(3950*(1/(T0 + 273.15) - 1/298.15)) | digits: 4
readout: slope at T, mV/°C = 1000*Vcc*Rf*1000*10000*exp(3950*(1/(T0 + 273.15) - 1/298.15))*3950/((T0 + 273.15)^2*(Rf*1000 + 10000*exp(3950*(1/(T0 + 273.15) - 1/298.15)))^2) | digits: 3
readout: one 12-bit count, °C = (Vcc/4096)/(Vcc*Rf*1000*10000*exp(3950*(1/(T0 + 273.15) - 1/298.15))*3950/((T0 + 273.15)^2*(Rf*1000 + 10000*exp(3950*(1/(T0 + 273.15) - 1/298.15)))^2)) | digits: 3
```

::: predict
## To make the divider most sensitive at 50 °C, what fixed resistor should go with a 10 kΩ (at 25 °C) thermistor that reads 3.59 kΩ at 50 °C?

- [ ] 10 kΩ, the thermistor's rated value
- [x] About 3.6 kΩ, its value at 50 °C
- [ ] As large as possible
- [ ] As small as possible

::: reveal
About 3.6 kΩ. The divider's output changes fastest with the thermistor's resistance when the two are equal, so the fixed resistor should match the thermistor at the temperature you care most about. 10 kΩ would be the right choice for 25 °C.
:::
:::

::: nameit
## The thermistor

An NTC (negative temperature coefficient) thermistor follows, closely enough for most designs,

$$R_T = R_{25}\,e^{B\left(\frac1T - \frac{1}{298.15\text{ K}}\right)}$$

with $T$ in kelvins, $R_{25}$ its value at 25 °C and $B$ a constant of a few thousand kelvins from the datasheet. Its relative slope, $-B/T^2$, is about −4.4% per °C at room temperature, more than fifty times a silicon sensor's (B9).

## The divider

With the thermistor on top and $R_f$ below, from $V_{cc}$:

$$V_\text{out} = V_{cc}\frac{R_f}{R_f + R_T}$$

which rises with temperature. Its slope is

$$\frac{dV}{dT} = V_{cc}\frac{R_fR_T}{(R_f + R_T)^2}\cdot\frac{B}{T^2}$$

At a single temperature it's largest for $R_f = R_T(T)$. Over a range, the slope falls off at both ends, so the best $R_f$ is the one whose *worst* point is best.

## The converter

An $N$-bit converter whose reference is the same $V_{cc}$ (a **ratiometric** design, so supply changes cancel) has a step of $V_{cc}/2^N$. One count then corresponds to

$$\Delta T = \frac{V_{cc}/2^N}{dV/dT}$$

## Self-heating

The thermistor dissipates $P = V_T^2/R_T$, and its **dissipation constant** δ (mW/°C) says how much that warms it: $\Delta T = P/\delta$. Keep $P$ small, with larger resistors or by powering the divider only while measuring.
:::

::: example
## A 10 kΩ thermistor (B = 3950 K) with a 10 kΩ fixed resistor runs from 3.3 V into a 12-bit converter. What does it read at 25 °C, and how fine is its resolution?

::: solution
1. **Reading at 25 °C.** $R_T$ = 10 kΩ, so $V_\text{out}$ = 1.65 V.
2. **The slope.**
   $$\begin{aligned} \frac{dV}{dT} &= 3.3 \times \frac{10^8}{(2 \times 10^4)^2} \\ &\quad \times \frac{3950}{298.15^2} \\ &= 36.7\ \text{mV/°C} \end{aligned}$$
3. **One count.**
   $$\frac{3.3}{4096} = 0.806\ \text{mV}$$
4. **Resolution in degrees.**
   $$\frac{0.806}{36.7} = 0.022\ \text{°C}$$

**Answer:** it reads 1.65 V at 25 °C, and one count is 0.022 °C.
:::
:::

::: example
## In that divider, the thermistor has 1.65 V across it and a dissipation constant of 1.5 mW/°C. How much does it heat itself?

::: solution
1. **Power.**
   $$\begin{aligned} P &= \frac{1.65^2}{10^4} \\ &= 0.27\ \text{mW} \end{aligned}$$
2. **Temperature rise.**
   $$\begin{aligned} \Delta T &= \frac{0.27}{1.5} \\ &= 0.18\ \text{°C} \end{aligned}$$
   eight times the converter's resolution.
3. **Reducing it.** A larger thermistor, or switching the divider on only to measure, reduces it.

**Answer:** the thermistor heats itself by 0.18 °C.
:::
:::

::: check
given: T = 0 | 50 | 100; B = 3435 | 3950
answer: 10*exp(B*(1/(T + 273.15) - 1/298.15))
unit: kΩ
tolerance: 0.5%

## A 10 kΩ NTC thermistor has B = {B} K. What is its resistance at {T} °C?

::: right
Right. $R_{25}e^{B(1/T - 1/298.15)}$ = {answer}.
:::

::: misses
- [any] Not yet. Convert to kelvins first: $T + 273.15$, and 25 °C is 298.15 K.
:::
:::

::: check
given: Vcc = 3.3 | 5; Rf = 4.7 | 15 | 22; RT = 3.6 | 10 | 33
answer: Vcc*Rf/(Rf + RT)
unit: V
tolerance: 0.5%

## The thermistor reads {RT} kΩ on top of a {Rf} kΩ fixed resistor, from {Vcc} V. What is the output?

::: right
Right. $V_{cc}\frac{R_f}{R_f + R_T}$ = {answer}.
:::

::: misses
- [Vcc*RT/(Rf + RT)] The output is across the fixed resistor at the bottom.
- [any] Not yet. A divider with $R_f$ at the bottom.
:::
:::

::: check
given: T = 0 | 40 | 60
answer: 10*exp(3950*(1/(T + 273.15) - 1/298.15))
unit: kΩ
tolerance: 0.5%

## What fixed resistor makes the divider most sensitive at {T} °C, with a 10 kΩ, B = 3950 K thermistor?

::: right
Right. Match the thermistor's value there: {answer}.
:::

::: misses
- [10] 10 kΩ is the best match only at 25 °C.
- [any] Not yet. $R_f = R_T(T)$.
:::
:::

::: check
given: Vcc = 3.3 | 5; N = 10 | 12 | 16
answer: Vcc/2^N*1000
unit: mV
tolerance: 0.5%

## An {N}-bit converter has a {Vcc} V reference. How big is one count?

::: right
Right. $V_{cc}/2^N$ = {answer}.
:::

::: misses
- [any] Not yet. $V_{cc}/2^N$.
:::
:::

::: check
given: s = 10 | 25 | 37; Vcc = 3.3 | 5; N = 10 | 12
answer: Vcc/2^N*1000/s
unit: °C
tolerance: 0.5%

## A divider's output changes by {s} mV/°C, read by an {N}-bit converter with a {Vcc} V reference. What temperature step does one count represent?

::: right
Right. $\frac{V_{cc}/2^N}{dV/dT}$ = {answer}.
:::

::: misses
- [s/(Vcc/2^N*1000)] That's counts per degree; invert it.
- [any] Not yet. One count's voltage over the slope.
:::
:::

::: check
given: V = 1 | 1.65 | 2.5; R = 10 | 100; d = 1 | 2
answer: V^2/(R*1000)*1000/d
unit: °C
tolerance: 0.5%

## A thermistor of {R} kΩ has {V} V across it and a dissipation constant of {d} mW/°C. How much does it heat itself?

::: right
Right. $\frac{V^2/R}{\delta}$ = {answer}.
:::

::: misses
- [any] Not yet. Power $V^2/R$ in mW, over δ.
:::
:::

::: check
kind: python

## Write `rt(Tc)` for a 10 kΩ, B = 3950 K thermistor (`Tc` in °C), and `vout(Tc, Rf, Vcc=3.3)` for the divider with the thermistor on top.

```python starter
import numpy as np

def rt(Tc):
    return 10e3 * (1 - 0.044 * (Tc - 25))

def vout(Tc, Rf, Vcc=3.3):
    return Vcc * Rf / (Rf + rt(Tc))

print(rt(0), vout(25, 10e3))
```

```python solution
import numpy as np

def rt(Tc):
    T = Tc + 273.15
    return 10e3 * np.exp(3950 * (1 / T - 1 / 298.15))

def vout(Tc, Rf, Vcc=3.3):
    return Vcc * Rf / (Rf + rt(Tc))

print(rt(0), vout(25, 10e3))
```

```python tests
import numpy as np
assert abs(rt(25) - 10e3) < 1e-6, "At 25 °C the thermistor should read 10 kΩ."
assert abs(rt(0) - 33620.60) < 0.5, f"At 0 °C it should read 33.62 kΩ; got {rt(0):.1f}."
assert abs(rt(100) - 697.52) < 0.05, f"At 100 °C it should read 697.5 Ω; got {rt(100):.2f}."
assert abs(vout(25, 10e3) - 1.65) < 1e-9, "Equal resistors from 3.3 V give 1.65 V."
assert abs(vout(100, 3300) - 3.3 * 3300 / (3300 + 697.5197729861881)) < 1e-6, "Check the divider orientation: thermistor on top."
```

::: right
Right. The linear starter is fine near 25 °C and badly wrong at 0 and 100 °C: thermistors are strongly nonlinear.
:::
:::

::: check
kind: python

## Write `resolution(Tc, Rf, bits=12, Vcc=3.3)`: the temperature (°C) one converter count represents at `Tc`, using a central-difference slope of `vout` with a step of 0.01 °C.

```python starter
import numpy as np

def rt(Tc):
    return 10e3 * np.exp(3950 * (1 / (Tc + 273.15) - 1 / 298.15))

def vout(Tc, Rf, Vcc=3.3):
    return Vcc * Rf / (Rf + rt(Tc))

def resolution(Tc, Rf, bits=12, Vcc=3.3):
    return Vcc / 2 ** bits

print(resolution(25, 10e3))
```

```python solution
import numpy as np

def rt(Tc):
    return 10e3 * np.exp(3950 * (1 / (Tc + 273.15) - 1 / 298.15))

def vout(Tc, Rf, Vcc=3.3):
    return Vcc * Rf / (Rf + rt(Tc))

def resolution(Tc, Rf, bits=12, Vcc=3.3):
    slope = (vout(Tc + 0.01, Rf, Vcc) - vout(Tc - 0.01, Rf, Vcc)) / 0.02
    return (Vcc / 2 ** bits) / slope

print(resolution(25, 10e3))
```

```python tests
r = resolution(25, 10e3)
assert abs(r - 0.0219772) < 2e-6, f"At 25 °C with 10 kΩ, one count is 0.0220 °C; got {r:.6f}."
r = resolution(100, 10e3)
assert abs(r - 0.1411951) < 2e-5, f"At 100 °C the curve flattens: one count is 0.141 °C; got {r:.5f}."
r = resolution(25, 10e3, bits=10, Vcc=5)
assert abs(r - 0.0219772 * 4) < 1e-5, f"Ratiometric: Vcc cancels, and 10 bits is 4 times coarser than 12; got {r:.5f}."
```

::: right
Right. The supply voltage cancels: a ratiometric design reads the same with 3.3 V or 5 V.
:::
:::

::: check
kind: python

## Write `best_rf(T1, T2, bits=12)`: from E24 values in 1 kΩ to 91 kΩ (the list is given), return `(Rf, worst)`, the fixed resistor whose worst resolution over 101 evenly spaced temperatures from `T1` to `T2` °C is smallest, and that worst value.

```python starter
import numpy as np
E24 = [1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1]
CANDIDATES = [m * 10 ** e for e in (3, 4) for m in E24]

def rt(Tc):
    return 10e3 * np.exp(3950 * (1 / (Tc + 273.15) - 1 / 298.15))

def vout(Tc, Rf, Vcc=3.3):
    return Vcc * Rf / (Rf + rt(Tc))

def resolution(Tc, Rf, bits=12, Vcc=3.3):
    return (Vcc / 2 ** bits) / ((vout(Tc + 0.01, Rf, Vcc) - vout(Tc - 0.01, Rf, Vcc)) / 0.02)

def best_rf(T1, T2, bits=12):
    return 10e3, resolution((T1 + T2) / 2, 10e3, bits)

print(best_rf(0, 100))
```

```python solution
import numpy as np
E24 = [1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1]
CANDIDATES = [m * 10 ** e for e in (3, 4) for m in E24]

def rt(Tc):
    return 10e3 * np.exp(3950 * (1 / (Tc + 273.15) - 1 / 298.15))

def vout(Tc, Rf, Vcc=3.3):
    return Vcc * Rf / (Rf + rt(Tc))

def resolution(Tc, Rf, bits=12, Vcc=3.3):
    return (Vcc / 2 ** bits) / ((vout(Tc + 0.01, Rf, Vcc) - vout(Tc - 0.01, Rf, Vcc)) / 0.02)

def best_rf(T1, T2, bits=12):
    temps = np.linspace(T1, T2, 101)
    best = None
    for Rf in CANDIDATES:
        worst = max(resolution(T, Rf, bits) for T in temps)
        if best is None or worst < best[1]:
            best = (Rf, worst)
    return best

print(best_rf(0, 100))
```

```python tests
rf, worst = best_rf(0, 100)
assert abs(rf - 3300) < 1e-6, f"For 0 to 100 °C the best E24 value is 3.3 kΩ; got {rf:.0f} Ω."
assert abs(worst - 0.0597476) < 2e-5, f"Its worst resolution is 0.0597 °C; got {worst:.5f}."
rf, worst = best_rf(-20, 40)
assert abs(rf - 18000) < 1e-6, f"For -20 to 40 °C the best is 18 kΩ; got {rf:.0f} Ω."
```

::: right
Right. For 0 to 100 °C the best choice, 3.3 kΩ, is close to the thermistor's value near the middle of the range, but not exactly: the worst point is what matters.
:::
:::

::: explain
## Why is a thermistor divider read by a converter whose reference is the same supply that feeds the divider?

::: model
The divider's output is a fixed fraction of its supply, set only by the two resistances. A converter reports its input as a fraction of its reference voltage. If the reference is the same supply, any change in that supply scales the input and the reference together, and the converter's reading, the fraction, stays the same. The supply's tolerance, noise and drift all cancel, so the measurement depends only on the thermistor and the fixed resistor. With a separate reference, every millivolt of supply error would look like a temperature change.
:::
:::

::: practice

::: check
given: T = 25 | 37 | 85
answer: 3950/(T + 273.15)^2*100
tolerance: 0.5%

## By what percentage per °C does a B = 3950 K thermistor's resistance fall at {T} °C?

::: misses
- [any] $B/T^2$, with $T$ in kelvins.
:::
:::

::: check
given: N = 10 | 12; V = 3.3 | 5; s = 20 | 40
answer: s/(V/2^N*1000)
tolerance: 0.5%

## A signal changes by {s} mV/°C into an {N}-bit converter with a {V} V reference. How many counts per °C is that?

::: misses
- [any] Slope over one count's voltage.
:::
:::

::: check
given: R = 10 | 100; V = 1.65 | 2.5
answer: V^2/(R*1000)*1000
unit: mW
tolerance: 0.5%

## How much power does a {R} kΩ thermistor dissipate with {V} V across it?

::: misses
- [any] $V^2/R$.
:::
:::
:::
