Jeremy Cook writes about a simple project to keep the Raspberry Pi 4 cool:
While passive cooling options are often good enough to avoid overheating and thermal throttling–and I do love a ridiculously oversized heat sink–at some point you’ll need to think about using a cooling fan. The problem is that the Raspberry Pi’s GPIO pins don’t supply enough power to get one going.
One alternative is to hook the fan up to a 5V and ground pin, and just have it run continuously. However, this seems slightly wasteful power-wise, and potentially quite annoying. As outlined previously, you can also use a transistor and temperature-reactive Bash script to turn a fan on and off via the processor’s temperature. Things have changed since mid-2020, however, and Raspberry Pi OS now has this functionality built-in. Making things even more convenient, if you’re using a fan with a PWM input, you don’t actually need to add an extra transistor!