I have a project which will require using a Raspberry Pi in a low power environment, but it will also require a 3G connection. I have not done any tests, yet, but I am under the assumption (and correct me if I am wrong) that a 3G modem plugged into a Raspberry Pi and connected to a network will use power, and given the environment, any extra power usage is a non requirement. So, how, programmatically, can I turn on and off a 3G modem, or the USB connector on a Raspberry Pi?

  • 1
    AFAIK You can't turn off a USB port, so it would rely on the 3G dongle having a power saving mode - it probably uses less power when not connected... but it probably uses a reasonable amount of power to connect/disconnect. Oct 12, 2012 at 14:54
  • 1
    thing is, this will be a completely autonomous and remote unit... it should be turning on and off 3G as needed... there wont be anyone there to unplug or plug it in... hence the programmatically part...
    – TiernanO
    Oct 12, 2012 at 23:11
  • 3
    As Alex said, there is no mechanism to control power to the Pi's USB ports from software - they are directly connected to the supply rail with only a passive current limiter. So unless you can tell the peripheral itself to shut down/sleep, you'll need an external power switching device, which you control over USB itself or via a GPIO pin. Oct 13, 2012 at 15:36

4 Answers 4


Sadly there is no way to fully power off with software alone. You will need to add a switching circuit connected over the GPIO pins to trigger a "hardware disconnect" by cutting power to your hardware.


To switch with GPIO it's just a simple transistor circuit.

enter image description here

B is attached to your GPIO pin. Depending if it's HIGH or LOW the transistor is on or off. C and E you put the power line to the USB-Device (RL).

For more detailed information better look at this site: http://www.kpsec.freeuk.com/trancirc.htm#switching and specially at http://www.kpsec.freeuk.com/trancirc.htm#ic

  • Think you could go into more detail about how to do this?
    – Jivings
    Oct 25, 2012 at 7:46
  • Sure. I'll edit
    – Mose
    Oct 25, 2012 at 7:54
  • yea that is good- you can put that transistor in a short USB extension cable.You will need to cut it open and intercept the power lines talked here. Then you can plug 3G into the extension and control power. I like it +1
    – Piotr Kula
    Oct 25, 2012 at 11:12
  • That looks promising! Thanks! will have to have a chat with my Electrical Engineering friend to help with that, but fingers crossed! Thanks again!
    – TiernanO
    Oct 25, 2012 at 12:11
  • "Sadly there is no way to fully power off with software alone." One of the more recent answers seems to demonstrate this is not the case: raspberrypi.stackexchange.com/a/83404/5538
    – goldilocks
    Aug 3, 2021 at 13:44

I would not advise you to turn an USB device ON/OFF just by using a transistor base switch because proper power ON/OFF protocol and electrical interface should be used as defined by the USB specifications.

I would rather use a switchable USB hub that allows you to turn ON/OFF any of it's downstream ports through software by using a simple command.

Something like this USB switchable hub should work for what you want.

  • 1
    That looks Sooo cool! I have to try that... I'm thinking this could also be handy for smart charging of phones... Hmmm.... Thanks!
    – TiernanO
    Nov 7, 2014 at 23:25
  • 2
    Disclaimer: I now working at Yepkit. So you may consider me biased on this subject. Nov 11, 2014 at 18:24
  • 1
    As a device can be plugged by a user at anytime, USB specs state that this must be handled by drivers and devices. So I don't see the point of spending 29€ when you can build simple electronics for cents with the same result and also backed by specs.
    – Mose
    Feb 21, 2016 at 14:13

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. But keep in mind that this hardware only supports turning off or on all USB ports at once, not independently. However, USB and Wifi+Ethernet power rails can be controlled independently (except for 4B, which doesn't use USB interface for networking).

Use it like this:

List all devices that can be controlled:

sudo uhubctl

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 4 is very different from previous models as it has USB3 chip. You would use command like this to turn power off (all ports):

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.


Hi I agree with @electrfunch since I am working on a Project of controlling devices on the USB ports. Instead of on-board Electronic Circuit proposed by @Mose, I created my own Isolation Board using Relays and looks similar to the USB Switch Hub and this makes sense since even though initially ignored- Currents within the Raspberry Pi will start becoming a criterion on a longer run which might affect your Pi performance.

For what I mean, you could refer these manuals for Low Current measurements:

Reference 1

Reference 2

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.