Fan
A fan moves air. The shop's part costs $6 and is a world-coupled load: on the board it is a small 5 V stand-in, but in the simulated world it exchanges the air in its room with the outdoors — pulling the zone's temperature, humidity and CO₂ towards the outside and adding its hum to the room's sound. That makes it the actuator for ventilation: a greenhouse fan switched on when it gets too hot, or a fan burst that blows fresh air through a stuffy room. It cannot be driven from a GPIO (the stand-in alone draws 100 mA); it goes behind a relay.
Pins
| Pin | What it is | Type |
|---|---|---|
| + | Supply + (switched through a relay) | passive |
| - | Supply − | passive |
| Setting | Type | Range | Default |
|---|---|---|---|
airflow | number | 0.1–5 | 1 |
Fan()— Fan — $6- Pins: 2
- Chain ends:
+ >> fan >> -
The two leads are a supply loop: + takes the switched supply (through the relay's NO contact) and − returns to the supply ground. Wire the relay into the + side, as the relay + fan kit does.
Wiring it in circuit.py
A high-trigger relay switching the fan from the Pi's 5 V rail:
from wiring import *
pi = Pi()
relay = Relay("high") # IN high = contacts closed
fan = Fan() # Fan(airflow=2) for a window fan twice as strong
pi.V5 >> relay.dc_plus
pi.V5 >> relay.com # switched supply in at COM
relay.no >> fan.plus # out at NO, into the fan
fan.minus >> relay.dc_minus
relay.dc_minus >> pi.GND
pi.GPIO17 >> relay.signalFan takes its airflow setting by name (0.1–5, default 1 = one room-volume exchanged per the zone's timescale). It is a world-model number, not something Python can measure.
Driving it in main.py
from gpiozero import OutputDevice
from time import sleep
blow = OutputDevice(17)
while True:
blow.on()
sleep(5)
blow.off()
sleep(5)The program drives the relay; the fan's effect happens in the world. A real controller would read a temperature or humidity sensor first — see the DHT22 page and the thermostat recipe for that loop.
Electrical notes
- On the board, every load is a 50 Ω stand-in: 5 V across it draws 100 mA, well past a GPIO's safe 16 mA. The relay's contacts switch it instead.
- Its effect on the world scales with
(V ÷ 5 V)², clamped to 1.5, and below 2 % of full it counts as off. airflowmultiplies how fast the zone mixes with outdoor air. At the default 1, the indoor model's wall leakage is doubled; a greenhouse's temperature and a room's CO₂ relax at(1 + airflow)times their normal rate.- The fan also reports 45 dB of sound into its zone whenever it is running, so a sound sensor nearby hears it.
- A relay switches a fan on and off only; PWM-ing a relay would arc and wear it out. For speed control, a motor driver such as the DC motor + L298N is the part.
Simulator vs real hardware
- The behaviour is the shared load model: a 50 Ω resistor across
+/−, a level that follows the supply, and a world effect ofairflow × level(plus 45 dB of sound). While off it reports no load. - It does not cool air. It swaps it: indoor zones pull towards the outdoor temperature through
leakage × (1 + airflow), and the CO₂ rate scales the same way. What makes a room "cold" after a fan is mostly evaporative and felt cooling — the model keeps the physics honest. - The fan acts on the zone it is placed in (
indoorby default, changeable in the inspector). Sensing the effect works exactly as with the heater: a DHT22 on its world feed in the same zone sees the temperature move. - In the judge, an objective's
environmentpins sensor readings, so checks do not depend on the zone's slow response; the load still acts on the zone for sensors left on their world feed. - The canvas spins the fan blades while it runs (
spins: true); the simulator has no bearing noise beyond the sound figure.
Going deeper
- The switch that makes it safe: relay module and the primer relays and switching loads.
- Kit: relay + fan.
- Recipe: thermostat with a relay — swap the heater for a fan and it ventilates.
- Sibling loads: heater, pump, lamp.
Further reading
- gpiozero: OutputDevice — the class the relay is driven with.
- Raspberry Pi 4 datasheet — why a pin is a signal, not a power supply.
- Adafruit: Power Relay FeatherWing pinouts — switching a load through COM/NO.