Making Music

In this project, you'll learn how to generate sound with the Arduino.

Parts needed: Software stuff you'll learn: Arduino      Buzzer      Breadboard     
1 Making the connections
  • Connect one terminal on the buzzer to pin 8 on the Arduino.
  • Connect the other terminal on the buzzer to GND on the Arduino.
Tone connections
2 Create a new program by selecting File from the menu,
then select New.
3 Type in this program.









The tone command generates a music note in the given frequency, in this case 440 Hz, which is the A note on the piano.

The delay command causes the note to play for 1 second before turning it off with the noTone command.

The noTone command stops the sound.
Tone Melody
4 Upload and run the program. You should hear a note for one second.
5 Change the number 440 in the tone command to 523.
Upload and run the program again.
What do you notice? Experiment with other numbers.
6 This next program will play several notes of a song. Create a new program by selecting File from the menu, then select New. Type in this program.






The #define command defines an identifier name and assigns a number to it. For example, the identifier name NOTE_G3 is given the value 196. Later in the code, we can use the identifier name instead of the number.

The identifier name must start with a letter and cannot have any spaces.

Notice that there is no semicolon at the end of the #define line.
Tone Melody
7 Upload and run the program. You should hear a song.