I want to have 6 audio jacks IN waiting for connection to start some WAV/OGG playback as soon as a headphone plugs in. In fact, I'd like to have simultaneous playback in 6 lines.

I've seen in the market some stuff that you can add buttons to different actions (play, pause, stop, etc). So far I believe this might be possible and affordable with Adafruit's Audio FX (which are stand-alone, Arduino-programmable WAV/OGG decoder circuits).


Is it possible to start audio playback when headphones gets plugged in? HOW?

Is that an event? like pressing a button?

Does it need some "hacking" between GND lines maybe?

  • 5
    You can detect when a headphone is plugged in because the connector closes a switch within the body of the audio jack when its fully plugged in (assuming you're using a 3.5mm jack). If you have a function for starting playback, you can call it as soon as the MCU detects the switch has been closed. – SoreDakeNoKoto Apr 23 '16 at 22:52
  • @TisteAndii - You should turn your comment into an answer... I'd give it an upvote :-) – Greenonline Apr 26 '16 at 16:04
  • @Greenonline thanks...was waiting for some feedback from the OP to know if its what they want – SoreDakeNoKoto Apr 26 '16 at 16:14
  • @TisteAndii - I would think that it is the best [only?] and most obvious way to go... it was the first thing that came to my mind, when I saw the question. – Greenonline Apr 26 '16 at 16:16

A lot of 3.5mm jacks come with built-in normally-closed contacts, and their state can be tested through the pins of the jack with a multimeter or sensed by your MCU like any other switch. There are usually 2 pins each for the ring (pins 2 and 4 below) and the tip (pins 3 and 5), each pair connected to the other and one pin for the sleeve. The insertion of the headphones' connector breaks the connection between each pair, so that only one pin of each pair is actually connected to the connector's tip and ring.

jack schematic

You can connect the tip (pin 3) of each jack to digital input pins and connect the other pin of the pair (pin 5) to Vcc; you only need to read the tip because if the tip contacts are closed, it means nothing is fully plugged in yet. When no connector is plugged in, input pin reads HIGH from the tip since it is connected to Vcc through pin 5. When the headphones are plugged in, it breaks the 3-5 connection, and the tip now floats. Its voltage is indeterminate; it will probably sit somewhere near the middle of the 0-5V range, but we can't be sure. To remedy this, there are 2 possible approaches I can see:

  • You use an analog input pin, instead of a digital pin. This way, you can read the very voltage at the tip; if its ADC value is above 900 perhaps, you can conclude that its HIGH and therefore nothing is plugged in, whereas if its below 600, you can conclude that the tip is floating and a headphone is plugged in. However, this method will require an input pin per headphone. The Uno has 6 analog pins, so this will take up all of them. If you aren't already using any of them, this method may be good enough. You could also use an analog GPIO expander.

  • You can use a digital input pin for the tip (pin 3) but instead of pulling pin 5 to Vcc, you connect it to a digital output pin. You can connect the pin 5 of each headphone set to this common output pin. To test if a particular jack has headphones plugged into it, you read the associated input pin and check if this is the same as the current value of the common output pin (saved to some variable). If it is, you toggle the output pin and again check the input pin to see if it mirrors the new value of the output pin; just additional confirmation. If everything checks out, then nothing is connected to the jack yet. If either test fails, you can reasonably conclude that headphones are plugged in.

Now that you know headphones are plugged in, you can call the appropriate function to begin playback through the right jack. Of course, all this assumes you'll be working with the jacks directly and not through some module. If you use the Adafruit Soundboard, you can check out the L (Left Channel) pin, which corresponds to the tip. I don't know if it's actually connected to the jack so you'll have to experiment and find out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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