Temperature controlled fan using GPIO on rpi 3

  • Hello,

    I am trying to create a background service which should start when libreelec starts and monitor the CPU temperature. If the temperature goes beyond certain limit switch the fan ON. I have almost got all the hardware ready and connected to the GPIO (pin 18).

    Below is the script I manage to create so far. Please let me know if this will work or not and specifically if this is fine or not. I am planning to install it as a service addon uisng zip file.

    Lately the temperature on my Rpi 3 (Libreelec 7.0.3) goes above 70 which was not the case before. I am running moderate overclock settings. Also, have been running transmission, couchpotato and sonarr along with Kodi. Also, during startup I get the yellow warning of temperature which I believe is displayed when CPU is above 80. Can anybody point me in correct direction how to find out which service or addon is causing the pi to overheat so much?

    I am newbie in linux, but can follow steps if provided. Have learned couple of tricks so far :)

    fan.py

    addon.xml


    The circuit diagram is as follows. The DC motor is actually a fan. Never connect motor to rpi like this.


    Thank you.

  • Years ago, I played around with a kickstarter project called "HotPi" which did exactly what you are hoping to achieve (albeit on the RPi1). Some of the documentation may still be around which will give you a few clues. However, I think you may run into problems if some of the python modules are not available in LE.

    Also, I found that the noise of the fan was annoying whilst watching a movie.

    If you're overclocking the RPi3 (and possible other performance "tweaks") your going to have to expect temperature problems.

    Ways around it are to remove the lid of a case if any, install a heatsink (don't use a heatsink if enclosed in a case - counter productive without a fan).

    What I ended up doing, was just using a small 5V fan connected to 3.3V and Gnd. It's slow enough to be quiet but effective enough to keep the temperature around 40 degrees with normal usage.

    A red thermometer is the sign of overheating (Actually when the RPi3 throttles back) a yellow zigzag is a sign of voltage issues.

    You won't be able to see what processes are using the system as the system is still starting up - having transmission, couchpotato and sonarr are not going to help unless they are delayed on startup.

  • Thanks. I do have heatsink installed. The plastic case do have good ventilation, but I feel its not enough. The fan I have is the same you are referring to, it came with the case and runs fine connected directly on the pwr & gnd pins. I am planning to add delay to all those services so that I can even out the load on startup. I wanted the script so that the fan does not run continuously as you said it is annoying while watching movie. I have seen that while watching anything temperature is below 55. Do you have any idea on what the error is in the scripts above. I cannot install it using zip file and no error is logged as well so I am kind of stumped.

  • I would try running the script from a terminal - python myscript.py and see what errors you get. Also I would install the LE add-on RPi-tools as that may have some of the modules needed.

    Also some of the data refers to xbmc, this may have change to kodi - you'll need to check.

  • I did the same project a while back when i built my raspi NAS setup. I got help on the raspberry pi forum to get it working. I never did get it quite right though, i could turn the fan on and off, but it wouldn't work on temp control. I powered my fan from a usb plug and used the transister as a switch to ground. I also put a .5 amp fuse between the pi and the transister to protect my pi. My coding skills are less than minimal, but the raspbery pi forum is a great resource.