Lite / Building Machines That Respond / 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?
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.
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?
- Nothing unusual
- The heater chatters on and off rapidly as the noise crosses 18.0 °C
- The heater stays off
Guess first, then reveal
Every jitter across the single switch-point flips the heater. Splitting it into two thresholds (on below 17, off above 19) means noise must be much larger to cause a switch: that gap is **hysteresis**.
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.
What the interactive shows (text version)
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.
Watch (optional)
Watch for: 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.
“Thermostats: Cooler than you think!” by Technology Connections (opens YouTube; streaming video uses a lot of data)
The video is optional. Everything you need is in this lesson's text.
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 changeNotice 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
Intuitive
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.
Technical
Hysteresis gives on/off control a limit cycle whose amplitude is set by the band plus overshoot from thermal lag. A Schmitt-trigger input does the same for noisy digital signals in hardware.
Mathematical
With setpoint r and total band h: on below r − h/2, off above r + h/2. For r = 18 °C, h = 2 °C: on below 17, off above 19.
Applied
Domestic fridges often cycle their compressor with a band of a few degrees; a greenhouse heater might use 1.5–2 °C, as in the Smart Greenhouse Level 3 answer.
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.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
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.
Reflect
Where else could a gap between two thresholds stop a machine from dithering? (Think about the debouncer in week 20.)
Write your answer on paper or in your own notes. Lite never stores what you write.