Play RTTTL Sounds With Arduino

250px-A_PSF.png

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!

 

excellent

is there a particular circuit one needs for connecting the 'duino to a speaker?

I used a small piezo

I used a small piezo speaker, in which case I just attached the leads to pwm pin 13 and GRD. If you wanted to use a huge speaker, presumably you would need some more complicated circuit, but that’s it for the one I used.

oh, and you’ll see in that code there’s a comment that says to use 1k resistors. I didn’t, and it works fine, but your mileage may vary.

ok :smiley: how do you program

ok :smiley: how do you program this to an ATmega?

"Then it hit me: people

"Then it hit me: people don’t know how to make sounds with Arduino!"

What were you on when this hit you?

 

 

 


I was

I was on https://www.robotshop.com/letsmakerobots.

debugging

Hey,

Im trying to play the A-team theme song.

However, even though i position the library in multiple places, it still get this error:

‘Tone’ does not name a type.

Anybody an idea what is missing/i’m doing wrong?

 

 

you need a new IDE

Tone() became a part of the core library starting with version 18