The software in this tech note is for the Basic STAMP microcontroller. The concepts and circuit diagram hold for the Arduino microcontroller. After reading through this note, consult these additional resources for the Arduino
Arduino tutorial on playing a melody:
Arduino contributed software library for making tones:
The Stamp can make sounds by hooking up an external speaker controlled by a Stamp pin. Here's the simplest way to do it.
The speaker should be 40 ohms or more. The 10uF capacitor is optional but may help to kill some of the hiss. Try with and without and see which you like. Use a 10 uF electrolytic capacitor and watch the orientation
If the sound is not loud enough or if your speaker is less than 40 ohm, which most speakers are, then you should run your speaker through a transistor amplifier as shown in the figure below.
Again, the 10uF capacitor is optional. Generally, the bigger the speaker the louder the sound. There is no volume control. If the speaker is too loud, put a pillow over it.
Two Stamp commands generate sounds, freqout and dtmfout. For complete details, see the Stamp manual, available for free download from the Parallax web site.
freqout x, duration, note1, note2
where x = stamp pin (0-15), duration is length of tone in milliseconds, note1 is frequency (in Hz) of first note and note2 is that of the second which is played simultaneously to form a chord. The argument note2 is optional. For example
freqout 2, 1500, 500, 1000
uses Pin 2 to output a note 1.5 sec long that combines 500 Hz and 1000 Hz tones.
dtmfout 2, [5,5,5,1,2,1,2]
is used to make the audio sound like telephone buttons. The example about uses Pin 2 to "dial" the number 555-1212.
Try these two commands out and see what you get.
Here is some demo software downloaded off the Parallax web site that shows off sound capability (StampSounds.bs2).
Or, look up the freqout and dtmfout commands in the Stamp manual for more sample code.