DIY USB sharing hub

USB sharing hub

Local shops wanted close to $100 for a mechanical USB switch, to share a USB keyboard and mouse between two computers. I accomplished the same thing with a cheap compact USB hub, an old keyboard and a 3 pole switch for less than $10.

The keyboard is wired to one of the USB hubs ports, the 3PDT switches the hubs two data lines plus the 5v+ rail. In an ideal world, the ground and shield should be switched too, but I only had a 3 pole switch and limited room.

DIY usb hub sharing switch diagram

I decided to put the hub inside the keyboard to reduce clutter, fitting everything in was the hardest part of the project, and not something I’d do again.

It works beautifully but there is a 10 second lag when switching to a Vista machine while it searches for the drivers for the mouse and keyboard, but it’s still easier than swapping the keyboard plug between machines.

8 thoughts on “DIY USB sharing hub

  1. thanks, you’ve been a big help, i placed all my components in a plastic electrics box from radioshack

  2. Pingback: A “Soft” KVM « Armen138

  3. I have a wireless keyboard that uses a dongle to connect to the keyboard. If i just have a female usb port slotted into where the hub is, i could achieve the same result?

  4. for example, if i have a Wireless mouse (the ones that have that dongle that plug into the pc…) Could i instead f having that hub there, have a female port(like the ones in your pc) and wire it up the same way you did?

  5. @Vignesh

    To answer Your question shortly: YES. It’s just a mechanical switch, physically routing wires from one PC to another (the equivalent of unplugging the device at PC A and plugging it in at PC B).

    Instead of switching the keyboard/mouse connector, You will be switching which PC the DONGLE is connected to. In essence, You just need two USB cables, one USB port, and a switch like the one above (if You want to get fancy, You can use a SPDT switch and do the connections using discrete transistors or relays).

    I guess it could easily be put in a with two USB cables and one USB port (and the switch), and it would work for both the wireless version (plug the dongle into it) as well as the wired version (plug the keyboard into it).

    WORD OF WARNING: the USB plug has a VERY specific layout – the power pins (outermost) are longer than the data pins (innermost) for a very good reason. It’s to allow the power inside the USB device to stabilize before D+ and D- are connected. Some USB devices don’t play nice (and some PCs, too), so switching all four lines immediately can cause problems (as in: burned devices). But there’s an easy way to solve this: put a 5V highly regulated power supply into the project. The GND connector should switch between PCs, as should D+ and D-, but the +5V line from both PCs should just be disconnected. That way power is applied all the time, which should solve the problem.

    This solution also gives an added bonus – if You use a 850mA power supply (theoretical max for USB 2.0), it also doubles as a charger for some USB devices that can use the USB port to recharge internal batteries. And it’ll work with both PCs off, by the way, thanks to the internal power supply… 😉

  6. Just so there are no misunderstandings: in the powered version above, the PCs +5V must be disconnected from BOTH each other AND the device itself (best just cut the wires and isolate the stub so that it doesn’t cause a short – or solder it somewhere where it can’t do harm). The +5V for the device is provided by the power supply built into the switch. 850mA should do fine (this being aware that as part of the USB negotiation protocol, the device sends out its load requirements – this shouldn’t be affected). Also note that USB 3.0 has a higher power capacity (rated at 1500mA). Always remember to put a fuse into the supply line, it’s there to protect you from a fire!

    Also note that bridging GND from PC1 and PC2 is NOT recommended. For one, they can be at different potentials (which would cause power to flow from one PC and into the other, possibly burning the USB port and/or controller). For another thing, creating ground loops could also be an issue (both PCs are already grounded to the electrical grid, right?).

    If possible, the switching should be done by disconnecting D+/D- first, then switching GND over, and finally connecting D+/D- to the new host; if possible, a delay here would be most useful. IF YOU’RE USING RELAYS, make sure they’re the Break-Before-Make type (they break the old connection before making the new one) so that you don’t connect both PCs’ data lines together, even for a split second (make-before-break relays are suprisingly common so watch out for them).

    Still, the simplest version of this (as stated above) SHOULD be safe to use with most keyboards and mice – esp. the ones that have PS2/USB compatibility, since PS2 doesn’t introduce a delay between power and data connections, so the devices should be designed with that in mind already (the connection is handled by a single chip for both connections in those cases).

  7. Oh, my, me! I forgot that PS/2 connectors should be switched into/out of the PC when the power is off! 😀 Years of hot-plugging PS/2 connectors made me forget. SO – my last comment (about the USB/PS/2 devices) MAY NOT APPLY. Use with caution.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>