buzzer and ky-012 buzzer module with Arduino

What are buzzers, different types of buzzers, the working principle of buzzers,s and how to connect buzzers with Arduino are some questions that may arise when working with buzzer modules and Arduino.

Hello guy! Welcome back to my blog today we are going to see about the buzzer and Arduino also with KY 012 buzzer module. so let’s begin.

What is Buzzer in Arduino??

Buzzers are devices that are used to produce sound. this buzzer can be mechanical, magnetic, electromechanical, or piezo-electric. They come in different designs and sizes with different applications. We had heard this sound in toys, video games, alarm clocks, and doorbells also at the alert notifications, timers, etc. buzzer is used for audio communication between users and devices. this communication can indicate the end of the process, the start of the process, notification about the process, error in process or value exceeding or decreasing by the threshold, etc. operating range of such buzzer is between 3v to 20v dc. usually, the buzzer has 2 terminals, the positive terminal is denoted by the (+) symbol on top of the long terminal is represented to be the positive terminal, and the (-) symbol is the short terminal or GND terminal. Today we are going to discuss the piezo-electric buzzer. It’s not like a regular speaker, it changes shape when electricity is applied to it.  

piezo buzzer Arduino

How do Piezo-electric Buzzers work??

piezo buzzer

This buzzer has a piezo-electric element that has a piezo-electric effect which means it produces electricity when force is applied to it when you applied stress, pressure, or press this material to generate electric potential. Similarly, when you applied voltage to this piezo-electric element it deforms back and forth. It creates a vibration that generates sounds. The vibration of an element depends upon the applied voltage, changing the frequency of the voltage applied generates different pitches of sound. The faster the vibration moment of the disc, the higher the pitch of the sound. 

Different Types of Buzzer

1) Active Buzzer
2) Passive Buzzer

piezo speaker Arduino

1) Active Buzzer –

The active buzzer has a built-in oscillator. So we need only DC signal to drive our Buzzer. When we applied the DC signal to the oscillator it will create an AC signal which generates vibration in the piezoelectric element and we heard a tone from the active buzzer. The active buzzer generates a sound itself. To operate the Active buzzer we only need to give the command.

digitalWrite( buzzer pin, HIGH)

That will turn ON the beeping music and stop the buzzer.

digitalWrite(buzzer pin, LOW)

The problem with an Active buzzer is that we cannot generate our desired music tone. Hence it has a built-in oscillator, we cannot adjust the frequency which gives us different tones. For such applications, we have a passive Buzzer.

2) Passive Buzzer –

As in active buzzer. Passive buzzers do not consist of a built-in oscillator. So we can adjust the frequency parameter to obtain different tones, to do this we have one function which is the tone () function. This tone function generates a square wave. We can generate only one tone at a time. We have to use PWM pins with tone function.

This tone function has three parameter

tone(pin, frequency, duration)  

pin –  pin where we have connected buzzer

frequency – the frequency at which we have to produce tone in hertz

duration – it's optional we can set the duration of tone in milliseconds.

We cannot generate tones that are lower than 31Hz

Applications of buzzer

  • Alarm devices
  • Alert Systems
  • Security Systems
  • luggage security system 
  • Timers
  • Electronic devices
  • Games
  • Industrial application
  • Automobiles
  • Printers
  • Computers

How to connect a Piezo-Buzzer with Arduino

piezo buzzer Arduino

How to connect a Piezo-Buzzer Module with Arduino

buzzer module Arduino


Code For Active Buzzer with Arduino


int buzzer_pin = 10;

void setup() 
{
 pinMode(buzzer_pin,OUTPUT);
 Serial.begin(115200);

}

void loop() 
{
 digitalWrite(buzzer_pin,HIGH);
 delay(500);
  digitalWrite(buzzer_pin,LOW);
  delay(500);
}

Code For Passive Buzzer with Arduino

Simple sound :

int buzzer_pin = 10;

void setup() 
{
 pinMode(buzzer_pin,OUTPUT);
 Serial.begin(115200);

}

void loop() 
{
   // tone(pin,frequency,duration);
   tone(buzzer_pin,1000,500);
   
}

Using for loops with buzzer for producing tune music


int buzzer_pin = 10;

void setup() 
{
 pinMode(buzzer_pin,OUTPUT);
 Serial.begin(115200);

}

void loop() 
{
  for(int i=0;i<13000;i++)
  {
    Serial.println(i);
   // tone(pin,frequency,duration);
   tone(buzzer_pin,i,500);
   
  }
}

Conclusion –

Today we learn about IoT buzzers, what is a buzzer, different types of buzzers, electronic buzzer working principles,s and how to use buzzers with Arduino. the buzzer is a small, low-power device that generates sound when voltage is applied to it. we have seen buzzers everywhere in our day-to-day life. the buzzer has wide applications in fields of medical, electronics devices, security devices, and other industrial applications.

"I hope you find this IoT blog very helpful to you. In the upcoming lesson, we will see more about IoT sensors till then bye. See you all in my next blog."

Close Menu