The basic buzzer was invented in 1831 by Joseph Henry and was mainly used as a doorbell. Since then, the size has reduced, and many other types have evolved. If you have ever tried punching numbers into a membrane keypad without a buzzer, you will realize how vital this little piece of electro-mechanics has become to us.

Shown in the picture below is a selection of buzzers of different families.

There are two main families: active buzzers and passive buzzers, and each of these can often be made with piezo or electro-magnetic (speaker) technologies.

An active buzzer has a built-in oscillator of some type. In contrast, a passive buzzer has no built-in oscillator and relies on an external AC source to drive it, much like a tiny loudspeaker. It is always best to buffer buzzer with a transistor in a final design, even though it can drive it straight out of the port of an Arduino without buffering. This way, you will often get a louder noise.

Active Buzzers

Active buzzers are the simplest to use. They come in various voltage ratings but have a wide tolerance. They typically come in ranges from 1.5 to 24V. All you have to do is apply a voltage to the pins in the correct polarity, and they beep, buzz, or squeak, depending on how lucky you are.

The polarity follows the same rule as LED’s and capacitors: the longer pin goes to positive. The downside of active buzzers is that the frequency of the beep is fixed and can be annoying.

Passive Buzzers

Passive buzzers need an AC signal to energize them. The great thing about this is that it is fairly easy to generate a wide range of tones on the Arduino with the “tone” command from about 40Hz to 15kHz. Each buzzer has its own “sweet spot” or resonant frequency, and so you can tune the frequency to be resonant at this frequency, making the tone very much louder.

Mine was about 1.7kHz. It is even possible to play melodies (see code further down).

But how do you tell the difference as they look pretty much the same? Apply a DC voltage in the right polarity at about 12V to the buzzer. If it beeps, it is an active buzzer. If it just clicks, it is a passive buzzer.

Dissection

Let’s rip some apart to see what lurks beneath the neat plastic exterior.

Above, we have a passive buzzer. The loudspeaker-type anatomy is evident with the circular magnet, the inner coil, and the vibrating disk with a little ferromagnetic part to work with the electromagnetic coil.

Above, we have an active unit. Note that it is a piezo type. The three fingers make contact with the disk, and a little transistor amplifier is on the printed circuit board.

Here is a marvel of simplicity. Believe it or not, it is an active unit that somehow relied on the tension of the fingers to make and break contact with the disk as it oscillated.

Some Software Examples for the Arduino

First, connect an active buzzer to port 5 and a passive buzzer to port 7.

There are three sections in the main loop. The active buzzer beeps using the digitalWrite command and simple on and off. Then the passive buzzer gets swept through a wide range of frequencies using the tone command. Next, the active buzzer is forced to behave like a passive buzzer by rapidly turning it on and off to simulate a square wave.

Lastly, we use a function to emulate a siren.

/* Program to show various ways of using passive and active buzzers.

*/
const byte passiveBeepPin = 7;
const byte activeBeepPin = 5;
///////////////////////////////////////////////
void setup()
{
pinMode(passiveBeepPin, OUTPUT);
pinMode(activeBeepPin, OUTPUT);
}
////////////////////////////////////////////////
void loop()
{
//-------------------------------
//active buzzer making 5 beeps:
for(int i=0;i<=5;i++)
{
digitalWrite(activeBeepPin, HIGH);
delay(200);
digitalWrite(activeBeepPin, LOW);
delay(200);
}
delay(2000);
//---------------------------
//passive buzzer tone sweep:
//for(int i=40;i<=5000;i++)
for(int i=1000;i<=2000;i=i+10)
{
//Serial.println(i);
tone(passiveBeepPin, i, 0);
delay(10);
}
noTone(passiveBeepPin);
delay(2000); //---------------------------------------
//active buzzer bein made to generate other frequencies like a passive buzzer:
for(int i=1;i<=1000;i++)
{
digitalWrite(activeBeepPin, HIGH);
delayMicroseconds(150);
digitalWrite(activeBeepPin, LOW);
delayMicroseconds(150);
}
for(int i=1;i<=500;i++)
{
digitalWrite(activeBeepPin, HIGH);
delayMicroseconds(200);
digitalWrite(activeBeepPin, LOW);
delayMicroseconds(200);
} for(int i=1;i<=200;i++)
{
digitalWrite(activeBeepPin, HIGH);
delayMicroseconds(500);
digitalWrite(activeBeepPin, LOW);
delayMicroseconds(500); }
delay(2000); siren(20);
delay(2000);
}
//////////////////////////////////////////
void siren(byte loops)
{
for(byte L = 1;L<=loops;L++)
{
for(int i=100;i<=800;i++)
{
tone(passiveBeepPin, i, 0);
} for(int i=800;i>=100;i--)
{
tone(passiveBeepPin, i, 0);
}
}
noTone(passiveBeepPin);
}
///////////////////////////////////////////

Controlling with a Pot and a Button

Connect a pot to A0 and a button to 2.

<!-- wp:paragraph -->
<p>const byte potPin = A0;<br>int potValue = 0;<br>const byte activeBeepPin = 5;<br>const byte passiveBeepPin = 7;<br>const byte pushButton = 2;<br>///////////////////////////////////////////////<br>void setup()<br>{<br>Serial.begin(9600);<br>pinMode(potPin, INPUT);<br>pinMode(passiveBeepPin, OUTPUT);<br>pinMode(activeBeepPin, OUTPUT);<br>pinMode(pushButton, INPUT_PULLUP);<br>}<br>////////////////////////////////////////////////<br>void loop()<br>{<br>potValue = analogRead(potPin);<br>int toneValue = map(potValue,0,1023,500,2000);<br>tone(passiveBeepPin, toneValue );<br>Serial.println(toneValue);</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>byte temp = digitalRead(pushButton);<br>if(temp == LOW)<br>digitalWrite(activeBeepPin, HIGH);<br>else<br>digitalWrite(activeBeepPin, LOW);</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>}<br>////////////////////////////////////////////</p>
<!-- /wp:paragraph -->

Fritzing Diagram

Now, we have seen some active and passive buzzers and some application software. Last but not least, here is something truly amazing—Beethoven’s Fur Elize on the Arduino by Robson Couto:

https://github.com/robsoncouto/arduino-songs/blob/master/furelise/furelise.ino