This is a small circuit. It is plugged in to the Orange Pi Zero like a shield. It uses two GPIO pins of the Pi to control the transistor and the LEDs.
Here is the first prototype on the breadboard, the digital out pin turns on both the transistor and the red LED. The green LED will be turned on when the fan is not running.
Here you can see how I planned to build the circuit.
Here is the complete circuit.
Here are photos of the circuit plugged in to the Pi. The fan is stuck to the back of the ethernet port with hot glue.
First, install WiringOP. Follow these instructions. You can delete the downloaded files after running "./build".
In your home folder, create a file named fan-control.sh and enter these lines into it with your preferred text editor. After you save the file, make it an executable file by typing "chmod +x fan-control.sh". You can find this code file in the attachments of this project. You don't need to enter the three lines under "else" that start with "#".
This bash script will check the soc temperature, if it is higher than 50 degrees(C), it will turn on the fan and the red led. It will also enter a line to the log file, recording when the fan turned on. We will make this script run every minute, so I commented out the lines(added # to the beginning) that also record a line to the log file when the temperature is lower than 50.
edit on 31.01.2019: I've been informed by the user JE that there is a mistake in the script. I tested the script at the time of writing and it worked. However, if you get an error, try changing if [ $temperature -gt 50 ] with if [ "$temperature -gt 50" ].
Here is the current log file, showing when the fan turned on at what temperatures. It says 46 because I changed the value in the script from 50 to 45. You can set it however you like.
Add the last two lines in the screenshot below to your /etc/crontab file. Change "erhan" with your username. The first added line runs the script every minute. The second added line clears our log file every week(sundays at 00:00).
Enjoy your cool Pi.