Skip to content
Tactiverge

School/△ Builder/Week 26

On/off control and hysteresis

A heater with a single switch-point clicks on and off dozens of times a minute when the temperature hovers near it. How do real thermostats stop that?

About 35 min · 3 goals · Checked by automated tests

1.Why should I care?

Most fridges, irons, kettles and many greenhouses use on/off control because it is simple and the heater or compressor is either on or off anyway. Hysteresis is the small idea that makes it practical, and it is exactly what your term project needs.

  • ◇ Describe on/off (bang-bang) control and its typical temperature swing.
  • ◇ Explain how a hysteresis band reduces switching, especially with a noisy sensor.
  • ◇ Choose switch-on and switch-off thresholds that meet a comfort band.

2.Predict

A thermostat switches on below 18.0 °C and off above 18.0 °C. The thermometer jitters by ±0.3 °C. What happens near 18 °C?

Guess first. Being wrong here is how the surprise works.

3.Discover

Do Level 3 of the Smart Greenhouse: the vent is left open overnight and the thermometer is noisy. Set the switch-on and switch-off temperatures so the seedlings stay within 16–24 °C for all but 10 minutes and the heater switches no more than 80 times. Note the default's switch count first.

Can't use the interactive? Read a description instead

Smart Greenhouse Level 3 runs a simulated night with the vent open from 22:00 to 01:00 and a noisy thermometer. You set the switch-on and switch-off temperatures (and optional smoothing). The results show minutes spent outside 16–24 °C, the number of heater switchings and the energy used. A tiny gap switches hundreds of times; a gap of about 1.5–2 °C near the bottom of the band passes.

4.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1

A thermostat uses a setpoint of 20 °C and a total hysteresis band of 3 °C, centred on the setpoint. Below what temperature does the heater switch on, in °C?

°C

5.Watch

→ Look for how a mechanical thermostat builds in a gap between switching on and switching off, and why that gap matters.

Opens up classic thermostats to show the clever mechanical tricks behind simple on/off temperature control.

17 min 3 s · captions on YouTube · source

Nothing loads from YouTube until you press play.

The video is optional: everything you need is also in the lesson text and the interactive.

6.Understand

Bang-bang control

On/off control has two outputs: full power or none. If too cold, heater on; if warm enough, heater off. The temperature therefore rises and falls around the setpoint in a sawtooth. It is cheap and robust, and the swing is often acceptable for rooms, fridges and greenhouses.

Two thresholds, not one

Hysteresis uses separate thresholds: switch on below the lower one and off above the upper one; between them, keep doing whatever you were doing. In code:

if temp < ON_BELOW:
    heater = True
elif temp > OFF_ABOVE:
    heater = False
# otherwise: no change

Notice it is a two-state machine: the heater's current state decides what happens in the band.

Choosing the band

A wider band means fewer switchings (less wear on relays and compressors) but a bigger temperature swing. A narrower band holds the temperature tighter but chatters with noise. A good rule: make the band clearly wider than the sensor noise, and place it so the swing stays inside the comfort range, remembering the temperature overshoots a little after each switch.

Explain it another way

Like deciding when to put on and take off a jumper. If you swap the moment you feel a tiny bit warm or cold, you spend all day changing. So you wait until you are clearly cold, and clearly warm.

Worked example 1

Seedlings must stay between 16 and 24 °C. The thermometer jitters by about ±0.3 °C, and the air overshoots by about 0.5 °C after each switch. Suggest thresholds.

Keep the lowest dip (on-threshold minus overshoot minus noise) above 16 °C: on below about 16.8 °C. Off above about 18.5 °C gives a 1.7 °C band, much wider than the 0.6 °C noise, and stays far below 24 °C. Then test in the simulator, because the overshoot estimate is a guess.

Common mix-ups

  • Hysteresis makes the controller less accurate, so avoid it.
    ✓ It deliberately allows a small swing to stop chattering. Without it, noise wears out relays and can cause rapid cycling.
  • The temperature stays inside the band.
    ✓ Thermal lag makes it overshoot both thresholds a little. Leave room for that.

7.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 2

With 'on below 17, off above 19', the heater is ON and the temperature is 18.2 °C. What does the controller do?

Practice 3

What do you trade when you widen the hysteresis band?

Practice 4

A heater relay is rated for 100,000 switchings. A thermostat without hysteresis switches 350 times a night. With a 2 °C band it switches 60 times a night. How many more nights does the relay last with hysteresis? (Nights with band minus nights without, to the nearest night.)

nights

Practice 5

Your thermometer jitters by ±0.4 °C. Which band is most likely to chatter?

8.Apply it

Pass Smart Greenhouse Level 3 and record three runs: the default thresholds, your passing thresholds, and a band that is too wide. Make a table of time outside 16–24 °C, number of switchings and energy, and write one sentence on what the gap between on and off does.

Open BUILD 007: Design a Smart Greenhouse →

9.Reflect

Concepts: Open-loop and closed-loop control · Noise and filtering