Play RTTTL Sounds With Arduino
I was wondering why, despite the notice on the front page, there weren't very many robots with sound. Then it hit me: people don't know how to make sounds with Arduino!<!--break--> So I peeled my Seeeduino Mega out of the bubble wrap and started googling.
Alright, so you remember how to make sound from RTTTL with picaxe? You can do the same thing with a little tweaking on the Arduino.
First (well, other than an Arduino), you need an RTTTL code. You can find a lot of these on the web, or if you have a musical bent, make your own. This is helpful for debugging sounds for me.
You'll also need a piezo buzzer or speaker. I had one I gutted from an old toy; you can get one at your local electronics store for like a dollar. Somehow attach the speaker between pin 13 (a pwm pin) and the GRD. You can change to any other pwm pin later, but just stick with me for now. Also, a comment in the later code says to use a 1k resistor. I didn't and it worked fine, but it might be a good idea to do so.
Then, go here and download the file. Unzip it. Open your Arduino sketches folder and, if you don't already have it, make a file called 'libraries'. Put the folder you just downloaded in the folder you just made.FFinally, go Examples inside the folder Tone and open the file called RTTTL in the Arduino IDE.
See where there are a bunch of lines with things like "//char *song" and then a bunch of nonsense in quotes? That nonsense is the RTTTL code. The first thing you want to do is uncomment one of those lines by getting rid of those two slashes. (You can upload it to your Arduino now and play the Simpsons theme song if you want).
Paste your RTTTL code between the quotes, hit upload, and bask in the glory of 8-bit sound!