View Full Version : Detecting if headphone is plugged in.

06-09-2016, 11:32 PM
How would i go about turning off lineout if a headphone is plugged in?

06-09-2016, 11:54 PM
If you are talking about the Teensy Audio Adaptor Board, there is no way of sensing whether headphones are plugged in or not. But in general this detection is done by a headphone socket that has an integrated switch which is normally closed and opens when a jack is inserted: https://en.wikipedia.org/wiki/Phone_connector_(audio)#Switch_contacts
So you could build a detection circuit yourself.

06-12-2016, 02:02 PM
You'd first need to get a headphone jack with the extra switches inside, which connect or disconnect when the plug is inserted.

If using the audio shield, the headphone ground is actually a 1.6 volt DC output, and the 2 signals have 1.6V DC offsets. If the switch connects another pin to the headphone ground, you could just look for 1.6V. If the switch connects the audio signals, you could use a low-pass filter to remove the higher frequencies and then look for 1.6V DC. Probably add a pulldown resistor, like 100K, so the pin goes to zero volts when the switch inside the jack disconnects it. You could build a circuit or just use one of Teensy's ADC pins to read the voltage. If it's low-pass filtered audio, of course the number will vary quite a lot from the 1.6V level, but you still should be able to tell the difference between audio and no signal, if you look at several measurements.