Giter Club home page Giter Club logo

raspberry-pi-fan-script's Introduction

Raspberry Pi Fan Script

Simple Bash script to control the fan speed using the Rapsberry Pi GPIO and a transistor.

Requirements

  • Raspberry Pi
  • PC Fan (if possible, that it doesn't exceed 0.20A)
  • Soldering iron and some cables
  • NPN transistor (I used the 2N3904, but you can use any general purpose amplifier)

Electrical Circuit

The circuit is pretty simple. First you have to be careful identifying the three legs of the transistor, the middle one is the longest (Base) and from it, we can identify the other two (Emitter and Collector).

Once we have located them we can start soldering:

  1. Connect the positive pole of the fan to PIN4 of the GPIO
  2. Solder the Collector with the negative pole of the fan
  3. Connect the Base with the GPIO18(PIN12), it's important to use this pin because it's the only one compatible with PWM
  4. Finally, we join the Emitter with any Ground Pin of the GPIO (In my case PIN20)

Representation of the electrical scheme

Using the Script

First of all we'll need to access our system via SSH or open a terminal to install the GPIO access library for the Raspberry Pi:

sudo apt install wiringpi

Then we create a text document on the home directory and copy the content of fan.sh:

cd ~
nano fan.sh

Paste the script and save it with CTRL+X. When we exit the editor, we'll give the script execution permissions with:

sudo chmod +x fan.sh

Now the script is ready to be used. But we'll need run it manually every time the computer is started. To solve this we'll use a Linux daemon called Cron:

crontab -e

Paste the next line at the end of the file where there is no #:

@reboot /bin/bash /home/pi/fan.sh > /dev/null 2>&1

Save it with CTRL+X and exit.

Now the script is scheduled. To execute it we need to restart and it'll start running in the background.

sudo reboot

raspberry-pi-fan-script's People

Contributors

hamzab70 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.