Headphone detection - Page 1
Forum section: electronics / projects

author: Digibin
author_rank: Regular Contributor
timestamp: November 30, 2015, 09:24:30 pm
content: I have an audio output through a digital SPDT that switches between a miniature loudspeaker and a headphone output. The headphone connector does not have a mechanical switch indicating plug insertion. The SPDT is controlled by a microcontroller. I want to determine whether or not the headphones are connected. So I've got the headphone line tied to an input pin with internal pull-up. When the headphones are connected they pull the line low. I read this on the microcontroller and switch the SPDT to the headphone output. But I can't see an easy way back. If the headphones are removed, the line is still being driven so I cannot use it's high or low state. I would have to momentarily switch the SPDT back and read off the logic state of the headphone line. This would cause a blip and I would have to perform this check regularly so this doesn't work.I could use a headphone jack with a mechanical switch, this is probably the easiest solution. Alternatively I could use a current sense resistor to determine if current is flowing out of the headphones port. But that's just over-complicating things.Is there another simple solution? I'm happy either way, just curious.

author: trevorford
author_rank: Contributor
timestamp: November 30, 2015, 09:48:25 pm
content: The simplest solution is usually a headphone jack with the switch in it they aren't super expensive either.http://www.adafruit.com/products/1699

author: Delta
author_rank: Super Contributor
timestamp: November 30, 2015, 10:11:55 pm
content: Quote from: trevorford on November 30, 2015, 09:48:25 pmAgreed. K.I.S.S.If you must do it with the existing socket, how about reading the level with the MCU's ADC and watch for a drop as the headphones load down the output...?

author: Zero999
author_rank: Super Contributor
timestamp: November 30, 2015, 11:30:13 pm
content: I agree with the above: a mechanical switch is the simplest option.However, this may not be possible if this is retrofit and the connector can't be modified.A pull up resistor will work but you also need a low pass filter to remove the audio signal so it can't drive the MCU input.

author: tooki
author_rank: Super Contributor
timestamp: December 01, 2015, 11:43:22 am
content: IIRC, a lot of gadgets use headphone jacks that simply have two independent contacts for the ground sleeve. One is connected to the ground, the other is used as a sense pin. This avoids the size and potential reliability problems of a mechanical switch. (iPhones use a similar setup to detect a microphone on the headset: If the second ring shorts to ground, it knows there's no microphone and the software knows that pure headphones are attached. If not, it then begins the various sensing tests to determine what kind of microphone/remote are attached, and sets up accordingly.)

author: Fungus
author_rank: Super Contributor
timestamp: December 01, 2015, 11:55:17 am
content: Quote from: Digibin on November 30, 2015, 09:24:30 pmThat depends on how high it's being pulled. If the pullup pulls higher then the maximum headphone voltage then it's easy to detect.

author: TheUnnamedNewbie
author_rank: Super Contributor
timestamp: December 01, 2015, 12:19:32 pm
content: A way I know it's done in active guitars is to have one more ring than needed. The last ring will mate up with the ground line of the headphone and can be used to sense if a headphone is plugged in. For stereo headphones you could use a TRRS jack (provided the headphones don't have fancy in-line controls since they would stop this from working.EDIT: I only now noticed that tooki posted exactly the same reply.Since a picture says more than a thousand words (or something along those lines) - my apologies but I can't seem to get my image to rotate as it should:

author: tooki
author_rank: Super Contributor
timestamp: December 01, 2015, 01:34:55 pm
content: A picture is worth a thousand words, so it's still great to have your diagram (and confirmation that I'm not talking out of my ass)!

author: Digibin
author_rank: Regular Contributor
timestamp: December 01, 2015, 06:22:36 pm
content: This isn't a retrofit - I'm free to chose another connector, which I will most likely do. I was just curious if there was an easy way to do it with a standard connector.Thanks for the replies.

author: Richard Crowley
author_rank: Super Contributor
timestamp: December 01, 2015, 06:38:23 pm
content: Maxim makes some models of their headphone driver chips that have built-in headphone detection. They also have several application notes on their website on the topic of headphone detection. The most straightforward method appears to simply use a jack with a switching contact.https://www.maximintegrated.com/en/pst/run.mvp?q=headphone+detection

author: Zero999
author_rank: Super Contributor
timestamp: December 01, 2015, 08:28:29 pm
content: A low pass filter will work.I've shown the AC coupling capacitor to the amplifier. Normally this would be polarised with the positive going to the amplifier and negative to the load. The problem is the pull-up resistor would reverse bias it, if the amplifier's bias pint is under 5V. The capacitor could be reversed or made non-polarised by connecting two back-to-back.