Buzzer Application with Arduino
Buzzer Application with Arduino

Buzzer Application with Arduino

Buzzer is used as a sound warning element in many electronic systems. In this application we will see how to use the buzzer in addition to different projects.
Buzzer is an easy to understand circuit element. It has two pins.

We will connect one end to digital pin 2 of the Arduino board. We will connect the other end to GND.

We will send note signals to the buzzer with "tone" from Arduino codes. Below are the numerical values corresponding to each note.

We need to add a waiting period between the notes with the help of the "delay" command. Otherwise, the notes are incomprehensible.
Arduino codes are below:
int buzzer=2; //Uno digital out pin number
//freq------------------------------
int Do=261;
int Re=294;
int Mi=329;
int Fa=349;
int Sol=392;
int La=440;
int Si=493;
int Do2=523;
//------------------------------------------------------
int notes[]={La,La,La,Do,Do,Re,Mi,Mi,Re,Do,Re,Mi};//notes
 
void setup()
{
  pinMode(buzzer,OUTPUT);
 }
 
void loop()
{
  int i;
   for (i=0;i< sizeof(notes)/sizeof(int);i++)
         // array length
{
 tone(buzzer,notes[i]); 
 delay(500); // time
 noTone(buzzer);
 delay(20);// milisecond
 }
 noTone(buzzer); //no sound
}