I'm in the progress of making a mod to my RPi case with fan.
Fan specs: 5v, 0,20mA
Manufacturer instructions were to connect red cable to 5v and the black cable to ground but since it's not recommended and causes too much fan noise I'm going to use a transistor and some python programming to control fan speed.
The transistor I'm using is BC337-40. I tested and it works. I send PWM signals to the GPIO pin, that is connected to the transistor, and fan speed changes accordingly. Here's the code I wrote to test:
Code: Select all
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(2,GPIO.OUT) p=GPIO.PWM(2,50) p.start(50) time.sleep(10) p=GPIO.PWM(2,100) p.start(100) time.sleep(10) p.stop() GPIO.cleanup()
Basically I'd like to tell RPi to spin the fan faster if the CPU gets hotter. For instance;
CPU temp(C) - Fan Speed(%)
30 - Fan turned off
40 - Fan 20%
50 - Fan 30%
55 - Fan 40%
60 - Fan 50%
65 - Fan 60%
70 - Fan 80%
75 - Fan 100%
I'm very new to Python and don't know how to create something like "Switch case statement" in Arduino C++. I also want this code to start automatically and run all the time.