Using a 555 timer as a timed switch for a USB device?

Thread Starter

Dowapa

Joined Sep 3, 2021
13
Without getting too into the weeds of my project; what I am attempting to do is to control the plugging in and removing of a basic USB device. To accomplish this, I have cut open the USB cable of my USB device and have cut the 5V line. I plan to connect the two sides of the 5V line to two switches in parallel (such that either switch can be used to activate the USB device and simulate the device being plugged in).

The first switch is a simple toggle switch. When closed, the first switch would simply connect the line and the USB device would act as it normally would and stay powered as long as the switch is closed.

The second switch is the part where I'm having trouble and need advice. I want the second switch to be on a timer circuit such that when I press a pushbutton, the switch closes for <~30 seconds allowing the USB device to be connected and detected by my PC. Then, after the ~30 seconds open again, disconnecting the device.

Here is a rough drawing of the circuit. The bit on the bottom left is the male USB plug that plugs into a PC, the top left is the simplified USB device, with the Gnd, Data+, Data-, and 5V terminals. (I apologize for the low quality, I drew it quickly on my whiteboard just to illustrate my idea).
Screenshot 2022-01-04 204958.png

My original plan was too use a 555 Timer as a one shot to accomplish this, but I started to get confused because I didn't know how to handle my USB device being both the load and the voltage supply for the circuit. I'm also aware that the USB device probably expects a full 5V upon being plugged in, and I'm worried that undervolting the device (due to charging/discharging a capacitor in a 555 circuit for instance) could cause damage to the device or my PC (I don't know a lot about how USB ports and devices function and want to be safe).

This got me thinking that I might be approaching this circuit from the wrong direction and wanted to see if anyone could help me reevaluate my design. I am not tied to the 555 timer and am open to any ideas, criticisms, ect. I'm also not opposed to connecting the timer circuit to a separate, external power supply, but I feel there's probably a simpler solution that doesn't involve another set of wires.

Thanks in advance!
 

sghioto

Joined Dec 31, 2017
5,376
Simple solution is the 555 controlling a relay.
The relay contacts perform the switch function with no lost of voltage. The 555 circuit and relay are all powered by the 5 volt USB.
1641487511639.png
 
Last edited:

Thread Starter

Dowapa

Joined Sep 3, 2021
13
Simple solution is the 555 controlling a relay.
The relay contacts perform the switch function with no lost of voltage. The 555 circuit and relay are all powered by the 5 volt USB.
Thank you for the reply! So what would I use as my ground in this case for setting up the 555 timer? Would ground be the "To USB device" lead? Or would it be a separate common point?
 

sghioto

Joined Dec 31, 2017
5,376
That will work, however with the component values shown the timing is highly dependent on the relay coil current.
Using a 5 volt 75 ma coil relay the timing was only 12 seconds. One could use a larger capacitor but better approach would be to add a second BC547 connected in a darlington configuration or use a FET. Doesn't need a reverse diode across the coil because the drop out voltage is only 1 volt.
1641503289236.png
 
Last edited:

MisterBill2

Joined Jan 23, 2018
18,167
I am wondering what sort of reason there is for this scheme. It makes no sense at all as I see it, because the software will get confused.
 

Thread Starter

Dowapa

Joined Sep 3, 2021
13
It is not the same if the signal/data wires remain connected.
Even with the data wires connected how would the PC recognize the device if the power is removed?
I have never tried this myself but maybe someone else has some input.
Tested it personally before moving to this step. By placing a switch in the middle of the 5V line of a USB cord, when plugged in you can simulate the device being unplugged and plugged in by flipping the switch. I haven't extensively tested it, so If there's something fundamental about how USB plugs work that I'm unaware of that could cause damage to my PC/USB device by doing this I'd ofc like to know.

But as far as I'm aware, simply disconnecting the 5V line from the PC would break the primary power of the USB device, which would be the same as simply removing the USB device from the computer manually.
 

Thread Starter

Dowapa

Joined Sep 3, 2021
13
I also appreciate the more detailed schematics! I'll post a finished product whenever I get everything wired up and working~
 

k1ng 1337

Joined Sep 11, 2020
940
falstad.com/circuit/ is a neat simulator which has several 555 timer examples which you can build on.

I recommend you go back and research the 555 in both astable and monostable operation. Then you can use a power transistor such as a BJT or MOSFET to power your circuit. It sounds like your playing around on the breadboard so it would be a good exercise to calculate the losses when using a transistor to switch a power source. The CMOS version of the 555 (TLC555 in my case) is also worth looking into.
 

AnalogKid

Joined Aug 1, 2013
10,986
But as far as I'm aware, simply disconnecting the 5V line from the PC would break the primary power of the USB device, which would be the same as simply removing the USB device from the computer manually.
Not quite. The data lines still are connected. This can be a problem because now there is the possibility that a data line into a chip in the USB device is high while it has no Vcc (Vdd) connection. Driving an input to an unpowered chip can cause "latch-up", a consequence of CMOS part fabrication that can destroy the chip. Many USB devices have protection against this designed in, but it is a possible issue.

ak
 
Last edited:

Thread Starter

Dowapa

Joined Sep 3, 2021
13
Not quite. The data lines still are connected. This can be a problem because now there is the possibility that a daata line into a chip in the USB device is high while it has no Vcc (Vdd) connection. Driving an input to an unpowered ship can cause "latch-up", a consequence of CNOS part fabrication that can destroy the chip. Many USB devices have protection against this designed in, but it is a possible issue.

ak
That’s good to know. It just so happens that the USB device I’m using has an exposed circuit so it should be relatively easy to check for that kind of protection if I know what I’m looking for; if you could give me an general idea of what to look for I’ll check.

Other than simply relying on the failsafe, what would be a better solution? Should I attach the data lines to the relay similar to how I’ve connected the VCC line? That way they’re disconnected and connected in continuity with the power line?

Another thing to note is that most of the time this USB device is not going to be written too and will only be read from for the ~30 second interval after it’s plugged in.
 

MisterBill2

Joined Jan 23, 2018
18,167
The best solution will be to do the delay in software, providing a delay in whatever routine initiates sending the message out the USB port to that connected device. I think that is possible, at least it was possible back with DOS.
 

BobaMosfet

Joined Jul 1, 2009
2,110
Some times, simple and reliable is better if you don't know what you're doing. What about using a daily timer and a USB Charging Adapter. You an get the timer from Amazon, and plug it into wall power:

1641842379488.png

And USB Chargin Adapter like this:

1641842439541.png
 
Top