I am designing a new board, where I need to detect if the DC input jack for powering the board has been plugged and then disconnect the USB power supply. I also need to detect it with the uC in order to enable some functions when I have a power supply. The problem is that both of them are 5V inputs.

DC power supply:

DC power supply

USB power supply and power selector:

USB power supply and power selector

I have a couple of conditions in this circuit:

  • DC Power not connected / USB connected / USB Host function OFF: In this scenario, the comparator outputs a low voltage which makes Q3 to be ON (p-channel) and this helps me have a clean 5V through this circuit.
  • DC Power connected / USB connected / USB Host function OFF: In this case, I want to disconnect the power from the DC jack from the USB, so current does not go into the USB connector. It shouldn't, since both of them are 5V, but stay with me. So, the comparator outputs a high voltage and turns Q3 off, disconnecting VUSB and 5V, and taking current only from the DC jack.
  • DC Power connected / USB connected / USB Host function ON: Now I want the device to be able to give power to the USB port, so I turn Q2 on with the USB_HOST_EN signal and power can flow from 5V to VUSB through Q2.

This circuit is a remix form the SparkFun SAMD21 breakout board and the typical power selector circuit that a lot or Arduino Boards use.

The problem I see is that when the USB is connected, the 5V from the USB can be found also at VJACK, so the comparator will always have its output at a HIGH state.

Q1 is a reverse polarity protection transistor. I thought of just putting a diode and that would solve all these problems, but I would not have 5V after the diode, but a 0.7V or more drop.

Also, since both the DC jack and the USB will have 5V, I thought the whole power selection circuit could not be there at all, and just join both 5V outputs, after Q2. But then the body diode from Q2 would also drop 0.7V when Q2 is off (Non host operation) and I would have less voltage than required.

Can anyone help with ideas on how to solve this?

Thanks a lot!

  • \$\begingroup\$ On a different note, the USB shield usually isn't connected to GND on the slave device site, or connected through a small capacitor. See here: How to connect USB Connector shield? \$\endgroup\$ Sep 24, 2018 at 23:39

1 Answer 1


One simple path that has escaped your considerations is that most DC power barrel jacks have an additional contact, precisely for the purpose of easy selection of power sources. See this contact in your schematics, red circled:

enter image description here

There are many uses of this extra contact, and I am sure the use of it will highly simplify your problem.

  • \$\begingroup\$ Thank you very much. That can really help. It's, for now, one possible solution, by tying that pin to 5V through a pull-up, and with that turn the Q3 ON or OFF. If the plug is connected, the 5V would turn the transistor OFF as requested, and if the plug is not there, it will be tied internally by the connector to GND. Thank you! I think other answers can still help, but it is a great catch. \$\endgroup\$ Sep 24, 2018 at 21:24
  • 1
    \$\begingroup\$ It's useful in some circumstances, but you need to be aware that an activation of the "plugged-in" switch on the jack is not the same as power being available. Firstly because the switch sometimes triggers before the plug actually makes contact and secondly because a user may plug the power supply into the device before plugging it in to the wall. \$\endgroup\$ Sep 24, 2018 at 21:48
  • \$\begingroup\$ @PeterGreen, unless I missed something, I don't see the requirement for power to be uninterruptible. \$\endgroup\$ Sep 24, 2018 at 22:36
  • \$\begingroup\$ Yeah, I did not mention it, but Peter is right, and we actually thought of it. A new solution we came up with, is this: goo.gl/fb8Awa A digital power switch. We can measure the voltage level at the input of the IC and enable it depending on this measurement. And also, we would turn Q3 ON or OFF with the uC, to be sure that we have power before disconnecting the USB power. It'd be dangerous not to detect if the voltage from the power supply is or isn't there, since we plan to give LEDs a certain brightness with USB and a different brightness with an EPS. Thanks to both of you! \$\endgroup\$ Sep 24, 2018 at 23:06
  • \$\begingroup\$ @sanotronics, if you are serious, you don't need to invent your own switches. There is a line-up of ICs called "Power Path Controllers". analog.com/en/parametricsearch/11029 You might want to check few other related posts like electronics.stackexchange.com/a/351468/117785 , or electronics.stackexchange.com/a/321927/117785 \$\endgroup\$ Sep 25, 2018 at 3:38

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.