GETTING STARTED WITH ARDUINO #3 Buzzer
by appytechie in Circuits > Arduino
3018 Views, 22 Favorites, 0 Comments
GETTING STARTED WITH ARDUINO #3 Buzzer
Hi, I am back here to explain the use of Piezo buzzer using Arduino.Have you you ever wonder of creating a music tone with the help of Arduino? This tutorial will teach you how to create a music tone with the help of this most used microcontroller. As I said in my previous tutorial these tutorial is completely dedicated for the beginner in electronics. So normally in my tutorial i will explain briefly about the components I use:
Arduino uno :-
Arduino is a pocket size computer that is used to control to control the physical world which cannot be performed by your desktop.It takes input from your input device such as sensors,switches and many more accordingly it controls the output device such as motors....etc The other application of Arduino is : -
-Programmable light displays that respond to music or human interaction
- Robots that use information from sensors to navigate or perform other tasks
- Unique, customizable controllers and interfaces for music, gaming, and more
- Connecting real world objects to the Internet (twitter is especially popular)
- Anything interactive
- Automating and prototyping
Piezo buzzer :-
Piezoelectric buzzers, or piezo buzzers, fitted into a wide array of products during the 1970s to 1980s .
Present day applications include:
Novelty uses
Educational purposes
Annunciator panels
Electronic metronomes
Game show lock-out device
-out deviceMicrowave ovens and other household appliances
Sporting events such as basketball games, electrical alarms
Joy buzzer- a mechanical buzzer used for pranks
So now time for having a look at the requirement.
THINGS REQUIRED :-
The things required for this simple project are :-
- Piezo buzzer
- Arduino uno
- Breadboard
- Jumper wire
Now let's build electronic.
PROCEDURE :-
This is very simple procedure, it just includes two steps :-
step 1 : Connect the red wire of the buzzer to the digital pin 0 arduino
step 2 : Connect the black wirre of the buzzer to the ground pin of the arduino
Now it's done.Time for uploading.
CODING :-
The code required for this awesome instructable is :
int speakerPin = 9;
int length = 15; // the number of notes char notes[] = "ccggaagffeeddc "; // a space represents a rest int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 }; int tempo = 300; void playTone(int tone, int duration) { for (long i = 0; i < duration * 1000L; i += tone * 2) { digitalWrite(speakerPin, HIGH); delayMicroseconds(tone); digitalWrite(speakerPin, LOW); delayMicroseconds(tone); } } void playNote(char note, int duration) { char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' }; int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 }; // play the tone corresponding to the note name for (int i = 0; i < 8; i++) { if (names[i] == note) { playTone(tones[i], duration); } } } void setup() { pinMode(speakerPin, OUTPUT); } void loop() { for (int i = 0; i < length; i++) { if (notes[i] == ' ') { delay(beats[i] * tempo); // rest } else { playNote(notes[i], beats[i] * tempo); } // pause between notes delay(tempo / 2); } }