I've a circuit that have one input pin that should go LOW if one of two conditions is accomplished:

  • USB is connected;
  • Button OR Switch is pressed/slided;

If USB is connected Button or Switch is ignored and input pin is always LOW.

Button may be permanent or momentary. Switch is a standard 3 pin switch.

Input pin voltage rate is indifferent, so 3v3 and 5v it's ok.

The button/slicer need to be debounced.

The only debouncer and ON/OFF switcher ICs I've found(with low power consume and small package) are:

  • LTC2950
  • MAX16054
  • MAX6816

Initial state of input pin should be always 1 even if I reinitializate deboucers ICs.

I prefer a momentary button(if the name is right) if is possible, but if not switch it's also ok.

My main problem is that this pin should go LOW when USB is connected even if switch output is 1.

Can you advice me a solution?

  • \$\begingroup\$ This seems like this application would be easy to accomplish using a small micro-controller, to detection of USB connected, switch and debounce and the logic operation and maybe some pull-ups for initial conditions. \$\endgroup\$
    – Kvegaoro
    Commented May 22, 2015 at 14:55
  • \$\begingroup\$ Agree on a micro being an easy solution for this. Could also do solely hardware based, but I'm not about to build the whole circuit for you... \$\endgroup\$
    – I. Wolfe
    Commented May 22, 2015 at 15:15
  • \$\begingroup\$ Luckily I just did :-) It's not even that big.. \$\endgroup\$
    – Asmyldof
    Commented May 22, 2015 at 15:28
  • \$\begingroup\$ How is the USB powered? Is this a host or slave? \$\endgroup\$
    – lm317
    Commented May 22, 2015 at 17:45

1 Answer 1


How about this:


simulate this circuit – Schematic created using CircuitLab

If the USB is connected, the Q1 will conduct and the output will ALWAYS be 0.

If the button is not pressed, R3 will charge the capacitor (in about 7ms to Vbase-on) and the Q2 will turn on, again pulling the output low.

If the button is pushed, the capacitor will be discharged and the Q2 be turned off, if then Q1 is also off (no USB connected) R2 will pull the output weakly high to the supply voltage. That signal is "strong enough" for a microcontroller, but if you need it to be stronger, you can reduce the resistance or build a sort of H-driver with one PNP and one NPN transistor.

The resistors are chosen such that at 5V the system will not drain more than 0.2mA (both USB connected and SW1 pushed in), reducing the resistances will increase the current draw, increasing them will reduce the consumption.

Be aware that changing R3 will also change the time constant for the switch debounce. Higher value -> stronger debounce / slower release response, lower value -> weaker debounce / higher release response. But you can easily vary the capacitor between 0.1uF and 10uF without any danger, larger values will give slower debounce, smaller will give faster response.

EDIT: In the comments it is pointed out you want the output to go low when the button is pushed. To Q2 you will need this change:


simulate this circuit

Switch one will now quickly charge the capacitor, and it will discharge slowly through R3 into the base of Q2. No extra parts and nearly the same effect. Only now, when the button is pushed the output turns low. Also the time constant is different, because the capacitor needs to discharge further down than it had to charge up before. Quick guesstimate this will get you about 35ms (at 5V)

  • \$\begingroup\$ OP wanted the button to pull the output low when the button is pressed, not when it is open. I am also curious as to what the debounce he wanted is needed for. Good drawing though. OP should be able to take that general idea and incorporate it. \$\endgroup\$
    – I. Wolfe
    Commented May 22, 2015 at 16:44
  • \$\begingroup\$ I'll add a small note, good looking out. \$\endgroup\$
    – Asmyldof
    Commented May 22, 2015 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.