USB 3.0 Cable Power Switch

by johnwargo in Circuits > USB

521 Views, 3 Favorites, 0 Comments

USB 3.0 Cable Power Switch

finished-enclosure.jpg

In my spare time, I do a lot of software development on Microcontrollers and platforms (Arduino, Raspberry Pi, ESP32, Particle, etc.). When you do this type of development, you spend a lot of time with some device (a smartphone or other hardware device) attached to your development system via a USB cable.

During testing of apps (or sketches) for these devices, I often find myself unplugging the USB cable from my computer to deal with a specific issues in my code. For example, sometimes my code for an ESP32 device Panics the device and it reboots repeatedly. Rather than let the device continually reboot while I figure out what went wrong, I disconnect the USB cable while I stare at my code for a while until I find the solution.

I also noticed that for some Microcontroller projects, like the M5Stack M5StickC-Plus I can't leave the device plugged in very long if I want to deploy a new version of the code to the device; for some reason it regularly disconnects from the computer. I often must unplug the device and plug it back in again during the compilation step so it's in the right state when the Arduino Compiler's ready to deploy code to the device.

Anyway, those situations started me looking for a USB switch I could use to connect and disconnect power to/from a device without having to unplug cables. I found a few, but they were all inline versions with the switch wired into the middle of a cable. Based on the position of my development computer, any cable-based device like that would pull a small microcontroller project off my desk and put the switch below the level of the desk.

To address my need, I built my own desktop USB switch, a switch that's large and heavy enough to stay on my desk (putting the switch close at hand) and enabling me to disconnect then reconnect with ease as I troubleshoot the code running on the device.

Supplies

The project uses the following components and supplies:

  1. 2 Type A USB 3.0 panel mount connectors; I used Type A 3.0 Female USB To PCB Connector USB3.0 Connector Power Supply Data Jack Socket With Screws Hole.
  2. 1 Double Pull Single Throw (DPST) switch (optionally one with an LED; I used 5/10pcs KCD1-104 Power Rocker Switch 4 Pin LED Light Red Black 12V 220V On Off DPST Latching Plastic Panel Push Button Switch). The switch LED must support a 5V input voltage since that's all you're going to get from a USB-A cable.
  3. USB A to USB A cable; this is the input cable, the cable from your PC to the switch. I used Cable Matters Short USB 3.0 Cable - 3ft, USBA to USBA Cable, Male to Male USB Cord, Black.
  4. 22 ga stranded wire in a variety of colors (at a minimum Red, Black, and two other colors)
  5. Soldering iron and solder
  6. Some sort of enclosure to install the hardware into

Note: I used a DPST switch for the project because I wanted one with a LED to indicate when the switch is on. You can use a Single Pull Single Throw (SPST) switch if you want, I provide instructions below how to handle this situation.

Panel Mount

For the panel mount USB ports I selected, I used 4 M3 x 8mm nylon bolts with 4 M3 nuts to mount them in the enclosure. For this you need:

  1. 3D Printer and filament

Here are the files necessary to print a front panel for the switch.

Prepare Enclosure or Panel

components.jpg

The USB Power Switch consists of essentially three components, two USB ports and a switch. As we start construction, we only need the two USB ports and something to mount them on. In my case, I 3D printed a front panel for my USB Power Switch and that's where I mounted all of the components before assembling them in a wooden enclosure.

For your project, select the enclosure where you want to install the USB ports and switch, then cut the appropriate openings for them.

Mount USB Ports

usb-ports-mounted.jpg
usb-ports-mounted-back.jpg

Using bolts, glue, or some other method, mount the USB ports to the enclosure. Make sure you orient the USB ports the same way so you'll never be confused by which cable goes in which way. I used nylon bolts and nuts to secure mine to the panel.

Note: Do not install the switch yet, I found that it was easier to solder the wires between the two USB ports without the switch in the way. We'll add the switch later.

Connect Voltage and Ground Wires

Drawing0.png
power and ground connected.jpg

Notice how I labeled the USB ports as input and output in the figure; this becomes important if you're using a switch with a LED. I'll explain this later.

The USB 3.0 ports have two ground connectors, but we only need one on each side for the power switch

Cut three black wires and two red wires to the appropriate length required to connect between the two USB ports; I used 3.5 inches for mine.

Solder one of the black wires between the Input USB Port's GND connector and the same GND connector on the Output USB Port.

Solder one of the black wires to the open GND connector on the Input USB port. Do not connect the other end of this wire to anything at this time.

Solder one of the red wires to the VBUS connector on the Input USB port. Do not connect the other end of this wire to anything at this time.

Solder one of the black wires to the open GND connector on the Output USB port. Do not connect the other end of this wire to anything at this time.

