Raspberry Pi practice problem · Motors & actuators
Heat or cool
HardBudget $30Python · gpiozero
A climate box with a heater and a fan, each switched by its own relay module (Relay("high"), coil on 5 V): the heater relay's input on GPIO17, the fan relay's on GPIO22. Wire each load from 5 V → COM, NO → load +, load − → ground. The two pre-wired kits together cost more than the budget, so buy relays and loads separately.
Three push buttons (to ground, Pi pull-ups): HEAT on GPIO5, COOL on GPIO6, OFF on GPIO13.
- HEAT turns the heater on, COOL the fan, OFF both off. Pressing the button of the mode already running changes nothing.
- Interlock: heater and fan are never on together. When switching from one to the other, the running one goes off at once and the other comes on 1 s later (a dead time).
- From off, the chosen load comes on at once.
The test presses HEAT at 1 s, COOL at 3 s, COOL again at 5 s, HEAT at 6 s and OFF at 8.5 s. So the heater runs 1–3 s and 7–8.5 s, and the fan 4–6 s.