The aim of this tutorial is to explore Arduino which is an open source hardware as well as software platform!
AIM:- Making sounds from Arduino
- Arduino (preferably UNO)
- USB cable
- Buzzer ( or a speaker)
- Some wires
- Battery (optional)
We can develop sounds or annoying noises from Arduino and even Melody’s (just that like from a piano) on an arduino using the instructions below.
What we need to do is to just plugin the positive and the negative of the buzzer in breadboard.
Now comes the question how to identify the buzzer’s +ve and -ve……well that’s child play just as one do with LEDs, longer part is +ve and the smaller one is -ve.
FAIR ENOUGH :-
One might say what if the both leads are equal or are made intentionally equal?
That again is not difficult to figure out …..just use your Digital multimeter in Diode mode and see what is +ve or -ve?
- Take a wire and put it in Digital PWM pin (* pins) on Arduino (in this case 11).
- Put the other end of your wire in the +ve lead of buzzer through the breadboard.
- Similarly take a wire from ground or gnd pin from Arduino and put it to -ve of buzzer through breadboard
- Finally put the buzzer in the positive and the negative holes in the breadboard
And here is the code:
//make sounds with Arduino!
int buzzpin=11; //PIN11 IS USED FOR BUZZER
delay(10); //giving a delay of 10 milliseconds or a frequency of 100 Hz
delay(100); //wait for one-tenth of a second
Voila! What did we just do? Well Amazing! Mission accomplished or may be no!
Method used above is just OK! But seems quite boring and actually we did not do anything more software oriented……..So to begin again Let’s have a look on tone function http://arduino.cc/en/Reference/Tone
PS: tone() can be used with a pin only one at a time
Syntax of the tone is as follows :
tone(pin number, frequency (in Hz),duration(in ms))
means generating a 20,000 Hz sound on pin 11 for 1 second.
Now we gonna produce different frequency sounds using the code as follows:-
int buzz=11; //buzzer on pin 11
/*start with 20Hz and go through 20,000 Hz with multiples
delay(1000); //gap of 1 second
Pingback: "Hello, DIGITAL World!" with Arduino