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? Commented Mar 12, 2013 at 9:07
  • I want to switch off the fan the pi must run normally.
    – opc0de
    Commented Mar 12, 2013 at 9:13

5 Answers 5


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. Commented Mar 14, 2013 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
    Commented May 3, 2013 at 7:25
  • 14
    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
    Commented Jan 3, 2018 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. Commented Jan 8, 2020 at 3:57
  • Might add that all of the other answer are correct on a software level. Those commands allow to switch power off in a way that the raspberry see all the usb as powered off and it does no longer communicate with them. However, in a hardware level, 5V is still issued by the USB port, and if you want a power cycle on your device it does not work.
    – Spoutnik16
    Commented Mar 29, 2022 at 8:06

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.

  • 1
    Does your tool keep power off after reboot?
    – dstonek
    Commented Feb 12, 2020 at 22:43
  • 2
    @dstonek, obviously no. but you can invoke it at /etc/rc.local to disable power at boot
    – mvp
    Commented Feb 13, 2020 at 1:56
  • This is perfect. Combine these commands with crontab and you unlock a lot of possibilities. Thanks!
    – Matthew
    Commented Oct 19, 2021 at 15:09
  • 1
    This worked on my Raspberry Pi 4 but some other process (I'm assuming) in the OS turns it on again immediately.
    – ccnokes
    Commented May 2, 2022 at 20:30
  • 1
    @ccnokes, please read this uhubctl FAQ item, it covers how to solve your issue.
    – mvp
    Commented May 3, 2022 at 23:28

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

enter image description here

  • 10
    wow never thought of that !!
    – opc0de
    Commented Mar 13, 2013 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
    Commented Mar 13, 2013 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
    Commented Mar 14, 2013 at 12:30
  • 2
    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. Commented Aug 10, 2015 at 8:14
  • 2
    This did not answer the question.
    – Dr. McKay
    Commented Jun 16, 2018 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.

  • Nothing happens with rasp 4, it just keep powering Commented Feb 20, 2023 at 20:38

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

  • Nothing happens Commented Feb 20, 2023 at 20:35

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.