TheTechMan23
Posts: 4
Joined: Tue Mar 05, 2013 5:43 pm

(Updated) Fan Box w/ Python Script to control temp!

Tue Mar 05, 2013 6:16 pm

Custom fan box with python script for temperature control
I built a box with fans attached to it to control the temp like a regular desktop would have. I wrote a python script that checks the temp of the CPU every 45 seconds and turns the fans on/off accordingly.

Image
Image
Image
Image
Image
Image
Image


Video w/ links in the description:
http://youtu.be/ANB1CZGX3zo

Python Script

Code: Select all

#!/usr/bin/env python3
import time
import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
GPIO.setwarnings(False)
def getCPUtemperature():
    res = os.popen('vcgencmd measure_temp').readline()
    return(res.replace("temp=","").replace("'C\n",""))
def fanON():
    GPIO.output(12, False)
    return()
def fanOFF():
    GPIO.output(12, True)
    return()
def getTEMP():
    CPU_temp = float(getCPUtemperature())
    if CPU_temp>40:
        fanON()
    else:
        fanOFF()
    return()
while 1:
    getTEMP()
    time.sleep(45)
Last edited by TheTechMan23 on Fri Mar 08, 2013 3:54 pm, edited 4 times in total.

TheTechMan23
Posts: 4
Joined: Tue Mar 05, 2013 5:43 pm

Re: Fan Box w/ Python Script to control temp!

Fri Mar 08, 2013 3:47 pm

Added more pics and posted the Python script. Anyone that has tried this or wants to, feedback would be much appreciated because Im currently drawing up plans for version 2.0 in a new box that's going to contain an Adruino built in as well.

jimmybobby
Posts: 29
Joined: Wed Feb 20, 2013 9:53 pm

Re: (Updated) Fan Box w/ Python Script to control temp!

Wed Apr 03, 2013 4:12 pm

What fans are you running, what voltages, what pins.

Are they effective, and is there a plan for the box?
I have an 80x80mm 12v fan, will it work?
It's fair to say I like obsolete/old technology. :)
A Level Comp Sci Student

Nicolaid
Posts: 1
Joined: Mon Apr 08, 2013 7:44 am

Re: (Updated) Fan Box w/ Python Script to control temp!

Mon Apr 08, 2013 7:46 am

I am also very interested in which pins you used for the project.

dan3008
Posts: 1172
Joined: Wed Aug 15, 2012 1:05 pm

Re: (Updated) Fan Box w/ Python Script to control temp!

Mon Apr 08, 2013 9:05 am

Well, the script works.

I modded it a bit, to light up an LED if the temp got too hot (I dont have a fan lol)

Nice box
dan3008 wrote:Pays your money, takes your choice

TheTechMan23
Posts: 4
Joined: Tue Mar 05, 2013 5:43 pm

Re: (Updated) Fan Box w/ Python Script to control temp!

Sun Apr 21, 2013 1:59 pm

jimmybobby wrote:What fans are you running, what voltages, what pins.

Are they effective, and is there a plan for the box?
I have an 80x80mm 12v fan, will it work?
I used the 3v for led's and the 5v for the fan.... I pulled the fan out of an old pc but I think you can get low voltage fans at radioshack. I used the 12 pin to control the fans by sending a signal from the 12 pin to the transistor to turn the ground on and off. I have the ground for an led and the fan going to the same transistor that the 12 controls. If you link to the video you can see how I wired the setup a lot better!

RaNDoM123SaLAd
Posts: 4
Joined: Mon Dec 16, 2013 9:05 pm

Re: (Updated) Fan Box w/ Python Script to control temp!

Mon Dec 30, 2013 3:16 am

Yes! Just what I was looking for! I can now modify the code to power my fan! Thanks!

headcloudmonkey
Posts: 4
Joined: Mon Mar 30, 2015 4:04 am

Re: (Updated) Fan Box w/ Python Script to control temp!

Sat Aug 15, 2015 11:42 pm

Lifting this to help with the code for my hottub controller :)

Thanks
Dan

Return to “Other projects”