Headphone detection and output selector circuit. Yay or Nay? diagram included

I’m working on an external circuit to add to my arduino synth. The circuit’s designed to play audio from a L and R channel through a built in speaker by default, but upon detecting a headphone jack, it stops playing through the speaker and indicates that it’s playing though the audio jack instead. I have a two pairs of LED indicators to indicate whether L or R is playing internally or externally. e.g. Red indicators for the speaker, and Blue indicators for the line out.
For the line out, I also added a switch to swap between mono and stereo and a pot to control the volume.

This is my first attempt at designing any kind of circuit, only found out what transistors look like a few hours ago. I’m unsure whether the logic is right, so I’m posting a diagram of the circuit so you can tell me if I should go ahead or go back to the drawing board! :slight_smile:

I’m particularly concerned about whether my pot’s in the right place and whether it will interfere with the transistor next to it.

Here it is:

There are female audio jacks that works like a switch, so you don't need to use that

I'm pretty sure that's how I have it set up. I'm intercepting the 'ground' coming back from the headphones and treating it like a HIGH value. Then it's sent through the transistor and +5v to invert the value and turn off the speaker output. e.g. HIGH on audio jack converted to a LOW value sent to the other two transistors.

I didn't know any specific symbol for the female audio jack, so I just drew it as two switches, if that's confusing you!

If you're talking about a fancy female jack, I don't have one. It would take away from the challenge anyway! :)

OK, lot's to cover here:

  • Please keep images less than 1000 pixels wide. The forum makes these poster-size attachments really hard to look at.

  • What's L and R "data"? What does the signal look like? PWM from +5v to 0v? AC from +0.7v to -0.7v?

  • Why do you have LEDs inline on (what I assume are) audio signals?

  • Switching audio jacks aren't "fancy", they're the correct, purpose-built tool to solve this very problem. You have Gnd, L, and R, plus a switch that is physically set by the headphone plug when it is in the jack. This switch does not carry audio -- it's there for whatever arbitrary signal you need for your plug/unplug detection. (In your case, probably 5vDC.)

  • You should not use a pot on the ground side. The normal way of attenuating volume on an audio signal is a two-gang (one for L, another for R) variable resistor with one end connected to the signal source, the opposite end connected to ground, and the wiper connected to the output. This way, the load on your device is always pretty much the same (the resistance from one end to ground), but the voltage passed on to the sink device (your speaker or headphones) is set through a voltage divider formed by the position of the wiper on the resistive material.

What you have drawn is a rheostat that adjusts the resistance to ground. You're effectively changing the ground reference from low-impedance (what it should be) to high-impedance (which is not what it should be.) At high-impedance, the L and R headphone drivers will reference each other instead of ground.

  • Very rarely is it a good idea to feed the same signal voltage to an internal speaker and headphones. You're either severely under-powering the internal speaker, or you're going to blow your eardrums out of your eye sockets. Have you ever heard a 5v signal through earphones? Ouch!

  • Your mono/stereo switch circuit looks suspect. There's a pretty good chance all you're doing is shorting the L and R sources to each other. If they're driving the exact same signal level, it'll be mostly OK, but if that were the case, it would be inherently mono anyway, and thus defeat the purpose of having a summing switch at all. The more likely case is there are different voltages from L and R. Shorting them together means the higher one will be driving the lower one. This is not what you want. Now, having the LEDs in there prevents reverse biasing, although it's still not the the right way to go about it.

So, ... sorry man, this entire thing probably should be scrapped and re-designed.

The internal speaker is actually connected to an amplifier, but I left it out for simplicity's sake. the reason I wanted to have this circuit was because of lack of pins and the overhead required on the software side to sense and switch outputs. I've been looking up how to make sure the audio being sent to headphones won't be damaging, but still in the process of doing that. I need to find the right minimum resistance or maximum voltage.

As for the type of signal, I'll admit that was a bit vague. I made a bitbang-based synth library and have it running through a guitar hero controller. L and R are two pulse channels / square waves which are basically digitalWrite(HIGH) and digitalWrite(LOW) alternations.

I'll take out the pot then, but I'll continue on!

OK! That I can work with. But first, what’s your amp setup look like? There are a few details that make it important – particularly, what are you using as an audio ground? This is typically 1/2 Vcc to allow positive and negative swings around the center point, assuming you’re capacitively coupling your speaker – BTW, are you?

You don’t really need any pins on the micro to handle plug / unplug events. A couple analog options that spring to mind:

  • Use the HP jack switch to enable power on the external amp. When the headphones are plugged in, the switch opens and the amp turns off. Depending on the rating of the switch and the current draw of your amp circuit, you might need a transistor on the amp’s power rail, controlled by the switch. If you need to invert the logic (switch is closed when headphone are removed, for e.g.) you can use an NPN / P-ch combo (or PNP / N-ch, or whatever…)

  • Use the HP jack switch to turn on a transistor which grounds the audio input to the amp when headphone are inserted. The amp can remain powered this way – which may or may not be desirable. You will need to isolate the amp input from the headphone feed, since otherwise you’ll ground the audio signal and won’t hear much from the 'phones. I attached an example schematic, although keep in mind it’s a concept more than a complete working circuit. (There’s no capacitive coupling here either, for e.g., nor does it address appropriate signal level for each output.) The 8-ohm resistor represents your speaker, and the 64-ohm resistor represents earphones.