Skip to main content
Updated image with flyback diode and R2 reduced to 10Ω from 100Ω
Source Link
DimP
  • 233
  • 1
  • 7

Depending on the fan, it could also be potentially dangerous for the Raspberry Pi the way you have it connected. If you insist on powering it from the Raspberry Pi, the proper way to do it - given the resistance of the fan is large enough to limit the current it draws; otherwise include one - would be by using a transistor, as seen in the schematic I created below (fan is represented by the coil):

Raspberry Pi - Fan connection SchematicRaspberry Pi - Fan connection Schematic

After the Raspberry Pi has booted up, you should run something like this in the terminal:

echo 12 > /sys/class/gpio/export 
echo out > /sys/class/gpio/gpio12/direction
echo 1 > /sys/class/gpio/gpio12/value

And once you want to turn the fan off, just before shutdown:

echo 0 > /sys/class/gpio/gpio12/value

That is one way to do it, there are of course numerous others to toggle the GPIO pins, a quick googling can give you alternatives.

Depending on the fan, it could also be potentially dangerous for the Raspberry Pi the way you have it connected. If you insist on powering it from the Raspberry Pi, the proper way to do it - given the resistance of the fan is large enough to limit the current it draws; otherwise include one - would be by using a transistor, as seen in the schematic I created below (fan is represented by the coil):

Raspberry Pi - Fan connection Schematic

After the Raspberry Pi has booted up, you should run something like this in the terminal:

echo 12 > /sys/class/gpio/export 
echo out > /sys/class/gpio/gpio12/direction
echo 1 > /sys/class/gpio/gpio12/value

And once you want to turn the fan off, just before shutdown:

echo 0 > /sys/class/gpio/gpio12/value

That is one way to do it, there are of course numerous others to toggle the GPIO pins, a quick googling can give you alternatives.

Depending on the fan, it could also be potentially dangerous for the Raspberry Pi the way you have it connected. If you insist on powering it from the Raspberry Pi, the proper way to do it - given the resistance of the fan is large enough to limit the current it draws; otherwise include one - would be by using a transistor, as seen in the schematic I created below (fan is represented by the coil):

Raspberry Pi - Fan connection Schematic

After the Raspberry Pi has booted up, you should run something like this in the terminal:

echo 12 > /sys/class/gpio/export 
echo out > /sys/class/gpio/gpio12/direction
echo 1 > /sys/class/gpio/gpio12/value

And once you want to turn the fan off, just before shutdown:

echo 0 > /sys/class/gpio/gpio12/value

That is one way to do it, there are of course numerous others to toggle the GPIO pins, a quick googling can give you alternatives.

Source Link
DimP
  • 233
  • 1
  • 7

Depending on the fan, it could also be potentially dangerous for the Raspberry Pi the way you have it connected. If you insist on powering it from the Raspberry Pi, the proper way to do it - given the resistance of the fan is large enough to limit the current it draws; otherwise include one - would be by using a transistor, as seen in the schematic I created below (fan is represented by the coil):

Raspberry Pi - Fan connection Schematic

After the Raspberry Pi has booted up, you should run something like this in the terminal:

echo 12 > /sys/class/gpio/export 
echo out > /sys/class/gpio/gpio12/direction
echo 1 > /sys/class/gpio/gpio12/value

And once you want to turn the fan off, just before shutdown:

echo 0 > /sys/class/gpio/gpio12/value

That is one way to do it, there are of course numerous others to toggle the GPIO pins, a quick googling can give you alternatives.