Audio Jack Detection

Go To Last Post
25 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi All,

 

I require a bit of guru input.  I have 2 x 3.5mm stereo female jacks, the 1st is a speaker output, and the 2nd is a headphone out.  These jacks are waterproof and this variety do not include the detection pin, only two pins +v and -v.

 

Essentially I am trying to achieve an auto detect.  When the headphones are plugged in the headphones are enabled and work, and when the speakers are plugged in the speakers are enabled and work.  Most of the TI and Maxim chips require more than 2 pin female jacks to function.  I understand the auto detect can be detected by a resistor network combo but I cannot find this.

 

Could anybody offer me advice on my design.

 

Thanks,

 

Tuurbo46

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We require a bit more information. What is driving these jacks?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A block diagram would help; perhaps (also) a schematic ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can use a simple pullup resistor to create a DC offset on the audio signal when notthing is plugged in.

When you plug in a speaker / headphone (Typically < 100 Ohm Impotence to GND)  The DC offset will collapse.

If there are large Elco's in the signal path which get discharged through the speakers this will create audible "plops".

So be a bit carefull where you put the resistor.

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

I currently have a TI LM4952TS running a speaker and it works great.  

 

I would like to put a switchcraft NPB638 jack in series between the LM4952TS and the speaker, and a second switchcraft NPB638 jack in parallel with the first running the headphones.

 

A switching circuit is then required in between the LM4952TS and two jacks to detect if either the headphones or speaker are plugged in.

 

 

Thanks,

 

Tuurbo46

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Paul mentioned adding a pull-up resistor.

You might also try adding two resistors, both large, set up as a voltage divider.

If the speaker or earphone are not present, then the ADC will read ~ Vcc/2.

 

If you plug in a 4 ohm speaker or a 100 ohm earphone, etc, the lower leg of the divider is essentially shorted out, and the ADC will now read << Vcc/2.

The exact value can be calculated if you know the spec's on the speaker and earphone, but it practice the exact value won't matter.

 

Know that the two resistors and the output cap form a LPF, and the resistors will draw current all the time, which can be important for a battery operated device.

For these reasons make them high values resistors, perhaps higher than the 100K shown.

 

For very power conservative designs, you could power the top of the resistor divider with an I/O pin, and turn on and off the test circuit, as needed.

 

Above is untested.

 

JC

 

Edit: Typo

 

 

Last Edited: Wed. Mar 14, 2018 - 02:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@DocJC. The technique is valid of course, but creating a 100mV offset or so seems more logical.

I left it deliberately to OP to figure this out (he already mentioned 2 resistors in his first post) to keep it "short".

My posts tend to get rather long sometimes...

 

Jo forgot to put a junction/ dot on the crossing between the resistors & the speaker output.

Why all those dots on the speaker? All insignificant.

 

A bit more sophisticated:

Without adding any external resistors you can put a varying DC bias on the "Audio input".

Then you can measure the RC time constant on the speaker output with the ADC.

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Tuurbo46 wrote:
These jacks ... do not include the detection pin

So why not just find some that do, then??

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi All,

 

I was thinking of a circuit like this:

 

Relays are active on and fets are N-fets logic level.  I think this will work but not sure if the gates will get upset with audio AC applied to them.

 

The functionality of the circuit is, when the circuit is switched on with no headphones or speaker connected both relays are on.  If either the headphones or speaker is connected, the other device is deactivated because the n-fet is pulled low.  Does this circuit make sense, and would it work?

 

Thanks,

 

Tuurbo46

 

 

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

and would it work?

Probably not the way you would like it to.

 

You are using the NFets as switches to turn the relays on and off.

In this mode, as a switch, one wants to turn the NFet either fully on, or fully off.

 

In the schematic you presented, the resistor divider will hold the gate at Vcc/2.

One would have to look at the specific NFet to see if this is off, on, or in between.

 

You are assuming that it is off, and that the added audio will turn it on.

This is not a good assumption.

 

If you wanted to do this, you would typically use an envelop detector or peak detector, etc., to watch for the presence of the audio signal, and then you would have a method to hold the NFet (and relay) on for some duration of time, so that this doesn't chatter with the incoming audio signal, and low and high volume audio.  You don't want the relay to drop out any time there is a moment of silence in the audio...

 

In my suggested circuit, you would have two adc's reading the two outputs to see if there is a speaker or earphone present, and then turn the audio on/off as desired, (perhaps through a control pin on the audio amp, (I didn't look at the amp chip)).

 

