USB Device Project - Right for Arduino?

Hi Folks,

I am a software tester who spends a lot of time testing USB Aircards (3G/4G modems). A portion of my testing involves "surprise removal" of the USB device on Windows and Mac platforms. This seems like a good use of the Arduino Platform to automate this tedious task.

Basically, I think I just need a "switch" that will cut the 4 USB Lines at a predetermined time and then reconnect them after x seconds. I would then increment a counter, wait x seconds and repeat.

Any suggestions/hints on what I should look at in the Arduino platform.

Thanks, Tim

Well, for the most accurate representation (mechanical insertion/removal) of this, you would probably want to use a relay - a 4PDT relay would be perfect, like this one:

Alternatively, you could use two DPDT relays, or four SPDT/SPST relays.

Hook it up according to the numerous examples available, coding is just toggling a digital i/o pin HIGH or LOW.

Hook the usb wires up to the relay (as close to the relay as possible), and the coil thru an NPN transistor (like a 2n2222) with a snubber diode across the relay's coil to prevent kickback voltage from destroying your transistor; the base of the transistor should go to the digital i/o pin with a bias resistor (1k or so) in between.

Hope this helps. Good luck!

This would be a very simple task for an Arduino.

As a USB connector has 4 conductors, two of which carry power current I think a simple 5vdc coil 4PDT relay would be the simplest method to have an Arduino disconnect and reconnect a PC USB link to your device under test. Here is a good relay to use:

You would have to drive the relay coil with a transistor as the coil draws around 80ma which is more then an output pin can supply directly. Also a reverse connect diode across the relay coil is recommended.

I would suggest the four USB lines to be switch wire from the four common and normally closed contacts. Then when the Arduino turns on the relay, the USB contacts would open up, causing your ""surprise removal" situation.

What would remain for you to do is to design the user interface (could even be controlled via the Arduino USB serial link and a PC program, or standalone with hardware UI components (switches and displays).

Good luck


Hey cr0sh you sure picked a big, ugly, and wrong voltage relay, where the same firm has the a much better, cheaper, smaller, 5vdc, and prettier relay such as I choose. I guess there is no accounting for taste. ;D


I'm a q&d kind of guy, I guess - just grabbed the first thing I saw; I would hope the builder of the circuit would verify things. I guess I shoulda looked closer; most of the time it seems you can't find 5VDC 4PDT relays, they almost always seem to be 12VDC...

I would say you only need to switch the two signal lines because the power being switched has no effect on the system. I assume this is to test the software drivers for the modem.

I've noticed hotswappable connectors often have an order that the contacts disconnect in, rather than all disconnecting approximately at once.

I could see how not having a set order for disconnecting contacts could fry things, if things are setup in an unlucky way.

Not sure how much USB cares, or how important it is in general.

It’s always ground that gets connected first on hot-swappable connectors, right?

In usb the two data lines gets disconnected first, and then the power lines, I think data should be always disconnected first because removing power abruptly will generate random data that could cause some failure in the host application(a BSOD after removing a pen-drive).

Thanks everyone for the hints. I am off and running!