Making Music
In this project, you'll learn how to generate sound with the Arduino.
| Parts needed:
Software stuff you'll learn:
- tone,
- noTone,
- #define,
- #include
|
1
| Making the connections
- Connect the buzzer with the two pins to columns 40 and 43 on the breadboard.
There'll be two holes in between them.
You might have to very gently squeeze the two pins slightly apart in order to fit.
The pins break very easily so be very gentle when you squeeze them apart.
- Connect one terminal on the buzzer to pin 8 on the Arduino.
To do this, plug one end of a wire into a hole below column 40 on the breadboard, and plug the other end of the wire to pin 8 on the Arduino.
- Connect the other terminal on the buzzer to GND on the Arduino.
To do this, plug one end of a wire into a hole below column 43 on the breadboard, and plug the other end of the wire to GND on the Arduino.
|
|
2
| Create a new program by selecting File from the menu,
and then select New.
You will see this new template.
|
|
3
| Type in this program.
The pinMode command tells the Arduino that our buzzer is connected to pin 8.
The tone command generates a music note in the given frequency, in this case 440 Hz, through the specified pin number, in this case it is pin 8. The frequence 440 Hz corresponds to 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 from the buzzer that is connected to pin 8.
|
|
4
| Upload and run the program. You should hear a note for one second.
|
| |