Skip to content
Tactiverge

Inside a Digital Thermostat

A bead whose resistance changes with temperature, a voltage divider, and a deliberate gap that stops your heating clicking on and off all day.

A wall thermostat does one job: keep the room near the temperature you chose. To do it, it turns a temperature into a resistance, the resistance into a voltage, the voltage into a number, and the number into a decision.

Conceptual only. Do not open real devices: they can hold mains voltage, charged capacitors, sharp edges or springs.

1Explode it

Pull the digital thermostat apart.

fig. 07 · digital thermostat, coming apart

20.0°

Parts of the digital thermostat, as a list

  1. Faceplate. The front cover, with slots so room air can flow past the sensor. Engineering idea: Where the sensor sits matters as much as how good it is. Vents let room air reach it, and the electronics are kept away from it so their own warmth does not fool it.
  2. Display. Shows the measured temperature and the setpoint. Engineering idea: Low-power displays let some thermostats run for a year on batteries. The display is updated only when something changes.
  3. Buttons. Raise or lower the setpoint. Engineering idea: Mechanical contacts bounce: one press can look like several on-off flickers. Firmware 'debounces' by waiting a few milliseconds for the signal to settle.
  4. Microcontroller board. Reads the sensor, compares it with the setpoint and decides whether to call for heat. Engineering idea: Its analog-to-digital converter turns the sensor voltage into a number. A few lines of code with hysteresis turn that number into an on/off decision.
  5. Thermistor. A tiny bead whose resistance falls as it warms up (an NTC thermistor). Engineering idea: A resistance is hard to measure directly, so the thermistor is paired with a fixed resistor in a voltage divider. Its temperature becomes a voltage the microcontroller can read.
  6. Relay. A switch the microcontroller controls, which turns the heating system's control circuit on and off. Engineering idea: Isolation: a small, safe signal from the chip switches a separate circuit. Many systems use a low-voltage control circuit; others switch mains, which is one reason never to open a real one.
  7. Wall plate and terminals. Mounts on the wall and holds the screw terminals for the heating wires. Engineering idea: Splitting the wall plate from the electronics means the thermostat can be replaced without rewiring, a common engineering choice called modularity.

2Part by part

What every piece is for.

  1. 01

    Faceplate

    The front cover, with slots so room air can flow past the sensor.

    the idea →Where the sensor sits matters as much as how good it is. Vents let room air reach it, and the electronics are kept away from it so their own warmth does not fool it.

    Design for manufacture

  2. 02

    Display

    Shows the measured temperature and the setpoint.

    the idea →Low-power displays let some thermostats run for a year on batteries. The display is updated only when something changes.

    Digital input and output

  3. 03

    Buttons

    Raise or lower the setpoint.

    the idea →Mechanical contacts bounce: one press can look like several on-off flickers. Firmware 'debounces' by waiting a few milliseconds for the signal to settle.

    Digital input and outputInterrupts and event-driven code

  4. 04

    Microcontroller board

    Reads the sensor, compares it with the setpoint and decides whether to call for heat.

    the idea →Its analog-to-digital converter turns the sensor voltage into a number. A few lines of code with hysteresis turn that number into an on/off decision.

    Inside a microcontrollerAnalog-to-digital conversionSuper-loops and finite state machines

  5. 05

    Thermistor

    A tiny bead whose resistance falls as it warms up (an NTC thermistor).

    the idea →A resistance is hard to measure directly, so the thermistor is paired with a fixed resistor in a voltage divider. Its temperature becomes a voltage the microcontroller can read.

    How sensors measureVoltage dividers

  6. 06

    Relay

    A switch the microcontroller controls, which turns the heating system's control circuit on and off.

    the idea →Isolation: a small, safe signal from the chip switches a separate circuit. Many systems use a low-voltage control circuit; others switch mains, which is one reason never to open a real one.

    Motors, servos and steppersDigital input and output

  7. 07

    Wall plate and terminals

    Mounts on the wall and holds the screw terminals for the heating wires.

    the idea →Splitting the wall plate from the electronics means the thermostat can be replaced without rewiring, a common engineering choice called modularity.

    Constraints, budgets and trade-offs

3The system

How the parts talk to each other.

Almost every machine has the same shape: something senses, something decides, something acts on the world, and a measurement feeds back so the decision can improve.

Inputs(sense)

  • Setpoint buttons
  • Thermistor + dividertemperature → voltage

Controller(think)

  • MicrocontrollerADC + hysteresis

Actuators(act)

  • Relay
  • Heater or boiler

The physical system(what changes)

  • Room temperature

Signals forward

  • Setpoint buttons to Microcontrollertarget temperature
  • Microcontroller to Relaycall for heat
  • Relay to Heater or boileron / off
  • Heater or boiler to Room temperatureheat

Feedback: the loop closes here

  • Room temperature feeds back to Thermistor + dividerair temperature
  • Thermistor + divider feeds back to Microcontrollersensor voltage

4The maths

From temperature to a number

The thermistor sits at the bottom of a voltage divider. As the room cools, its resistance rises, so V_out rises. The ADC turns that voltage into a whole number between 0 and 4095. Then hysteresis: heat on below 19.5 °C, off above 20.5 °C, so the heating does not chatter on and off around 20 °C.

the model

V_out = V_in · R_ntc / (R_fixed + R_ntc), code = ⌊V_out / V_ref · 2ⁿ⌋

Divider output
1.833 V
ADC reading
2,275 counts
Go deeper: the worked numbers

Symbols

R_ntc
thermistor resistance (Ω), about 12.5 kΩ at 20 °C for a common 10 kΩ part
R_fixed
fixed resistor, 10 kΩ
V_in = V_ref
3.3 V supply, also the ADC reference
n
ADC resolution, 12 bits

Worked example

  1. 1.V_out = 3.3 × 12 500 / (10 000 + 12 500) = 1.833 V
  2. 2.code = ⌊1.833 / 3.3 × 4096⌋ = ⌊2275.6⌋ = 2275
  3. 3.The firmware looks 2275 up in a table to get back to about 20 °C

5 · Your turn · Circuits lab

Design the divider

In the Circuits lab, build a voltage divider and change the bottom resistor as if the room were warming and cooling. Which fixed resistor gives the biggest voltage change around 20 °C?

Start the challenge →

runs in your browser, nothing to unscrew

Keep going