# Lesson 17--Microduino "Buzzer alarm"

 Language: English  • 中文

## Objective

We have used the buzzer in the light alarm experiment. This lesson will give a detailed instruction for the buzzer and use it simulate the air defense warning.

## Buzzer

Buzzer is an integration of electron acoustic structure, divided into two types, piezoelectric buzzer and magnetic buzzer.

### Piezoelectric buzzer

Piezoelectric buzzer is mainly composed by the multivibrator, piezoelectric, impedance matching unit and sound box, shell and so on. As shown in figure

### Magnetic buzzer

Magnetic buzzer is composed by the oscillator, the electromagnetic coil, magnets, vibration membrane and shell.

### Active buzzer and passive buzzer

• Active buzzer: connected to the rated power supply directly that make a sound continuously.
• Passive buzzer: like an electromagnetic speaker, need connect to the audio output circuit.

### Difference

• From appearance, the two kinds of buzzer as the same, but look closely, the height has a little difference, active buzzer height is 9 mm, and the height of the passive buzzer is 8 mm.
• When two pins are facing up to place the buzzer， it can be seen with a green circuit board is a kind of passive buzzer, no circuit board with black rubber seal is a kind of active buzzer.

## Experimental schematic

Note：In this experiment must use passive buzzer

## Program

```void setup()
{
pinMode(3,OUTPUT);
}

void loop()
{
for(int i=200;i<=800;i++)  //Dynamic to set the frequence from 200HZ to 800HZ in a cycle
{
tone(3,i);    //Output the frequence in port 4
delay(5);      //Keep this frequence 5ms
}
delay(4000);     //Keep 4mins in the Highest frequence
for(int i=800;i>=200;i--)
{
tone(3,i);
delay(10); //Keep this frequence 10ms
}
}```

## Result

After download, you can hear the alarm. Maybe you have found that buzzer with the polarity, actually passive buzzer is nonpolar, and active buzzer is polarity, but for the production cost savings and unified adopted active buzzer encapsulation, so we have the same results for both pin connection.