In this project we will use the piezo speaker to make music.
What You Will Need
Seven long wires (1 Red, 2 Black, 4 Other)
Some small wires
One piezo speaker
Three buttons
Three 10k – ohm resistors (brown – black – orange – gold)
Wire your circuit up like the following. If you use a small piezo you may have to wire the circuit up slightly different. Also note that the small piezo speakers have the power and ground marked on them on the bottom.
WARNING: THE CIRCUIT HAS AN ERROR IN IT. THE GREY WIRES IN LINE WITH THE BUTTONS SHOULD BE WIRED FROM POWER NOT GROUND!
The following code does not use the buttons but is intended to show you how the piezo speaker works.
In your Arduino program enter in the following code:
Run the program and observe the results!
In the tone command you take in two parameters. The pin that supplies the power, followed by the frequency of the note. 440Hz is the note A.
Try the following code:
Before you run your program try and predict the outcome.
The noTone function requires one parameter; the pin that you are turning off.
The last code I want you to run is the following:
Exercise
Create the code required to make a keyboard that will play a note when a button is pressed. There should be no sound coming from your circuit when the button is not pressed. You must be able to play the hit song “Mary had a little lamb”. You may need to look up the notes to the song, as well as their respective frequencies.
Once you are done submit your code and show me that you can play your keyboard.
Scoring
Can play Mary had a little lamb (Checklist). 30%
Code submitted with comments explaining what the code does. 40%
Total 70%
Extension
Research or play around with a third parameter for the tone function.
Rewrite your code so it uses that third parameter. 30%
New Total 100%