Electrical – Switching USB connections between two devices

usbusb device

I currently have plans to convert a keyboard to bluetooth using a bluefruit module, but I would also like to have a switch to make it wired if I ever want to plug it in.

The bluefruit module is being powered through a USB battery bank and the keyboard's USB connection is connected to the bluefruit's USB passthrough for power and the PS2 data pins. I want to be able to use a switch to cut the data connection (and maybe the power connection?) between the keyboard and the bluefruit and then directly bypass it to the USB connection leading up to the battery bank's charge port.

I'm fairly new to this kind of stuff, but my understanding is that I can't use a transistor because they're not bi-directional, and that there might be some other complications involved with electronically switching data lines due to the way USB devices initially report to the computer, but there are devices that do this kind of thing like the Plugable USB switch, so it has to be possible in one way or another.

Best Answer

A simple solution is to use relays. You would need some small signal relays with a nominal coil voltage lower than ~4,4V and a switching current lower than ~500mA (have a look at the USB Specifications). There are some nice changeover relays, which would work great for this application. You can wire the USB power connection to the relay coils, so it would switch as soon as you plug the cabel into your PC. Don't forget to add catching diodes!

You can use transistors as well! Here is a simple schematic how to wire a transistor as a switch:

schematic

simulate this circuit – Schematic created using CircuitLab

You will find many examples how to calculate this circuit in the internet, but you need Three-state logic! Here is an example:

image from https://de.wikipedia.org/wiki/Tri-State

Instead of Transistors you can also use some logical IC's. An AND-Gate for example switches if both inputs are true. So the first input can be used as enable and the second as data input from your keyboard. There are lots of different logical IC's with Three-State logic, which would work fine for this application.

Since you aren't the only one who want to handle a situation like this, there are many finished IC-Solutions. Just search around for an USB-Switch on a component distributor near you. Have a look at this for example: USB 3.1 SuperSpeed 10 Gbps Switch