Code Monkey home page Code Monkey logo

raspberry-pi-fan-controller's Introduction

Raspberry-Pi-Fan-Controller

Raspberry-Pi-Fan-Controller is a temperature based fan controller that turns the fan on when a certain temperature is reached and turns the fan off when the threshold isn't met anymore.

Components

  • Raspberry Pi

  • Fan

  • 2N2222 Transistor

  • 10K ohm Resistor

Schema

RPI4 GPIO Pinout

2N2222 Transistor

Prerequisites

  • Python 3.8+

  • Bash 4.2+

Installation

1. Installation script

The installation script will create an executable script, a config file and if selected it will autostart the script at boot.

sh -c "$(wget -qO- https://raw.githubusercontent.com/0xharu/raspberry-pi-fan-controller/master/install.sh)"

To uninstall the program and all of its files use:

sh -c "$(wget -qO- https://raw.githubusercontent.com/0xharu/raspberry-pi-fan-controller/master/uninstall.sh)"

Manual inspection

It's always a good idea to inspect the installation script, you can do that by downloading the installation script first, looking through it and then running it.

wget -q https://raw.githubusercontent.com/0xharu/raspberry-pi-fan-controller/master/install.sh

2. Clone the repository

git clone https://github.com/0xharu/raspberry-pi-fan-controller.git

3. DownGit Links

Usage

If you cloned the repository or used the DownGit links use: python3 fan.py or bash fan.sh.

If you used the installation script and installed only one of the scripts use: fan

If you installed both scripts use: fan-py or fan-sh.

In my experience even if the benchmarks are pretty much the same the python script seems to perform better and triggers the fan less frequently compared to the bash script.

Autostart

To autostart the script either use the installation script or edit your crontab list.

How to edit your crontab list:

  1. chmod +x <script>

  2. crontab -e

  3. Add this line at the end of the file: @reboot /path/to/the/script >/dev/null 2>&1 || touch "$HOME/Desktop/AUTOSTART_FAILED"

In case the script fails to autostart a file will be created on the desktop to alert the user.

If you installed the bash script add sudo before the path.

Run the script as a deamon

nohup fan >/dev/null 2>&1 &

I recommend using an alias like: alias fan-d="nohup fan >/dev/null 2>&1 &"

To kill the process use: kill -9 <PID>

The PID is returned by fan-d.

Benchmark

I benchmarked both scripts, I measured CPU and RAM usage every second for 5 minutes and plotted the collected data with Matplotlib.

Python

CPU AVG: 1.1428%

RAM AVG: 12.8993%

Bash

CPU AVG: 1.1505%

RAM AVG: 12.7267%

Useful Resources

RPI

github.com/mishka/RaspberryPiFanController

raspberrypi-aa.github.io/session2/bash.html

medium.com/coinmonks/controlling-raspberry-pi-gpio-pins-from-bash-scripts-traffic-lights

Cron

cyberciti.biz/faq/linux-execute-cron-job-after-system-reboot

Misc

cyberciti.biz/faq/how-to-redirect-output-and-errors-to-devnull

linux.com/training-tutorials/how-kill-process-command-line

License

This project uses the following license: MIT.

raspberry-pi-fan-controller's People

Contributors

0xharu 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.