This question already has an answer here:

I asked a similar question on a different website, DreamInCode, for assistance programming on an Android. I've also come on to this site for a different question but I can see that the folk that use this forum may also have a different set of expertise that may be able to assist me [specifically the USB tag]

Here's the link to the alternate question, but I'll rephrase it for additional clarity below: http://www.dreamincode.net/forums/topic/408284-can-i-drive-a-voltage-output-on-the-dd-lines-of-usb-communication/page__pid__2347827__st__0&#entry2347827

I'm using a SAMSUNG Galaxy S7 (although I don't believe the phone itself should matter, suffice to assume it's a modern android) and I've built my own modified USB OTG(OnTheGo) cable so that the phone can deliver power to an external device. For example, let's say I'm powering an LED in some external circuitry (I'm an electrical engineer). What I am trying to do is use the phone to enable/disable the external device(LED), preferably via an app on the phone. For my purposes, the circuitry must be enabled or disabled via user input on the phone.

I've tried googling how USB Serial communication works, and I have learned that the D+/D- wires are often pulled to specific voltage levels for certain chargers. Compatible phones will recognise these specific voltage levels and negotiate to receive higher voltage or current than normal to enable fast charging. What I haven't been able to determine if you can set the D+/D- wires as an output from the phone to certain voltage levels (e.g. digital HIGH or LOW), and use them as a DC control signal to connected to an electrical switch.

It is also important to me that this occurs through Serial communication; not wirelessly, bluetooth or via the audio jack, but I haven't been able to determine if I can set the phone to deliver a DC voltage from the D+/D- wires continuously (for a few seconds) to enable the device whilst it performs a measurement. The device itself will be powered by the USB OTG from the phone (5V) and draws very low current (milliamps).

If anyone could please help and identify a way to set a DC output on either of the D+/D- USB communication wires (or confirm if this is possible), I would greatly appreciate it :)

Sadly I do not understand enough about USB communication and all my research has returned is the protocol and sequence of various USB packets, not how the communication actually operates or if I can manipulate the D+/D- wires into a DC voltage source (low current is fine). I also believe the maximum voltage of the D+/D- wires is TTL Voltage (3.3V), commonly interpreted as a HIGH at 2.8V.

EDIT: If it were possible, the DC output on the D-/D+ wire would not drive any significant load, it would be used as a control signal to place an electrical switch (BJT,MOSFET) into saturation. Typically the base current of a BJT or gate current of a MOSFET is micro-amps.

Edit2: There is a much better explanation on Using D+ and D- from USB as power source?, by DrFriedParts. Ali Chen also comments on DrFriedParts that sending a stream of uninterrupted 1s may be possible, using a test mode.


marked as duplicate by Tom Carpenter, DoxyLover, Dave Tweed Dec 20 '17 at 12:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


What I haven't been able to determine if you can set the D+/D- wires as an output from the phone to certain voltage levels (e.g. digital HIGH or LOW), and use them as a DC control signal to connected to an electrical switch.

This type of low level control is not possible with the typical USB implementation.

But you may be able to turn the OTG Host power on and off. See: https://stackoverflow.com/questions/14151077/android-usb-otg-programmatically-turn-off-power-to-the-port

It involves needing Root.

  • \$\begingroup\$ Thank you for your comment. I'm also planning on implementing a OTG Y-cable though, to allow the phone to charge whilst the device is in use. When the charger is connected: the phone needs to be out of OTG mode so it receives power and begins to charge. During this time the power from the charger also powers the device. So if I only have the ability to turn the OTG off, that doesn't prevent the device being on for long periods during charging, which may gradually affect the performance and lifetime of the components in the device \$\endgroup\$ – Jakkatak Dec 20 '17 at 23:36

no, you may not. D+/D- is the bi-directional data line. it is not meant to supply power to a device. ... of course you could attach a USB device that accepts commands and outputs the required voltages. the the current for the output would be supplied from the +5V Vbus which can supply up to 500mA.

  • \$\begingroup\$ Don't assume the charge pump in a phone can supply 500mA. \$\endgroup\$ – Chris Stratton Dec 20 '17 at 13:44
  • \$\begingroup\$ I'm not attaching a USB device per se, I'm using a USB cable from the phone to deliver +5V DC to an external device. Currently, they D+/D- lines are left floating. Given that it doesn't need to be bi-directional, and I understand I wouldn't be using it for it's intended purpose, is there no way to constantly loop the phone through sending the same output, and being able to utilise that, e.g. for digital logic? \$\endgroup\$ – Jakkatak Dec 20 '17 at 23:36
  • \$\begingroup\$ did you not understand the first four words of my answer? \$\endgroup\$ – jsotola Dec 21 '17 at 1:55

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