Solder one of the red wires to the VBUS connector on the Output USB port. Do not connect the other end of this wire to anything at this time.

When you're done, you'll have one wire connecting the two USB ports and two sets of red and black wires, one set connected to each USB Port connected to nothing. We'll connect the open red and black wires to the switch later.

Solder Remaining USB Connections

usb-port.jpg
panel-back.jpg

The USB 3.0 Port has 9 solderable connections and we've already soldered wires to three of them. The remaining connections are all paired, meaning there are two wires/connections for each. The pairs are:

  1. Transmit: labeled as TX+ and TX-
  2. Receive: labeled as RX+ and RX-
  3. Data: labeled as D+ and D-

For this step, cut three sets of wires in two colors (not red or black, we already used those colors and those colors mean something special in electronic circuits). Use the same length wire as you used earlier.

Solder wires between each of the matching solderable connections on the two USB Ports. This means:

  1. TX+ to TX+
  2. TX- to TX-
  3. RX+ to RX+
  4. RX- to RX-
  5. D+ to D+
  6. D- to D-

For my implementation, I used white and blue wires, so I connect white wires between the `+` connections and blue wires between the `-` connections. Being consistent with the colors here allows you to quickly identify breaks in the pattern.

DPDT Switch Connection

Drawing1.png
switch closeup.jpg
panel-back.jpg

If you're using a DPST switch for this project, use the instructions here. If using a SPST switch, jump to the next step.

As I said at the beginning of this Instructable, I chose a DPST switch with an LED in it so I could easily tell when the switch was powered on. You can also use a DPST switch without an LED in it, but its really not necessary without the LED.

Mount the switch in the enclosure, making sure to orient the switch in a way that makes the most sense for you. I positioned mine so down turns the switch off and up turns it on.

Start by figuring out which set of switch posts power the LED. If you look at the close-up of the switch I used, you'll see two wires snaking out and wrapping around the switch posts at the top of the switch. Those are the connections that power the LED.

To make this work correctly, you must connect the power (red) and ground (black) wires from the Input USB port to the opposite wires from the witch posts with the LED connected to them. You must also figure out the polarity of the LED connections, one post connects to ground and the other connects to the input voltage (the red wire). If you have documentation for your switches (I didn't), then you can just figure this out from the docs. If not, you can figure this out pretty easily with a little trial and error.

To validate LED connection polarity, switch the switch to the On position then take a 5V power source with two wires, one for voltage and the other ground, and connect them to the lower switch posts (not the ones with the LED wires connected to it). if the LED turns on, you've got it, you've nailed down the LED connection polarity. If the LED does not illuminate, then switch the polarity of the connections, basically switch the wires to the opposite sides of the switch.

Next, with the LED illuminated, turn off the switch. If the LED turns off, then you're all set. If it stays on, that means that you're working with the output side of the switch, not the input.

When you have this all sorted out, solder the red and black wires from the Input USB port to the correct posts on the non-LED side of the switch. Then solder the red and black wires from the Output USB port to the matching connections on the other side (the output side) of the switch. You must have Red/Red on one side of the switch's connections and black/black on the other.

You can see the completed connections on the image for this step.

SPST Switch Connection

Drawing2.png

If you decided to use a SPST switch in your project, complete the following instructions.

Solder the unconnected black wire from the Input USB port to the black wire on the Output USB port. This connects both ground connections to each other on both sides.

Next, solder the voltage (red) wire from the Input USB port to one of the switch connections (it doesn't matter which one) and connect the voltage (red) wire from the Output USB port to the other switch connection.

That's it!

Testing

testing.jpg

Connect a USB-A to USB-A cable between your computer system and the Input port on the switch. Next, connect a USB cable between the Output port on the switch and an external device.

When you turn the switch on, the device should power up. With the device powered on via the switch, you can deploy code to the device and interact with it from the computer system like you would with a normal USB cable.

Enclosure Assembly

assembly-1.jpg
assembly-2.jpg
assembly-3.jpg
assembly-4.jpg

To assemble my enclosure, I used a 5 by 1/2 inch piece of Maple. I cut the pieces to length then used a 45 degree chamfer bit to put a 45 degree chamfer along the enclosure joints (the first image above). When taped together, the pieces form the almost perfect enclosure shown in the second figure. When I glued it all together, I fixed the joints so they were flush and sanded out any imperfections.

Next, I used a couple of passes on my table saw to cut the grove for the front panel (third image). With that in place, I tightened up the tape holding the pieces together then glued them all together. The masking tape I used was all I needed to hold it all together securely as the glue dried.

Once the glue was dry, I sanded out all of the imperfections and put a few coats of clear finish on it. All done!