My Account

Wish List (0)

PiBorg is still open and we are still shipping orders.
We expect orders may be delayed by a day or two due to COVID-19.


Written by in Build, PicoBorg - Build on .

Nobody likes it when computers overheat, especially when you venture into the realms of over-clocking!

So we thought it would be great if you could setup a fan for a Raspberry Pi to work the same way they do in a laptop, turning on when it gets too hot and turning off again when it is sufficiently cooled. We have a drive control board, PicoBorg, which should be plenty capable of driving a PC style fan, and a small fan suitable for the task. The result was, a Python script which reads the current processor temperature and controls PicoBorg appropriately:

Here's the code, you can download the ChilledPi script file as text here Save the text file on your pi as Make the script executable using chmod +x and run using sudo ./

#!/usr/bin/env python
# coding: latin-1

# Import libary functions we need
import RPi.GPIO as GPIO
import time

# Set which GPIO pins the drive outputs are connected to
DRIVE_1 = 4
DRIVE_2 = 18
DRIVE_3 = 8
DRIVE_4 = 7

# Set all of the drive pins as output pins

# Map the on/off state to nicer names for display
dName = {}
dName[True] = 'ON '
dName[False] = 'OFF'

# Function to set all drives off
def MotorOff():
    GPIO.output(DRIVE_1, GPIO.LOW)
    GPIO.output(DRIVE_2, GPIO.LOW)
    GPIO.output(DRIVE_3, GPIO.LOW)
    GPIO.output(DRIVE_4, GPIO.LOW)

# Setup for processor monitor
lProcessorFans = [DRIVE_1]                              # List of fans to turn on when processor is too hot
pathSensor = '/sys/class/thermal/thermal_zone0/temp'    # File path used to read the temperature
readingPrintMultiplier = 0.001                          # Value to multiply the reading by for user display
tempHigh = 37000                                        # Reading at which the fan(s) will be started (same units as file)
tempLow = 33000                                         # Reading at which the fan(s) will be stopped (same units as file)
interval = 1                                            # Time between readings in seconds

    # Start by turning all drives off
    raw_input('You can now turn on the power, press ENTER to continue')
    fansOn = False
    while True:
        # Read the temperature in from the file system
        fSensor = open(pathSensor, 'r')
        reading = float(
        # Adjust fan(s) depending on current status
        if fansOn:
            if reading <= tempLow:
                # We have cooled down enough, turn the fans off
                for fan in lProcessorFans:
                    GPIO.output(fan, GPIO.LOW)
                fansOn = False
            if reading >= tempHigh:
                # We have warmed up enough, turn the fans on
                for fan in lProcessorFans:
                    GPIO.output(fan, GPIO.HIGH)
                fansOn = True
        # Print the latest reading and the current state of all 4 drives
        print '%02.3f %s %s %s %s' % (reading * readingPrintMultiplier, dName[GPIO.input(DRIVE_1)], dName[GPIO.input(DRIVE_2)], dName[GPIO.input(DRIVE_3)], dName[GPIO.input(DRIVE_4)])
        # Wait a while
except KeyboardInterrupt:
    # CTRL+C exit, turn off the drives and release the GPIO pins
    print 'Terminated'
    raw_input('Turn the power off now, press ENTER to continue')
Last update: Nov 05, 2017

Related Article

Related Products


Leave a Comment

Leave a Reply

The product is currently Out-of-Stock. Enter your email address below and we will notify you as soon as the product is available.