Commande ventilateur 5v avec raspberey

2 posts
by ikram » Thu Jun 08, 2017 7:37 am
J'ai une ventilateur 5v que je veux la branché á une pin pour la commander par la suite avec un bouton (dans une autre pin)je pens que le probleme c'est que la sortie du pin est 3.3v donc il y a t-il des propositions pour convertir 3.3v a 5v ou bien avez vous d'autre solution?
Posts: 84
Joined: Fri May 20, 2016 10:37 am
by Ernst » Thu Jun 08, 2017 10:01 am
As nobody has replied until now I will give you an answer in english because my french is worse then a google translation.

I am running a 5V fan (30mm x 30mm, 200mA) to provide cooling for the cpu on a Raspberry Pi 3B.
The fan is connected to pin 2 (5V) and a the D[rain](*3) of a 2N7000 MOSFET, the S[ource](*1) is connected to pin 6 (GND), and G[ain](*2) is connected to pin 12 (GPIO .1)
For more information on 2N7000 see
To control the fan you can use a very simple shell script using gpio (see
Code: Select all
gpio -g mode 18 output  # set output mode
gpio -g write 18 1           # fan on
gpio -g write 18 0           # fan off

Because the fan is very loud I did some experimenting and I now use a different way to control the fan:
Code: Select all
gpio -g mode 18 pwm   # set to pulse width modulation
gpio -g pwm 18 0          #  fan off
gpio -g pwm 18 840      # fan on very low speed
gpio -g pwm 18 ....        # a value calculated using 840 + (CPU temperature - 62) * 20
gpio -g pwm 18 1000    # fan on high speed

This is the complete script that runs in the background:
Code: Select all
GPIO='gpio -g'
sleep 30
# power fan on for 60 seconds to show that the script has started
$GPIO mode $PORT output
$GPIO write $PORT 1
sleep 60
$GPIO write $PORT 0
$GPIO mode $PORT pwm
$GPIO pwm $PORT 0
while true; do
  if [ $CPU -lt $LIMIT0 ]
    $GPIO pwm $PORT $PWM
    sleep $SLEEP1
    $GPIO pwm $PORT $PWM
    sleep $SLEEP2

Please note that this fan is used on an overclocked Pi3 that is used to run processor intensive jobs, under normal conditions you do not need a fan, sometimes a small heatsink will be sufficient.
My first computer was an ICT1500
Posts: 360
Joined: Sat Feb 04, 2017 9:39 am
Location: Germany