Code Monkey home page Code Monkey logo

pi_fan_control's Introduction

Pi Fan Control

This is a fan control solution for the Raspberry Pi which uses a 5v CPU cooing fan, connected to the Raspberry Pi, through an NPN transistor, to a PWM pin. The script ramps up the fan speed gradually, proportional to the temperature of the Pi CPU. I felt the need to make this because my fan, on its max speed, makes a lot of noise and I found that in most cases, you don't even need the fan on, let alone run it on slow speeds. It is only when the Pi is overclocked and running under some heavy load, that you need to ramp up the fans. Having a variable speed fan control script like this is very handy in an overclocked setup (In my case, a Raspberry Pi 4B overclocked to 2GHz). Also, the fan makes significantly less noise when it is not running at full throttle.

Fan Wiring

In my setup I used pin 12 but you may use any pin and modify the pin number in the script accordingly. This is my wiring setup for the fan:

Pi Fan Wiring


The transistor is a 2N2222 NPN transistor and the resistor is a 600 Ohm resistor. The fan is a standard 5V cooling fan.

There are two python scripts present here, fan_control_script and fanctl. The fan_control_script script is responsible for controlling the fan and the fanctl script is used to toggle the fan on or off and to query the fan for information such as fan speed. These scripts have been tested on a fresh install of Raspberry Pi OS. Feel free to modify the scripts as per your convenience.

Installation

You need python3 and git installed on your system (Installed by default on the desktop version of Raspberry Pi OS).

git clone https://github.com/aniansh19019/pi_fan_control
cd pi_fan_control
sudo chmod +x install.sh
./install.sh

Usage

After running the install.sh script, the files fan_control_script and fanctl will be moved to your /usr/bin folder and a systemd service is created which makes sure that the fan control script runs on system boot. You can modify the thresholds in the fan_control_script file if you want.

Now, to view the status of the fan (fan speed, CPU temperature), use the following command:

fanctl status

or just

fanctl

To toggle the fan on or off:
fanctl toggle

Uninstall

To uninstall the scripts, follow the given instructions:

sudo systemctl stop fan_control.service
sudo systemctl disable fan_control.service
sudo rm /etc/systemd/system/fan_control.service
sudo rm /usr/bin/fan_control_script
sudo rm /usr/bin/fanctl

pi_fan_control's People

Contributors

aniansh avatar aniansh19019 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.