Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Project 7: Musical Notes
1. 67
PROJECT 7 : Musical Notes
What we are making
In this project, we’ll see how to generate musical tones in Arduino
with a simple buzzer !
So, lets make some music - aka noise :)
PARTS :
+ This section lists the parts you
will need to complete the project.
JUMPER
WIRES
x 2 x 1
PIEZO
BUZZER
Parts Required:
PROJECT 7
2. 68Step 1:
PROJECT 7 : MUSICAL NOTES
Connect a Black jumper wire: UNO GND pin <-------> 30-a on Breadboard
Connect a Red jumper wire: UNO pin 8 <-------> 30-j on Breadboard.
Note that the color of the jumper wires do not matter.
Red and Black jumper wires are used as convention for positive
and negative terminals respectively.
3. 69Step 2:
PROJECT 7 : MUSICAL NOTES
Connect the longer-leg of a Piezo Buzzer to 30-f.
Connect the other end to 30-e.
This completes our circuit !
4. 70Step 3:
Open Arduino software (IDE) on your computer and write below code in it:
Now press the upload button in Arduino software.
5. BINGO !!
Your Arduino should be playing Sa-Re-Ga-Ma-Pa-Dha-Ni-Sa now !
71
Explanation:
In our code, we declare 2 variables:
int wait - This variable is used to store the value 500 which is
repeatedly passed to the tone method later on.
int pin - This is the pin number to which our Piezo Buzzer is connected
(via the jumper wire). In the setup() method, we set pin 8 as OUTPUT so
that we can output avoltage on this pin later on.
6. Question:
PROJECT 7 : MUSICAL NOTES
A Piezo buzzer typically does exactly as its name suggests. You put a
voltage across its terminals and you get a beeping sound/noise.
But there is more to it. If you feed it with a pulse, instead of a DC voltage,
it will sound at the frequency of that pulse and thus can play a note / tone!
Thankfully there is an in-built tone() function which takes the pin number,
frequency and the duration as parameters.
Remember that each note of Sa, Re, Ga, Ma, Pa, Dha, Ni, Sa has a
different frequency. We pass this frequency to the tone() function
to get the corresponding sound.
72
Answer: Try it before reading further.
The resistor will take limit the current flowing to the Piezo Buzzer.
Thus the sound will be of lower volume.
What will happen if we put a resistor in the circuit ?