Passive Buzzer for Arduino (Keyes KY006)

passive buzzer

Unlike the Active Buzzer, which generates a fixed tone when the power is connected, the passive needs a generated tone, as a loudspeaker does, to make it operate. This buzzer is almost identical in appearance to the Active Buzzer YL-44.

Either PWM or simply switching a digital pin on then off,  the frequency being determined by the length of the delay between switching on and off.

The second method is used here to generate a two tone signal.

/********************************************************
Example Code for KY-006, Two Tone.
Connections::

  Gnd to Arduino Gnd

  Vcc to Arduino 5 volts

  I/O to Arduino pin 6
********************************************************/ 

int out =2;

void setup ()
{
  pinMode(out, OUTPUT);
}

void loop ()
{
  unsigned char i, j ;
  while (1){
    for (i = 0; i <80; i++){ // number of cycles to sound
      digitalWrite (out, HIGH); // turn buzzer ON
      delay (1) ;// Delay 1ms set frequency 1
      digitalWrite (out, LOW); // turn buzzer OFF
      delay (1) ;// delay ms
    }
    for (i = 0; i <100; i++){ // number of cycles to sound
      digitalWrite (out, HIGH); // turn buzzer ON
      delay (2) ;// delay 2ms set frequency 2
      digitalWrite (out, LOW); // turn buzzer OFF
      delay (2) ;// delay 2ms
    }
  }
}

Advertisements

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