0
\$\begingroup\$

Is it possible to detect that there is a device connected on the other side of the cable without using any current sensor? I simply want my arduino to do something when i plug my phone to charger.

I have tried to use 4N35 without success as shown on the picture, even with some resistors.

???

I know i could use something like ACS7xx current sensor but i think it could be done without it.

Another way to do this would be to use DATA lines of the usb since they are pulled either HIGH or LOW but i'm not sure if i want to mess with that.

Any help or advice would be highly appreciated.

Thanks.

EDIT I have tried to detect the device on DATA line and it works, unfortunately only when the device is on since i need to read HIGH signal.

\$\endgroup\$
  • \$\begingroup\$ Your 4N35 is trying to act as a current sensor, it is not designed to withstand the current that could be drawn by your USB device. As to it not working: Mabe the shielding provides a short between your ground and the devices ground, shorting the 4N35's LED. \$\endgroup\$ – Wouter van Ooijen Jul 3 '15 at 17:39
  • \$\begingroup\$ The mobile charger shorts the data lines of USB. The short can be detected from other side of the cable. \$\endgroup\$ – Umar Jul 3 '15 at 17:48
  • \$\begingroup\$ @Umar I know about the shorting and I tried to detect the device on DATA line and it works as long as the device is on. When its off i don't know how to detect it. I just think it should be trivial but nothing i try seems to work. \$\endgroup\$ – Molda Jul 3 '15 at 19:09
  • \$\begingroup\$ This will not necessarily be trivial. A current sensor could detect when the phone is drawing charge power, but once it is charged if the device is asleep there may be no noticeable draw. And in the USB charging case, the resistors are usually on the charger, not the phone, so that won't work to detect the phone - unlike with an actual USB port, where there port detects the peripherals pullup on one or the other of the data lines to indicate its base speed. \$\endgroup\$ – Chris Stratton Jul 3 '15 at 19:31
1
\$\begingroup\$

The device has a pullup on one of the data lines depending on its speed. Host has (weaker) pulldowns. When both lines are zero there is no device. When one is one there is a device. USB is 3.3V bus BTW, design your detector accordingly, and measure at the host connector.

\$\endgroup\$
  • \$\begingroup\$ This may not work if the host connector is a power supply with its own biasing resistors. Those tend to be weaker than the USB detect pullup, so the phone probably does some algorithm of trying to be recognized by a host controller or trying to recognize a charger, both connecting its own pullup resistor and trying to detect externial bias resistors with its own pullup removed. The success of the goal will depend on it if tries its own pullup before checking for bias resistors, or even if it finds them. If not, if it recognizes a charger without every applying the pullup, then this won't work. \$\endgroup\$ – Chris Stratton Jul 4 '15 at 1:02
  • \$\begingroup\$ @Oleg Mazurov Sorry i didn't mention that i also want to detect a device which is swiched off (after battery drained) so can't use DATA lines. \$\endgroup\$ – Molda Jul 4 '15 at 7:55
  • \$\begingroup\$ @Molda: The pullup resistors that Oleg is talking about are connected to the USB power bus, not the device's internal power supply, so they are always active. \$\endgroup\$ – Dave Tweed Jul 4 '15 at 22:38
  • \$\begingroup\$ @DaveTweed - no, they probably aren't. In a smartphone that can detect weak charger bias resistors, they are almost certainly switched in and out of the circuit under software control. If they were permanently connected they would preclude detecting the charger's bias on the data lines. Even many simple micro controllers implement the pullup internally under software control. \$\endgroup\$ – Chris Stratton Jul 5 '15 at 22:39
0
\$\begingroup\$

So i've found a solution. enter image description here

Thanks for comments and answers.

\$\endgroup\$
  • \$\begingroup\$ Since you don't really know if it is a solution, it is not an answer to your question. So you should edit your question to include this attempt. \$\endgroup\$ – Lorenzo Donati Jul 4 '15 at 10:06
  • 1
    \$\begingroup\$ Well i have tested it and it works as expected (Q3's base straight tu MCU). I can detect a device and then start charging. And that's what i was after. \$\endgroup\$ – Molda Jul 4 '15 at 12:14
  • 1
    \$\begingroup\$ Then edit the answer to reflect this, so that anyone looking at your answer in the future knows it is a solution, not a simple hypothesis (as the text in your answer could imply). \$\endgroup\$ – Lorenzo Donati Jul 4 '15 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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