Electronics

Buzzer Active Module

AED 9.45

1

Description

1 module driven by S8550 triode
2 working voltage of 3.3 V to 5 V
3 sets of fixed bolt hole, convenient installation
4 small board PCB size: 3.3 cm X 1.3 cm


Three shipping list
1 X  Active buzzer module


How to use a buzzer/piezo speaker with Arduino

 

Hello everyone, in this tutorial we’ll use buzzer or piezo-speaker with its two version (3 pins module) and 2 pins version, It’s very simple to use, the buzzer convert an electrical signal to a sound by making vibration movements, it depends on the signal frequency we get a proportionnal sound. It’s a handy module for security systems and simple to wire or use.

Wirings:

Here are the wirings of different types and they works with the same codes

 Codes:

Here Are two version of codes:

-.Ino Codes: Download here

-Text codes:

Code 1:

//This code is to use with a buzzer if you're using the module with 3 pins wire the I/O with D8
//If you're using the other version wire the (+) pin with 8 // Refer to SurtrTech.com for more information
//Emitting 1KHz sound for 1s and then 2KHz sound for 1s

int buzzer = 8;
 
void setup() {
 
}
 
void loop() {

tone(buzzer, 1000); // tone() is the main function to use with a buzzer, it takes 2 or 3 parameteres (buzzer pin, sound frequency, duration)
 delay(1000);
 tone(buzzer, 2000); // You can also use noTone() to stop the sound it takes 1 parametere which is the buzzer pin
 delay(1000);
 
}

Code 2:

//This code is to use with a buzzer if you're using the module with 3 pins wire the I/O with D8
//If you're using the other version wire the (+) pin with 8 // Refer to SurtrTech.com for more information
//Increasing sound freqency from 100Hz to 2KHz then decreasing frequency from 2KHz to 100Hz

int buzzer = 8;
 
void setup() {
 
}
 
void loop() {
for(int i=100 ; i<2000 ; i++){ // loop for to increase the sound frequency
 tone(buzzer, i);
 delay(10); //You can change the delay if you want to make it longer or shorter
}
for(int i=2000 ; i>100 ; i--){
 tone(buzzer, i);
 delay(10);
} 
}

 

Code 3: Star Wars theme (I took it from here   https://gist.github.com/nicksort/4736535 )

 
const int c = 261;
const int d = 294;
const int e = 329;
const int f = 349;
const int g = 391;
const int gS = 415;
const int a = 440;
const int aS = 455;
const int b = 466;
const int ch = 523;
const int cSH = 554;
const int dH = 587;
const int dSH = 622;
const int eH = 659;
const int fH = 698;
const int fSH = 740;
const int gH = 784;
const int gSH = 830;
const int aH = 880;
 
const int buzzerPin = 8;
const int ledPin1 = 12;
const int ledPin2 = 13;
 
int counter = 0;
 
void setup()
{
 //Setup pin modes
 pinMode(buzzerPin, OUTPUT);
 pinMode(ledPin1, OUTPUT);
 pinMode(ledPin2, OUTPUT);
}
 
void loop()
{
 
 //Play first section
 firstSection();
 
 //Play second section
 secondSection();
 
 //Variant 1
 beep(f, 250); 
 beep(gS, 500); 
 beep(f, 350); 
 beep(a, 125);
 beep(ch, 500);
 beep(a, 375); 
 beep(ch, 125);
 beep(eH, 650);
 
 delay(500);
 
 //Repeat second section
 secondSection();
 
 //Variant 2
 beep(f, 250); 
 beep(gS, 500); 
 beep(f, 375); 
 beep(ch, 125);
 beep(a, 500); 
 beep(f, 375); 
 beep(ch, 125);
 beep(a, 650); 
 
 delay(650);
}
 
void beep(int note, int duration)
{
 //Play tone on buzzerPin
 tone(buzzerPin, note, duration);
 
 //Play different LED depending on value of 'counter'
 if(counter % 2 == 0)
 {
 digitalWrite(ledPin1, HIGH);
 delay(duration);
 digitalWrite(ledPin1, LOW);
 }else
 {
 digitalWrite(ledPin2, HIGH);
 delay(duration);
 digitalWrite(ledPin2, LOW);
 }
 
 //Stop tone on buzzerPin
 noTone(buzzerPin);
 
 delay(50);
 
 //Increment counter
 counter++;
}
 
void firstSection()
{
 beep(a, 500);
 beep(a, 500); 
 beep(a, 500);
 beep(f, 350);
 beep(ch, 150); 
 beep(a, 500);
 beep(f, 350);
 beep(ch, 150);
 beep(a, 650);
 
 delay(500);
 
 beep(eH, 500);
 beep(eH, 500);
 beep(eH, 500); 
 beep(fH, 350);
 beep(ch, 150);
 beep(gS, 500);
 beep(f, 350);
 beep(ch, 150);
 beep(a, 650);
 
 delay(500);
}
 
void secondSection()
{
 beep(aH, 500);
 beep(a, 300);
 beep(a, 150);
 beep(aH, 500);
 beep(gSH, 325);
 beep(gH, 175);
 beep(fSH, 125);
 beep(fH, 125); 
 beep(fSH, 250);
 
 delay(325);
 
 beep(aS, 250);
 beep(dSH, 500);
 beep(dH, 325); 
 beep(cSH, 175); 
 beep(ch, 125); 
 beep(b, 125); 
 beep(ch, 250); 
 
 delay(350);
}