Hi!
I want to mute the speaker when I'm using an audio jack with a diy gamebuino, arduboy and espboy that I'm planning to make. I surfed the web for a couple of hours and I don't know if I'm doing it well. Here's a photo of the audio schematic:
While it makes sense to have a current limiting resistor between D3 and the speaker, I would have thought the same to be true between D3 and whatever is going to be connected to the jack socket. I would therefore suggest moving the 100 ohm resistor between D3 and the socket. Even with a 100ohm resistor in series, that would draw 50mA. The specification allows for up to 40mA per GPIO pin, so I would probably increase that value to at least 120ohm which would be just about on the limit, or perhaps even 150ohm which would give a safe margin by limiting to 33mA, assuming an 8 ohm speaker. If you wanted/needed more power, then you will need a transistor. You might also consider a 10uF capacitor in series with the speaker/earphone to block DC.
Your schematic looks correct with the input connected to the switched input. So your actual wiring probably doesn't match the schematic, or maybe you don't have a switched connector.
A stereo switched (or "closed") jack has 5 contacts - Left in & out, right in & out, and ground. (Sometimes there are extra ground/mounting contacts.)
You might have to check/identify the connections with your multimeter while plugging-in a plug with nothing connected to it.
Yep, the speaker that I'm going to use has 8 ohm. Thank you for the suggestion about the resistors. Putting the resistors with 200 ohm will save some energy or it will be too much?
BTW, my assumption here is that the switch is normally closed thus connecting the speaker while no thing is connected to the jack, and open when a plug is inserted thud breaking the speaker connection and passing the signal to the device connected to the socket. Often there will be a resistor across the switch so that the output level is reduced when an earphone/headphone is connected. Disconnecting the plug closes the switch and delivers full power to the speaker. Given the relatively low output levels here, and additional resistor across the switch is probably not necessary. Good idea to check and identify the connections first though.
Yes, not a good idea to connect the speaker directly to the GPIO pin like that unless its a high impedance device. Otherwise It may work, for a while at least, but ultimately risks damaging the GPIO output.
As you already have done, by including a current limiting resistor in series with the speaker. The capacitor I suggested is an additional precaution so that if the GPIO pin gets left high for any reason, you will not have a continuous current running through the speaker.
Sorry, didn't spot the polarity markings on the speaker object. They should be the other way around as you say, negative to ground, positive to the jack.
Just because someone has been stupid enough to draw a schematic showing a speaker being connected directly to an Arduino pin, doesn't mean that it won't destroy your Arduino, if not immediately, but in the long run.
With arduboys and gamebuinos some people use piezo and others speakers. The games on these devices only makes beeps so a piezo is not a problem but, the espboy can run gameboy games and I don't think that they will sound great with a piezo speaker. That's why I want to use the 8 ohm 0.5w speaker (the same that the gameboy pocket use).