3

I have little to no experience with any form of computer software coding/editing but I have managed to get EmulationStation working (sort of) on my Raspberry Pi 2. I have a bought a fan and plugged it into my Pi but the problem is that when I shutdown the Pi the fan will continue to spin unless I completely unplug my system. I don't want to have to plug and unplug a wire every time I use my Pi so I was wondering if there is a command that I could enter through the terminal interface somehow to make the fan turn off when I select shutdown from the EmulationStation menu. Agagin I want to emphasise that I have very little understanding of computer brains so a step by step answer would be easiest for me to understand. Thanks.

1
  • 1
    "I have little to no experience with any form of computer software coding/editing" -> So based on this was there actually an operating temperature issue? If the answer is "I don't know" probably the best idea, if you find the fan irritating, is to remove it. It does not serve any purpose that it hasn't already served (suckering a few consumers out of a few dollars).
    – goldilocks
    Apr 28, 2016 at 23:06

2 Answers 2

6

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.

6
  • Hello and welcome! What's R2 for?
    – Ghanima
    Apr 28, 2016 at 22:39
  • Hello! R2 is just to limit the current in case the fan's resistance is too low. As I am saying above "given the resistance of the fan is large enough to limit the current it draws; otherwise include one".
    – DimP
    Apr 28, 2016 at 22:42
  • The fan is unlikely to run on <50mA. Ditch the series resistor. The fan probably has a brushless motor but you should still include a flyback diode. There is no need for the 47kΩ resistor (but it does no harm).
    – Milliways
    Apr 29, 2016 at 0:54
  • The 100Ω resistor is just an indication, but you are right, I will change the value. I still believe a series resistor is needed (5Ω-10Ω), as otherwise the fan could draw too much current. You are right on the flyback diode, will add this. Why don't we need the 47kΩ? Does the Raspberry Pi have internal pull-downs? Because it is usually a good practice to use a pull-down at the base, even with BJTs. (ref: electronics.stackexchange.com/questions/56010/…)
    – DimP
    Apr 29, 2016 at 8:57
  • If it is a 5V fan it needs 5V to run. If you put a resistor in series it will get a lower voltage. With 100Ω it is unlikely to run. No it is not "good practice" all the 47kΩ does is reduce the drive. As an Electrical Engineer with 50 years experience I can assure you it is unnecessary. The supposed reason "helps to turn the BJT off fast(sic)" is spurious. In this case speed is irrelevant, but if you (for some reason) you want to speed up switching use an active pulldown. Effectively when the Pi output goes low the 4.7kΩ is effectively connected from base to Gnd.
    – Milliways
    Apr 30, 2016 at 2:28
3

You haven't said how you are powering the fan. "I have a bought a fan and plugged it into my Pi" is vague.

Given that it stays on I reckon it's safe to assume you have connected it to a 5V pin and a ground pin. These pins are not GPIO, they are not switchable, they are powered as long as the Pi is powered.

So the answer to your question is no, there is no command to switch the fan off.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.