BITE SIZE ARDUINO – PIEZO BUZZER

Today we will have a look at how to connect a piezo buzzer to an Arduino and how to generate different audio signals with it. A piezo buzzer is a audio signalling device, it is the most basic electronic component by which to generate sounds at different frequencies.

A piezo buzzer has 2 connection terminals, one is connected to GND and the other to a PWM digital pin, for this example we will use pin 3.

piezo_bb

We will use the tone() function to generate tones at different frequencies, for an Arduino Uno the frequency rage is between 31 and 65535 Hz. Please note that the possible min and max frequencies differ between different models of Arduino boards. The tone() function takes 3 parameters, firstly the pin to use, then the frequency to use and lastly the duration to generate the tone in milliseconds.

Here is the code used:

#define PIEZO_PIN 3

void setup()
{
}

void loop()
{
     tone(PIEZO_PIN, 31, 1000);
     delay(500); // Pause between Tones 
     tone(PIEZO_PIN, 15000, 1000);
     delay(500); // Pause between Tones 
     tone(PIEZO_PIN, 30000, 1000);
     delay(500); // Pause between Tones 
     tone(PIEZO_PIN, 45000, 1000);
     delay(500); // Pause between Tones 
     tone(PIEZO_PIN, 65535, 1000);
     delay(500); // Pause between Tones 
     noTone(PIEZO_PIN); // Silence Tones
     delay(500);
}
BITE SIZE ARDUINO – PIEZO BUZZER

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s