• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Turn headphone jack into GPIO

KminekMatej

Lurker
Hey guys,
I have a device, that based on some event, closes the relay output. I need an app on Android to react on this event and make some action based on this input (actuallly saving exact time of this event to sql db).

Easiest solution that comes on mymind is using headphone 3,5 jack as an GPIO input pin.

Can I somehow detect on Android, whether the two pins on jack are closed or not? Mabe I would need to connect some resistor to the pins instead of directly connecting them, thats doable.

Any help appreciated :-)
 
Hey guys,
I have a device, that based on some event, closes the relay output. I need an app on Android to react on this event and make some action based on this input (actuallly saving exact time of this event to sql db).

Easiest solution that comes on mymind is using headphone 3,5 jack as an GPIO input pin.

Can I somehow detect on Android, whether the two pins on jack are closed or not? Mabe I would need to connect some resistor to the pins instead of directly connecting them, thats doable.

Any help appreciated :)

That might be possible, because I think that's basically how wired headsets work when you press the inline control to pause/play music or answer a call. Also some selfie sticks have a remote shutter release that uses the jack. I'm not a developer of course, so can't help you there.

EDIT

In fact I just dug out the multimeter and tested it with a stock Oppo headset, and pressing the inline control puts a short across the mic connections on the TRRS jack-plug. So that's how it's connected and the phone detects that.
 
Last edited:
Yes, it's possible...

Here's a schematic on how headphones are wired internally:
U2BDN.png

Play/Pause is where you can connect your relay switch. Connect the COMMON and NORMALLY OPEN terminals to it. (You can also connect NORMALLY CLOSED)

(Ignore FWD and REV, those are two extra buttons of the headset. I couldn't find a better schematic... Actually all the wiring there is not required for you... You just need to connect the relay at GND and MIC+)

Then you just need to add some code to detect a headset button press (sorry, can't help you with that...)

Good luck for your project!
 
Back
Top Bottom