Buzzer Interfacing with Arduino 

What is a Buzzer?

A Buzzer is an electronic signaling device that produces sound when powered. In Arduino applications, a buzzer is used to generate audio alerts, tones, or beeps in response to certain events. 

Buzzer Features and Specifications

1. Rated voltage: 6V DC.

2. Operating voltage: 4- 9V DC.

3. Current: <30mA.

4. Sound Type: Continuous Beep.

5. Frequency: ~2300 Hz.

Function of Buzzer Interfacing

1. tone( ):- It is used to send a frequency of a sound signal to the pin on which the buzzer is connected.

Syntax:- tone(pin,Frequency);

Parameters:-

pin:- To which the Buzzer is connected on the Arduino Board.

Frequency:- The frequency in Hertz.

2. noTone( ):- It is used to stop the sound signal to the pin on which the buzzer is connected.

Syntax:- noTone(pin);

Parameters:-

pin:- To which the Buzzer is connected on the Arduino Board.


Task 1: To turn on the buzzer with a 1 and 5-second time gap.

 Code:-


int buzz=12;
int a;
void setup()
{
  pinMode(buzz, OUTPUT);
}
void loop()
{
  tone(buzz,400); 
  delay(1000);
  noTone(buzz); 
  delay(1000);
  tone(buzz,500);
  delay(5000);
  noTone(buzz);
  delay(5000);
}


 Output:-


Task 2: Play different frequencies on buzzer using three  switches.

int buzz=13;
int sw1= 12 ,sw2=11,sw3=10;
void setup ()
{
  pinMode(buzz,OUTPUT);
  pinMode(sw1,INPUT);
  pinMode(sw2,INPUT);
  pinMode(sw3,INPUT);
}
void loop ()
{
  if (digitalRead(sw1)==LOW)
  {
    noTone(buzz);
    tone(buzz,500);
  }
   else if (digitalRead(sw2)==LOW)
  {
    noTone(buzz);
    tone(buzz,1000);
  }
    else if (digitalRead(sw3)==LOW)
  {
    noTone(buzz);
    tone(buzz,1500);
  }
}

 Output:-



Task 3: Turn on buzzer using one switch and turn it off using other switch.

int buzz=13;
int sw1= 12 ,sw2=11;
void setup ()
{
  pinMode(buzz,OUTPUT);
  pinMode(sw1,INPUT);
  pinMode(sw2,INPUT);
}
void loop ()
{
  if (digitalRead(sw1)==LOW )
  {
    tone(buzz,500);
  }
   else if (digitalRead(sw2)==LOW)
  {
    noTone(buzz);
  }
 
}

Output:-