Online Circuit Simulator
Temperature controller simulation: heater, thermistor, on/off and PI
We typically respond within one business day.
A 6.8 ohm resistor heats an aluminium block from a 12 V supply through a MOSFET. A 10 kohm NTC thermistor on the block tells an ATmega328P the temperature. The program holds the block at 50 C, either by switching the heater on and off around a band or with a PI controller. The circuit, the block, the sensor and the chip are simulated together.
A teaching model on a bench scale: a low-voltage heater on a small block, with round numbers. It is not a design tool for heating equipment.
Recorded runs. Orange: the block; blue: what the thermistor reads; grey: heater duty; dashed: 50 C. In the PI run a fan starts at 250 s.
What is being simulated?
The block is one thermal mass C that loses heat to the air through a thermal resistance Rth. The thermistor bead follows the block with its own lag of 8 s. Its resistance falls with temperature by the B equation, and a 10 kohm resistor to 5 V turns that into a voltage on A0.
C dT/dt = P_heater - (T - T_air) / Rth
R(T) = R25 exp(B (1/T - 1/298.15 K))
| Part | Value |
|---|---|
| Heat capacity C | 40 J/K |
| Thermal resistance to air Rth | 2.5 K/W |
| Air | 25 C |
| Heater (12 V, 6.8 ohm) | 20.9 W |
| Thermistor | 10 kohm at 25 C, B 3950 K |
| Sensor lag | 8 s |
The block alone has a time constant C Rth = 100 s. At full power it would settle at 77.2 C, and it passes 50 C after 65.2 s. At 50 C the thermistor is 3588 ohm, A0 reads 1.320 V, and holding the block there takes 47.9 % duty.
What does the default program do?
Every 100 ms it reads A0 and turns the code into a temperature with a table of 65 points and straight lines between them; the table is never off by more than 0.10 C between 30 and 80 C. A switch on D3 picks the controller. On/off: heater on below 49.5 C, off above 50.5 C. PI: 1.2 % of duty per 0.1 C of error plus an integral with a 38 s integral time, with anti-windup.
With on/off the reading stays between 49.1 and 51.0 C, but the block swings 4.2 C from peak to peak with a period of 32 s: the sensor lags, so the heater is still on when the reading reaches the top of the band. With PI the block settles within 0.2 C of 50 C by 144 s with no overshoot, and the fan at 250 s pulls it down by 2.0 C before the controller brings it back.
Default program in AVR assembly
Default program in C
- Temperature table for the assembly program (thermo_table.inc)
- Temperature table for the C program (thermo_table.h)
Lessons and challenges
- Full power. Leave the heater on. The block passes 50 C at 65.2 s, and the reading only at 73.6 s: that gap is the sensor lag.
- On/off. Close the switch on D3. Measure the swing of the block and the period, then make the band narrower: the reading tightens, the block hardly does.
- PI. Check: within 0.2 C of 50 C by 160 s, no overshoot above 50.2 C.
- Windup. Build the program without anti-windup. The integral grows while the heater is pinned at 100 %, and the block overshoots by 3.9 C.
- Disturbance. The fan lowers Rth from 2.5 to 1.5 K/W at 250 s. The new duty is 79.9 %; the controller finds it by itself.
- Challenge: make the table smaller. Use 17 points and keep the error under 0.5 C between 30 and 80 C, or compute the temperature without a table.
Where do the parts go?
You can put the thermistor next to the heater, in the middle of the block or at the far edge, and choose how much lag its mounting adds. More lag makes on/off control swing wider and asks for gentler PI gains.
How were the numbers checked?
The thermal model was checked against its first-order step response and the exact two-lag response of the sensor. The on/off run was compared with an ideal on/off model, and the PI programs in assembly and C give the same PWM values; the assembly program also ran on the project framework solver.
Get your project started
We typically respond within one business day.