Paul,

The dots are artifact from the drawing software, and don't mean a connection.

Old school.

If the lines cross at 90' then they connect.

If there is a semi-circle arc "over" the wire, then they don't connect.

 

Sorry for the confusion.

 

JC

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I thought you wanted some kind of feedback to a uC ?

Using relays and mosfets seems like overkill for a circuit like this.

 

Another technique is to put a resistor in series with the audio and simply short the "output side" of the resistor to GND with a transistor or Fet when you want the output to be off.

 

But for really good advice we need to see the whole picture. Where is your audio coming from? Is there a uC nearby?

Tuurbo46 wrote:
When the headphones are plugged in the headphones are enabled and work, and when the speakers are plugged in the speakers are enabled and work.
  Euhm, I Assumed (which is...) that you are familiar with the fact that your speakers & headphone will stop working when you pull the plug out?

If so, then why do you need detection?

 

If it has anything to do with the "waterproof" ness of your connectors. If the inside of the connectors gets wet while there is a DC voltage present they will corrode. You will need a different kind of circuit for that.

 

My first vote is with AwNeil. Go get yourself a waterproof plug with the switch built in.

If that is not an option, then measuring the RC constant seems second best.

If waterproofness is an issue, beware of DC voltages and electrolysis.

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Paulvdh wrote:
(Typically < 100 Ohm Impotence to GND)

Being of a certain age, my Impotence has a much larger resistance.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Being of a certain age...
... that could change every year now smiley

(No intention to insult), sometimes I just can't resist letting some typo's be for wahat they are.

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

Tuurbo46 wrote:

These jacks ... do not include the detection pin

 

So why not just find some that do, then??

 

Or, at least, get the "stereo" versions of those connectors.

 

That is, the ones with Tip, Ring, and Sleeve (TRS) contacts:

 

Image result for Tip, Ring, and Sleeve

 

Since you are just using TS plugs, their Sleeve will short the Ring & Sleeve contacts of a TRS ("stereo") jack - so you can use that to detect an inserted plug!

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi All,

 

Thank for your great feedback.  I have hunted the internet for a 3.5mm waterproof female jack with enable but I cannot find one.  If I could find one it would solve this problem easily.

 

I have added a schematic below related to paulvdh post.  I think this is what you were meaning.

 

As I understand it, audio is an AC signal and the ADC would struggle to read this.  However the signal would be collapsed and close to 0V when either the headphones or speaker are plugged in, so the ADC should be OK reading this low voltage?  If I add a capacitor before each ADC pin would this will affect the audio out signal?  

 

Hope this makes sense.

 

 

Thanks,

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tuurbo46 wrote:
I have hunted the internet for a 3.5mm waterproof female jack with enable but I cannot find one.

But, surely, there must be TRS ("stereo") ones ??

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Of course audio is an AC signal. If audio were a DC signal your ears will get filled with audio and burst.

It's also why C1 and C2 are in the last schematic. They block the DC part.

Part of my advise was based on the assumption you could make your audio source emit a DC signal for headphone detection.

 

The circuit as you have drawn it is exactly what I mean.

Unfortunately I've made an error there, I did not think it through completely.

If you put a 1k resistor in series with an 4 Ohm speaker you wil not be able to get any decent sound level output.

Shorting the  signal to GND is only a viable option with high impedance inputs, such as an opamp buffer in the place of your speaker / headphone.

 

After all these posts I get the general idea that your experience level with electronics is not very high.

I want to reccomend that you build some ciruits on a breadboard. Find out your self what works, and what does not work.

In the mean time you'll boost your general knowledge of electronics.

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Paulvdh wrote:
If audio were a DC signal your ears will get filled with audio and burst.

I don't know which emoticon to use for this.

 

If there are going to be circuit changes made then I'd suspect that there is >>somewhere<< a more appropriate plug.

 

That said, one can use the internal pullup of the AVR.  IME (at least in one app) the weak internal pullup is defeated [enough] by the low impedance connected device that it nicely reads logic 0.  Pin change can be used to detect some plugging/unplugging changes.

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That said, one can use the internal pullup of the AVR.  IME (at least in one app) the weak internal pullup is defeated [enough] by the low impedance connected device that it nicely reads logic 0.  Pin change can be used to detect some plugging/unplugging changes.

But then the AC coupled drive to the speaker/headphone would swing the I/O pin below ground, and the protection diode would take the brunt of it.  Wouldn't you need a high-value resistor before the I/O pin?

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

