Tech-Dex / RPi-Fan-Controller

Automatically set fan's PWM based on CPU Temperature for a Raspberry Pi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RPi-Fan-Controller

Automatically set fan's PWM based on CPU Temperature for a Raspberry Pi. This script will work only if you have the fan connected to RPi via a GPIO pin.

Why I created this script? Why should you use it?

I bought a Raspberry Pi 4 with official case and official fan and the fan is very noisy.
The RPi is on my desk and this one is next to my bed and it was disturbing.
I am not exaggerating but the RPi official fan is noisier than my Desktop PC with 7 fans in it so I had to do something.

Setup

  1. Install requirements

sudo pip3 install -r requirements.txt 
      or
sudo pip3 install gpiozero
  1. Edit <YOUR_PATH> inside fancontroller.service then copy the file in /lib/systemd/system/

sudo cp fancontroller.service /lib/systemd/system/
  1. Enable Service

sudo systemctl daemon-reload
sudo systemctl enable fancontroller.service
sudo systemctl start fancontroller.service
  1. Check Service

sudo systemctl status fancontroller.service

How to edit the script?

TEMPS and PWM_OUTPUT: Edit them based on your temperature limit and what PWM you want to use when the CPU Temperature is above the limit you selected previous.
GPIO_PIN : Edit this one based on the GPIO Pin you are using for your fan. The script I think it can be extended with more fans, example below.
DEFAULT_PWM: Put the fan PWM value back to default value when you stop the script.

Extend script for more fans(I didn't test this one bcs I don't have more fans, so it might be broken):

fan1 = PWMOutputDevice(GPIO_PIN1)
fan2 = PWMOutputDevice(GPIO_PIN2)
fan3 = PWMOutputDevice(GPIO_PIN3)
fan1.value = 1.0
fan2.value = 0.8
fan3.value = 0.4

Stress test with stressberry

sudo apt install stress
sudo pip3 install stressberry
sudo /home/<<USER>>/.local/bin/stressberry-run -n "Custom PWM Test" -d 1800 -i 300 -c 4 test.out
sudo MPLBACKEND=Agg /home/<<USER>>/.local/bin/stressberry-plot test.out -f -d 300 -f -l 400 1600 -t 30 90 -o test.png --not-transparent

stressberry

About

Automatically set fan's PWM based on CPU Temperature for a Raspberry Pi

License:MIT License


Languages

Language:Python 100.0%