Kenneth Yang
Published © GPL3+

Smart Raspberry Pi CPU fan

A smarter way to keep you Pi cool.

BeginnerFull instructions provided6 minutes18,085
Smart Raspberry Pi CPU fan

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Brushless Fan
5v or 12v
×1
12v power supply (generic)
only if using 12v fan
×1

Story

Read more

Schematics

12v fan wiring

12v fan schematic

5v fan wiring

5v fan schematic

Code

Fan Control

Python
Python code for Raspberry Pi to control the Fan
import RPi.GPIO as IO
from gpiozero import CPUTemperature
import time

minspin = 10


IO.setwarnings(False)
IO.setmode(IO.BCM)
IO.setup(14,IO.OUT)
fan = IO.PWM(14, 100)

cpu = CPUTemperature()

fan.start(0)

oldtemp = cpu.temperature

while True:
    temp = cpu.temperature
    if abs(temp - oldtemp) < 1.5:
        time.sleep(1)
        print(str(temp)+"  skipped")
        continue
    oldtemp = temp
    if temp > 50:
        speed = ((temp - 45)*4)+minspin
        if speed > 100:
            speed = 100
        fan.ChangeDutyCycle(speed)
        print(str(temp)+"  "+str(speed)+"  fan on")
    else:
        fan.ChangeDutyCycle(0)
        print(str(temp)+"  fan off")
    time.sleep(1)
fan.stop()
IO.cleanup()
print("done")

Credits

Kenneth Yang

Kenneth Yang

8 projects • 100 followers
Maker, developer, 3D content creator

Comments