This tutorial of Robo India is on Peizo Buzzer. Here two examples are included one plays beep sound and other one plays a song.
1. Introduction:
This tutorial of Robo India expalins how to use a Peizo Buzzer on Arduino. When voltages are supplied to its terminal it generates beep sound. This buzzer is used to give beep sound to various embedded systems.
2. Required Hardware
Following Hardware will be required to perform this sketch of shift register.
S.No. | Item | Quantity |
1. | R-Board with FTDI or Arduino Board | 1 |
2. | Bread Board | 1 |
3. | Male to male Jumpers | 5 |
4. | 100 OHM Resistance | 1 |
5. | 5 Volt Buzzer | 1 |
3. Building Circuit
Make following circuit with the help of above mentioned components. We have included two examples here both of them use the following circuit.
3.1 You may go with Robo India’s R-Board(UNO Compatible)-
Here is the schematic of this circuit-
or
3.2 You may go with original Arduino UNO Board-
Here is the schematic of this circuit-
4. Programming 1 – Playing a beep sound.
Once we are done with circuit part, here is our programme to this circuit. Every command of the following programme is explained in the comment section.
You may download this code (Arduino Sketch) from here.
/* Beep sound generation Tutorial By Robo India http://roboindia.com */ const int Buzzer = 9; void setup() { pinMode(Buzzer, OUTPUT); } void loop() { digitalWrite(Buzzer, HIGH); delay(400); digitalWrite(Buzzer, LOW); delay(2000); }
5. Programming 2 – Playing a song:
Cicruit is same as above mentioned. Copy this code and upload to your Arduino board.
You may download this code (Arduino Sketch) from here.
/* Tone generation Tutorial By Robo India http://roboindia.com note frequency c 262 Hz d 294 Hz e 330 Hz f 349 Hz g 392 Hz a 440 Hz b 494 Hz C 523 Hz */ const int Buzzer = 9; const int songLength = 18; char notes[] = "cdfda ag cdfdg gf "; // a space represents a rest int beats[] = {1,1,1,1,1,1,4,4,2,1,1,1,1,1,1,4,4,2}; int tempo = 150; // Speed of tempo void setup() { pinMode(Buzzer, OUTPUT); } void loop() { int i, duration; for (i = 0; i < songLength; i++) // step through the song arrays { duration = beats[i] * tempo; // length of note/rest in ms if (notes[i] == ' ') // is this a rest? { delay(duration); // then pause for a moment } else // otherwise, play the note { tone(Buzzer, frequency(notes[i]), duration); delay(duration); // wait for tone to finish } delay(tempo/10); // brief pause between notes } while(true){} // Remove this line if you want to play this song for ever. } int frequency(char note) { int i; const int numNotes = 8; // number of notes we're storing char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' }; int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523}; for (i = 0; i < numNotes; i++) { if (names[i] == note) { return(frequencies[i]); } } return(0); }
6. Output:
Here is the output of the above two examples.
if you have any query please write us at: info@roboindia.com
Thanks and Regards
Content Development Team
Robo India
http://roboindia.com