How to connect Arduino to headphone jack?

I would like to connect a headphone jack to my Arduino and make it as an output. I mean I would simply send some simple beeps.

I know that there is a breadboard friendly headphone jack, but I don't know how to wire it. I really don't know if I can simply connect the Arduino to the headphone jack, or I will need some resistors, etc. Will I need some voltage measurements?

Also, can I do this simply by connecting the parts of the jack ( right, left, GND) to the Arduino?

This project connects the headphones directly to a digital pin. Here is the schematic:

I would, however, be more cautious and add a limiting resistor. The output of an Arduino pin should be limited to 20mA as stated here. So, using

V=I*R

5 = 0.02 * R

R = 5 / 0.02

R = 250ohms

So I would add a ~250ohm resistor in series with the head phone. Especially if I were debugging my code. That is, in case I accidentally left the output pin high for an extended period of time.

The head phones should have some DC resistance. If the sound is not loud enough you might measure that DC resistance of the head phones and subtract it from the 250 ohm resistance calculated above and use a limiting resistor of that value instead.

I had the same problem and here how I figured out a solution,

Assume your stereo jack is connected to the folowing pins; Pin 9 = Left stereo Pin 10 = Right stereo GND = Ground

The solution relies on using arduinos inner circuitry. Pin 9 and Pin 10 are our pins to control left and right stereo sounds. We need a third pin which will be the main output source for stereo both(left and right) condition.

Say this pin be Pin8. Connect Pin8 to Pin9 and Pin10 by two resistors of 1kOhm or similar depending on your sound level choice.

When you seet pin8 mode to OUTPUT, pin 9 and pin 10 modes to INPUT, and when you play a tone at pin8 as tone(pin8,duration,frequency) will play stereo on the headphone.

On the other hand if pin9 is set to OUTPUT and pin10 set to INPUT, playing tone at pin8 will flow the current through right pin of the stereo jack, right sound.

Similarly if pin10 is set to OUTPUT and pin9 is set to INPUT,and tone played at the pin8 send the current through left stereo jack connected to pin9, left sound is played.

Hope this helps.