Simple python script for control speed of a pwm cooling fan.
Tested with a KDB0605HB laptop cooler on a Raspbery Pi 4, Ubuntu server 19.10 64bit, 20.04 64bit; Raspberry Pi OS
- python3 (installed and made default by update-alternatives)
- package RPi.GPIO
- package gpiozero
I assume you connected to Pi via SSH before (Ubuntu server has it and started it by default). ReferenceLink
- Download packages with pip or apt
- pip:
$ pip install RPi.GPIO gpiozero
- or apt:
$ sudo apt-get install python3-rpi.gpio python3-gpiozero
- pip:
- Copy fancontroller.py to user directory (in my case /home/ubuntu)
- Create cron job:
- open crontab:
$ sudo crontab -e
- insert a new line and paste
@reboot /path/to/python3 /path/to/fancontroller.py
- e.g.: "@reboot /usr/bin/python3 /home/ubuntu/fancontroller.py" in my case
- save and exit
- open crontab:
- Reboot Pi and script should work after system startup
I am using Raspberry Pi 4 with KDB0605HB blower fan - whitch is a part of an Asus laptop - as my own DIY project. 300Hz was quite appropriate as PWM output frequency for this cooler, but if you have another type (for example this one), this can be different.
- How to use soft PWM in RPi.GPIO 0.5.2a pt 2 – led dimming and motor speed control
- Raspberry Pi: PWM in GPIO (Python)
- RPi.GPIO basics 4 – Setting up RPi.GPIO, numbering systems and inputs
- class gpiozero.CPUTemperature
Temperature in idle mode fluctuated between 41-43 Celsius under Ubuntu 19.10, therefore PWM.ChangeDutyCycle() got 20% in those loops. Note that Ubuntu server for RPi consumes much resource and heating CPU compared to Raspbery OS.
This is my first uploaded project, so execuse me if experience any deficiency on my commit...