|
| 1 | +# raspberrypi-fan-controller |
| 2 | + |
| 3 | +This program serves to turn your 5v-fan on/off when the pi reaches a certain temperature. This is set to 60°c by default and will turn off when cooled to 45°c. The script utilizes a controlled infinte loop to consisitantly monitor the temperature every 10 seconds. It therefore should be setup so as to run when the pi is first turned on. |
| 4 | + |
| 5 | +The script utilizes < vcgencmd measure_temp > to find the current temperature of the pi. |
| 6 | + |
| 7 | +## Setup |
| 8 | + |
| 9 | +There are numerous methods you can use, this is just the way i've applied it. You can use an S8050 transistor to communicate with the pi & control the fan. The below schematic shows the basic layout, controls are applied via GPIO14. |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +For software setup follow the below statements |
| 15 | + |
| 16 | + git clone https://github.com/AliCW/raspberrypi-fan-controller.git |
| 17 | + |
| 18 | +Import the following dependencies - you will need to run this in sudo mode for the below rc.local auto-start function to work, otherwise the package will not be available for the root user. But you can always install without the sudo command if not using rc.local for auto-starting the script. |
| 19 | + |
| 20 | + sudo pip3 install schedule |
| 21 | + |
| 22 | + |
| 23 | +## Auto-Start via rc.local |
| 24 | + |
| 25 | +You will probably want to implement some auto-starting features for the fan script so you dont have to run it everytime time you start your pi. |
| 26 | + |
| 27 | +Navigate to the folder the fan-script has been cloned to and type the below |
| 28 | + |
| 29 | + pwd |
| 30 | + |
| 31 | +Copy the path given by the command to the clipboard. Now type the below command to open rc.local in nano editor. |
| 32 | + |
| 33 | + sudo nano /etc/rc.local |
| 34 | + |
| 35 | +Navigate down to the bottom of the file, one line above "exit 0" and type the below |
| 36 | + |
| 37 | + sudo python3 /<paste-path-to-script>/fan_script.py & |
| 38 | + |
| 39 | +Then hold control/command 'X' to exit and 'Y' to save the changes. The '&' is very important as the script uses an infinite loop to detect temperature, if excluded, the pi will not be able to run "exit 0" within rc.local. |
| 40 | + |
| 41 | +## Adjusting settings |
| 42 | + |
| 43 | + |
| 44 | +Alter the GPIO pin if GPIO14 is already in use. |
| 45 | + |
| 46 | + fanPin = 16 |
| 47 | + |
| 48 | +You can change the temperature which engages the fan by changing the if statements, the below example changes the script so the fan engages at 70°c. |
| 49 | + |
| 50 | + |
| 51 | + if temperature >= 70.0: |
| 52 | + GPIO.output(14,True) #turns the fan on |
| 53 | + if temperature < 45.0: |
| 54 | + GPIO.output(14,False) #turns the fan off |
0 commit comments