Instructables
Picture of Arduino Basics: Making Sound
The arduino is surely the little micro controller that could. you can do so much with it! We at instructables have been having so much fun with our arduinos, we wanted to show the instructables community how to do some of the basics!

This first tutorial will go over how to make your arduino make simple sounds, and turn your arduino into mini tone generator.



 
Remove these adsRemove these ads by Signing Up

Step 1: Supplies

Picture of Supplies
For this tutorial you will need the following

1 small 8 ohm speaker
1 arduino board
1 push button
1 10 k resistor
some solid core wire

For my purposes, i used the adafruit protoshield to help me lay it out my stuff!
jvictor44 minutes ago

Would it be better if we use the piano key frequency formula -> f(n) = 2 ^ (n - 49/12) * 440 Hz, instead of defining all tones?

smackaay1 year ago
If you put a capacitor in series with the speaker it will be much louder.

what type of capacitor?

how to set up it?

thanks..

tvance929 made it!5 months ago

OK - piece of cake and very very cool ... but one thing TOTALLY escapes me... How do you 'jam out' so 'radically'!?!? The hood, the matching glasses... the rockin mouth poses! Please add instructable on this as well please, otherwise this tutorial is just not complete. :)

keyboard.jpg
Where did you get the 8 ohm speaker? Thanks.
crazyg1 year ago
consider me tuned !
crazyg crazyg1 year ago
Can two tones be played at the same time, and what does the resistor do? Would like to be using square waves somehow.
crazyg crazyg1 year ago
Yes they can,kinda choppy,and I still don't know bout the resistor, this is what iv made with the tone function, will write it up soon, ordered some relay shields the other day ,but now iv used the board, doh.
1271843_614348325255054_1590190615_o.jpg
jsori1 year ago
having a problem with the Pitches.h file. i can get it to work when i use the absolute path, but i can't get the relative path to work. i put the Pitches.h in the same folder as the .ino and i'm using a windows machine. anyone know why the relative path isn't working?
bespired1 year ago
Well cool ! 
I had to assign a path in the h include. But's that prob just because I'm a noob.


#include "./Pitches.h"

// notes in the melody:
int melody[] = { NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4 };

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = { 4, 8, 8, 4,4,4,4,4 };

void setup() {
  int speakerPin = 8;
 
  // iterate over the notes of the melody:
  for ( int thisNote = 0; thisNote < 8; thisNote++) {

    // to calculate the note duration, take one second
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 700/noteDurations[thisNote];
    tone( speakerPin, melody[thisNote], noteDuration );

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay( pauseBetweenNotes );
    // stop the tone playing:
    noTone( speakerPin );
  }
}

void loop() {
// no need to repeat the melody.
}
bespired1 year ago
I saved the pitches defines as a .h file in the folder where the sound.ino went.
And included the .h file with a relative path.

#include "./Pitches.h"

That was the only way i could get it to work.
Thanks.

panton2 years ago
Would it be possible to make a sound recording and then have the speaker play the sound recording? I want my garduino to talk when he is hungry hehe.. I have a little 8ohm like the one used in this tutorial. Very cool tutorial.
I don't have any speakers, although i do have some piezo buzzers. Will one of these work instead of the speaker?

-TheWaddleWaaddle
I got my speaker from an old tv at goodwill. The TV cost 99cents and I got 2 speakers!
Yes, they will
trouble013 years ago
We need some videos about this project !!!!
Udon trouble013 years ago
Yeah, we wanna hear!
villahed943 years ago
Can this Arduino make sounds ala chiptunes using a fairly common SN76489? Thanks in advance
sockless3 years ago
What waveform is the tone generated by the arduino?
jensenr303 years ago
sweet pics, dude. are those 3-D glasses?
no they r wayfarer(spicoli) shades. u can buy em in a mall at like zumiez. they r like $10
frenzy (author)  jensenr303 years ago
No they are 4D
ynze3 years ago
Cool I'ble! I get the feeling that even I can do this. Thanks!
Carleyy3 years ago
These pictures are too awesome!!
Thanks, this helped me out a lot!