The dots are artifact from the drawing software, and don't mean a connection.

Old school.

If the lines cross at 90' then they connect.

If there is a semi-circle arc "over" the wire, then they don't connect.

huh? Have you ever used Eagle?  Wire that cross at 90 deg should never be assumed as a connection.  Also a 4 way connection should never be used, dot or no dot (in case the dot does not show through clearly on a copy).  They should be shown as staggered T connections. 

 

this:

 

not this

 

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In my world: Draw dots to connect wires.

No dot == no connection.

 

There is nothing wrong with 4-way connections.

No dot is no connection, just 2 wires.

A dot means a 4 way connection.

 

It's not my rule I just follow the rules of my PCB Package (KiCad)

But I believe there is pretty much a consensus on this.

 

And for everybody else reading this:

Please stop using the "arcs / bows" to let a wire jump over another wire. This was amost abolished in the '70ies and '80ies when schematic entry programs became common.

I have never ever seen a  schematics package that uses them. Maybe some insignificant niche program uses it.

And it didn't even work properly on paper. Tried to draw such a "bow", made it a bit too small and it looked like a "dot".

Only DaveCad still uses it.

 

It's simple:

Wires do not connect untill you connect them. Wether you do it with a green dot or with a dab of solder does not matter much.

All those arcs and bows in a cable conduit of cables trying to avoid touching each other is a big squimy mess.

Something resembling this:

 

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:
does not show through clearly on a copy
That was the "rule" back when every thing was a paper copy and few if any electronic files. I bad spot on a copier could totally change the meaning of two crossing singles...

I still follow that rule; however, with most schematics provided electronically, I don't think it is as valid as it once was.

 

We used the "crossing arcs" at one of my former employers, but crossing wires were never to be connected even if there was a dot.

David (aka frog_jr)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

https://www.autodesk.com/products/eagle/blog/top-10-tips-draw-next-schematic-design-like-pro/

First, whenever you have two wires that form a junction and share an electrical connection, that intersection needs to have a junction dot. This is standard practice in every schematic design, and some tools like Autodesk EAGLE will add the junction dot for you

When adding junctions for intersecting wires, it’s also recommended to avoid a 4-way intersection as this will likely add to the confusion when reading your circuit. Instead, opt for a set of shared intersections as shown in the image below where each junction has its own unique connection. This makes it much easier to understand exactly the proper connections and avoid misinterpretation.

 

https://webcache.googleusercontent.com/search?q=cache:n3a1z2Hcbt4J:https://www.revolvy.com/main/index.php%3Fs%3DCircuit%2520diagram%26item_type%3Dtopic+&cd=9&hl=en&ct=clnk&gl=us

 

 

 

Wire Crossover Symbols for Circuit Diagrams. The CAD symbol for insulated crossing wires is the same as the older, non-CAD symbol for non-insulated crossing wires. To avoid confusion, the wire "jump" (semi-circle) symbol for insulated wires in non-CAD schematics is recommended (as opposed to using the CAD-style symbol for no connection), so as to avoid confusion with the original, older style symbol, which means the exact opposite. The newer, recommended style for 4-way wire connections in both CAD and non-CAD schematics is to stagger the joining wires into T-junctions.[3]

The linkages between leads were once simple crossings of lines. With the arrival of computerized drafting, the connection of two intersecting wires was shown by a crossing of wires with a "dot" or "blob" to indicate a connection. At the same time, the crossover was simplified to be the same crossing, but without a "dot". However, there was a danger of confusing the wires that were connected and not connected in this manner, if the dot was drawn too small or accidentally omitted (e.g. the "dot" could disappear after several passes through a copy machine).[4] As such, the modern practice for representing a 4-way wire connection is to draw a straight wire and then to draw the other wires staggered along it with "dots" as connections (see diagram), so as to form two separate T-junctions that brook no confusion and are clearly not a crossover.[5] [6]

For crossing wires that are insulated from one another, a small semi-circle symbol is commonly used to show one wire "jumping over" the other wire[3] [7] [8] (similar to how jumper wires are used).

A common, hybrid style of drawing combines the T-junction crossovers with "dot" connections and the wire "jump" semi-circle symbols for insulated crossings. In this manner, a "dot" that is too small to see or that has accidentally disappeared can still be clearly differentiated from a "jump".

 

 

 

 

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Paulvdh wrote:
a big squimy mess. Something resembling this:

Image result for electric wires india

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

...and don't forget your schematic & soldering iron.