Home Forum

Turn headphone jack into GPIO

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 :)
 

Related:

#1 KminekMatej, May 21, 2018
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.
 
#2 mikedt, May 23, 2018 Last edited: May 23, 2018
Yes, it's possible...

Here's a schematic on how headphones are wired internally:
[​IMG]
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!
 
#3 Daniel Fernandes, May 23, 2018
Thank you guys. If you would be chicks, I would say I love you both
 
#4 KminekMatej, May 29, 2018