I have a simple device connected to the Raspberry Pi, a small USB fan. The problem is that the fan does not have a on/off switch so I must unplug the fan every time I want it to stop.

My question is: is there any way I can cut the power coming from the Pi's USB ports?

  • Do you mean outgoing power, you want to be able to switch off the fan but not the pi, or incoming power, in whic the fan's power supply is backpowering the pi, even though the pi's own power supply has been disconnected? Mar 12 '13 at 9:07
  • I want to switch off the fan the pi must run normally.
    – opc0de
    Mar 12 '13 at 9:13

No, the usb power is hardwired straight to the RPi power.

You can interrupt the power to the fan with a transistor or a relay, but you'll have to cut the red wire.

  • 2
    Good answer, gnibbler, and quite correct from what I read on the raspberrypi.org forums. I can add that I've tried to do this on other machines (ARM and x86) and it is rarely possible -- only some USB controllers allow software power control. stackoverflow.com/questions/4702216/… stackoverflow.com/questions/1163824/… So I'm not surprised this isn't possible with the minimal USB in the Pi. Mar 14 '13 at 14:06
  • Often you can toggle power in a usb hub's ports. Might try with fan on hub on pi, then switch power on/off on that hub port. May need external powered hub, depends on how thick your air is and how hard fan has to work.
    – lornix
    May 3 '13 at 7:25
  • 10
    This answer is wrong. It's possible to control USB power for Raspberry Pi models B, 2B, 3B - see my answer how exactly to do that.
    – mvp
    Jan 3 '18 at 4:59
  • @mvp, I can equally say that your answer is exactly wrong for all the raspberry PI that existed when the question was asked. I won't change this answer as it's still true for millions of the original raspberry PIs. It's easy for someone with a PI manufactured after 2014 to see your answer is here too. Jan 8 '20 at 3:57

You can use my tool uhubctl, it supports Raspberry Pi models B+, 2B, 3B, 3B+ and 4B - these models have hardware ability to turn USB power off and on.

Use it like this:

Turn off power to all USB ports (must use port 2):

sudo uhubctl -l 1-1 -p 2 -a 0

Turn on power to all USB ports (must use port 2):

sudo uhubctl -l 1-1 -p 2 -a 1

Turn off power to Wifi+Ethernet (must use port 1):

sudo uhubctl -l 1-1 -p 1 -a 0

Note that Raspberry Pi 4B is very different from previous models as it has USB3 chip. It doesn't support turning off power to Wifi+Ethernet, and for USB you will need to use something like that to turn off (this turns off all USB ports - RPi 4B hardware does not support individual port power control):

sudo uhubctl -l 2 -a 0

If your Raspberry Pi does not support USB power switching, you can connect external USB hub that does (see list of compatible models), and control power on that external hub using uhubctl.

  • Does your tool keep power off after reboot?
    – dstonek
    Feb 12 '20 at 22:43
  • 1
    @dstonek, obviously no. but you can invoke it at /etc/rc.local to disable power at boot
    – mvp
    Feb 13 '20 at 1:56

You can use one usb fan with "on/off" switch.

enter image description here

  • 8
    wow never thought of that !!
    – opc0de
    Mar 13 '13 at 8:52
  • I don't really understand why is your comment so rude ? You never said you did think about the switch! I tried to help you (help: Is not that what you asked for). But, I understand you frustration, see my edit. It seems that the question has already been asked and answered.
    – David
    Mar 13 '13 at 11:25
  • 2
    Dont worry about it David - Maybe it was not the answer for the OP - But somebody else might like it for another circumstance. Your answer is good. +1 - Not sure why you got downvoted- The OP said he does not have an on.off switch and you showed him where to buy one with an on/off :) -1 was not needed here and a bit rude. yes :P
    – Piotr Kula
    Mar 14 '13 at 12:30
  • 1
    David, indeed you shouldn't worry, but your answer just doesn't answer the question, which is how to cut the power coming from the pi's usb ports. So it's not a good answer. I am surprised you did get any up votes at all. Aug 10 '15 at 8:14
  • 1
    This did not answer the question.
    – Dr. McKay
    Jun 16 '18 at 19:28

This also works for me on the Raspberry Pi 3. It was copied from here.

   sudo apt-get update
   sudo apt-get install libusb-dev
   git clone https://github.com/codazoda/hub-ctrl.c
   cd hub-ctrl.c
   gcc -o hub-ctrl hub-ctrl.c -lusb

This will create an executable named hub-ctrl. You can then run it to do the following:

  • Turn off power to all USB ports

    sudo ./hub-ctrl -h 0 -P 2 -p 0
  • Turn on power to all USB ports

    sudo ./hub-ctrl -h 0 -P 2 -p 1 

Follow the link to also turn on/off the Ethernet port.


You can turn of all USB ports with their power:

sudo tee /sys/bus/usb/drivers/usb/unbind

Data transfer will not be possible too.

To turn USB ports bak you can use:

sudo tee /sys/bus/usb/drivers/usb/bind

I have stolen this solution by user faceofbo from Raspberry Pi forum

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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