This project might be of interest. The author uses a simple bash
script to read the RPi CPU temperature, and turn a cooling fan on and off based on the temperature. In other words, the fan only runs when the CPU temperature rises above the value you set in the bash
script that controls it.
The hardware requirement is simple enough: a 2N2222 transistor serves as a switch to turn the cooling fan on & off. The 2N2222 is driven from a GPIO pin. A 500𝛀 resistor to bias the transistor properly, and a small diode for back emf protection completes the circuit.
simulate this circuit – Schematic created using CircuitLab
To switch the fan on at 48℃ with GPIO 17 (pin # 11 on the header) requires only the addition of the following line to your file /boot/config.txt
: