Passive Buzzer

In this lesson, you will learn how to use a passive buzzer.

The purpose of the experiment is to generate eight different sounds, each sound lasting 0.5 seconds: from Alto Do (523Hz), Re (587Hz), Mi (659Hz), Fa (698Hz), So (784Hz), La (880Hz), Si (988Hz) to Treble Do (1047Hz).

Component Required:

1x UNO R3

1 x Passive buzzer

1x F-M wires (Female to Male DuPont wires)

Passive Buzzer:

The working principle of passive buzzer is using PWM generating audio to make the air to vibrate. Appropriately changed as long as the vibration frequency, it can generate different sounds. For example, sending a pulse of 523Hz, it can generate Alto Do, pulse of 587Hz, it can generate midrange Re, pulse of 659Hz, it can produce midrange Mi. By the buzzer, you can play a song.

We should be careful not to use the UNO R3 board analog Write () function to generate a pulse to the buzzer, because the pulse output of analog Write () is fixed (500Hz).

Connection Diagram:

Wiring schematic:

Physical wiring diagram:

Code:

void setup()
{
}
void loop()
{
  for (int i = 200; i <= 800; i++) //Increase the frequency from 200HZ to 800HZ in a loop
  {
    pinMode(8, OUTPUT);
    tone(8, i); //Output frequency on port 8 delay(5);    //This frequency is maintained for 5 milliseconds
  }
  delay(4000);  //Hold for 4 seconds at the highest frequency
  for (int i = 800; i >= 200; i--)
  {
    pinMode(8, OUTPUT); tone(8, i);
    delay(10);
  }
}

You can also download the code below

Last updated