# Controlling USB power with raspberry pi or Arduino

**URL:** <https://forum.core-electronics.com.au/t/controlling-usb-power-with-raspberry-pi-or-arduino/3242>\
**Category:** Support\
**Created:** [13 August 2018 01:14 UTC](https://forum.core-electronics.com.au/t/controlling-usb-power-with-raspberry-pi-or-arduino/3242 "2018-08-13T01:14:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![John11754](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/john11754/32/871_2.png) [@John11754](https://forum.core-electronics.com.au/u/John11754)\
**Post date:** [13 August 2018 01:14 UTC](https://forum.core-electronics.com.au/t/controlling-usb-power-with-raspberry-pi-or-arduino/3242/1 "2018-08-13T01:14:50Z")

</div>

I have a USB device I want to turn off and on via a Pi or NodeMCU device. I tried the trick “echo 0 \> /sys/devices/platform/soc/20980000.usb/buspower” on the PiZero, but it didn’t work.

Could someone suggest a component or software solution to be able to turn on/off a USB power source? I could build something for 5v and wire a USB cable, but I had hoped there was something already out there.

Thanks.

-John

---

<div class="post-metadata">

**Author:** ![Stephen](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/stephen/32/1599_2.png) [@Stephen](https://forum.core-electronics.com.au/u/Stephen)\
**Post date:** [15 August 2018 02:56 UTC](https://forum.core-electronics.com.au/t/controlling-usb-power-with-raspberry-pi-or-arduino/3242/2 "2018-08-15T02:56:30Z")

</div>

Hi John!

Here is a link where some methods to pull this off are available, but they are using a RPI 3B+:  
[https://lb.raspberrypi.org/forums/viewtopic.php?t=162539](https://lb.raspberrypi.org/forums/viewtopic.php?t=162539)

This one also has some less specific Linux methods to give a try:

> <https://askubuntu.com/questions/741760/is-it-possible-to-turn-off-a-specific-usb-port-so-it-doesnt-accept-any-device>

If those don’t work you could always trigger a relay to shut off USB power externally.

---

<div class="post-metadata">

**Author:** ![dave50358](https://avatars.discourse-cdn.com/v4/letter/d/e480ec/32.png) [@dave50358](https://forum.core-electronics.com.au/u/dave50358)\
**Post date:** [15 August 2018 20:14 UTC](https://forum.core-electronics.com.au/t/controlling-usb-power-with-raspberry-pi-or-arduino/3242/3 "2018-08-15T20:14:21Z")

</div>

John,  
I have to ask Why? Is the USB used just to provide power or something else? If it’s just power, hack the lead from a USB charger and put a relay in it.

Dave

---

<div class="post-metadata">

**Author:** ![John11754](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/john11754/32/871_2.png) [@John11754](https://forum.core-electronics.com.au/u/John11754)\
**Post date:** [16 August 2018 00:08 UTC](https://forum.core-electronics.com.au/t/controlling-usb-power-with-raspberry-pi-or-arduino/3242/4 "2018-08-16T00:08:23Z")

</div>

Thanks Stephen, I’ll have a look.

---

<div class="post-metadata">

**Author:** ![John11754](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/john11754/32/871_2.png) [@John11754](https://forum.core-electronics.com.au/u/John11754)\
**Post date:** [16 August 2018 00:09 UTC](https://forum.core-electronics.com.au/t/controlling-usb-power-with-raspberry-pi-or-arduino/3242/5 "2018-08-16T00:09:10Z")

</div>

Dave,

Yes, it is just for power. Would you be able to suggest a relay device for this method that would be controllable by the Pi?

Thanks. -John

---

<div class="post-metadata">

**Author:** ![dave50358](https://avatars.discourse-cdn.com/v4/letter/d/e480ec/32.png) [@dave50358](https://forum.core-electronics.com.au/u/dave50358)\
**Post date:** [16 August 2018 20:10 UTC](https://forum.core-electronics.com.au/t/controlling-usb-power-with-raspberry-pi-or-arduino/3242/6 "2018-08-16T20:10:00Z")

</div>

John,  
have a look at [https://core-electronics.com.au/raspberry-pi-relay-board-v1-0-seeed-studio.html](https://core-electronics.com.au/raspberry-pi-relay-board-v1-0-seeed-studio.html) .

This has 4 relays on a Pi compatible board, but have a look around for “Raspberry Pi relay board”.

Dave

---

<div class="post-metadata">

**Author:** ![John11754](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/john11754/32/871_2.png) [@John11754](https://forum.core-electronics.com.au/u/John11754)\
**Post date:** [16 August 2018 22:43 UTC](https://forum.core-electronics.com.au/t/controlling-usb-power-with-raspberry-pi-or-arduino/3242/7 "2018-08-16T22:43:48Z")

</div>

Dave,

Thanks. This would work, but I’d need to have a think about how to wire in USB ports. I don’t want to cut the USB cables for the devices I want to switch on/off.

-John

---

<div class="post-metadata">

**Author:** ![Stephen](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/stephen/32/1599_2.png) [@Stephen](https://forum.core-electronics.com.au/u/Stephen)\
**Post date:** [17 August 2018 01:16 UTC](https://forum.core-electronics.com.au/t/controlling-usb-power-with-raspberry-pi-or-arduino/3242/8 "2018-08-17T01:16:09Z")

</div>

Great suggestion Dave! Before this conversation I wasn’t aware that there was a way to remove power from a USB port via software.

John, I would take a USB hub and wire that up to the relays for power, then you could shut your devices off without compromising the original USB cords.

---

<div class="post-metadata">

**Author:** ![John11754](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/john11754/32/871_2.png) [@John11754](https://forum.core-electronics.com.au/u/John11754)\
**Post date:** [19 August 2018 11:24 UTC](https://forum.core-electronics.com.au/t/controlling-usb-power-with-raspberry-pi-or-arduino/3242/9 "2018-08-19T11:24:52Z")

</div>

Interesting… The bind/unbind work on the Pi3B+. Cool.

Unfortunately, it turns off ALL usb ports and ethernet.  
To shut off power on USB ports (this shuts power on ethernet as well):  
**echo ‘1-1’ |sudo tee /sys/bus/usb/drivers/usb/unbind**  
To turn power back on  
**echo ‘1-1’ |sudo tee /sys/bus/usb/drivers/usb/bind**

I have no idea what this ‘bind’ and ‘unbind’ are doing…

-John
