Introduction: Arduino YL-44 Buzzer Module
Welcome to this tutorial!
So about a time ago I sat and looked around at my favorite site for ordering all kinds of arduino sensors, boards and much more. You might already have guessed it, but I am of course speaking about www.aliexpress.com. I just was looking and an actuator got my eyes. It was a buzzer module which was great for a future project. You can for example make it buzz every time you start your program. Although once I got it home, I was not really prepared for how to deal with this new unit. This might sound kind of stupid, but I am just a newbie to arduino. Got my genuine ardunio UNO for about a month or two ago, so bare with me.
After searching google, contacting seller and searched on google again, I did not find a solution. Then finally the seller provided me with what I needed, a square wave.
Now, I am going to show you how to connect this module and speak with it, sorry, make it understand my crappy code.
Step 1: Parts
Start by getting the required parts:
YL-44 buzzer (1$)
Any arduino board really (3-15$ depending on which one you get)
A couple of jumper wires (2-3$)
Step 2: Connections
Notice that I am using the arduino MEGA, but you can use any board you would like, for example, this code works on both the UNO and the Nano.
Your connections should be like the pictures and as following:
VCC -> Arduino 5V
I/O -> Any arduino PWM pin (I used 3)
GND -> Arduino GND
Step 3: Your Code
Now your code is easy as ABC, although we will create our own fast function to interact more easily.
This code worked great for me without any errors, enjoy!
Refer to Comments for explanation
//Code written by Samuel.
int buzzerPin = 3; //Define buzzerPin
void setup() { pinMode(buzzerPin, OUTPUT); //Set buzzerPin as output beep(50); //Beep beep(50); //Beep delay(1000); //Add a little delay
}
void loop() { beep(50); //Beep every 500 milliseconds delay(500); }
void beep(unsigned char delayms) { //creating function analogWrite(buzzerPin, 20); //Setting pin to high delay(delayms); //Delaying analogWrite(buzzerPin ,0); //Setting pin to LOW delay(delayms); //Delaying }
Step 4: Finished
Now I hope this helped you, and that your YL-44 is working now. Thanks for reading and as always, please favorite and subscribe for more tutorials.
Samuel
13 Comments
7 years ago
If you have a unit that need digital input to work (as my YL-44). You could try this code for some fun:
/* Buzzer type YL-44 with VCC, GND and I/O pin
* YL-44 will have sound ON when I/O is LOW
* Written by Kjartan, LA6SRA, 2015
*/
int buzzPin= 12; // I/O-pin from buzzer connects here
const int wpm = 20; // Morse speed in WPM
const int dotL = 1200/wpm; // Calculated dot-length
const int dashL = 3*dotL; // Dash = 3 x dot
const int sPause = dotL; // Symbol pause = 1 dot
const int lPause = dashL; // Letter pause = 3 dots
const int wPause = 7*dotL; // Word pause = 7 dots
void setup()
{
pinMode(buzzPin,OUTPUT); // Set buzzer-pin as output
}
void loop()
{
dash();
dot();
dash();
dot();
delay(lPause-sPause); // Subtracts pause already taken
dash();
dash();
dot();
dash();
delay(wPause-sPause); // Subtracts pause already taken
}
void dot(){
digitalWrite(buzzPin, LOW); // Tone ON
delay(dotL); // Tone length
digitalWrite(buzzPin, HIGH); // Tone OFF
delay(sPause); // Symbol pause
return;
}
void dash(){
digitalWrite(buzzPin, LOW); // Tone ON
delay(dashL); // Tone length
digitalWrite(buzzPin, HIGH); // Tone OFF
delay(sPause); // Symbol pause
return;
}
Reply 2 years ago
Bonjour j'ai essayé avec ce code ms tjr ça marche pas dans la compilation sur l'arduino, je ne sais pas prq
Reply 6 years ago
Thank you so much! Had really bad problems with constant buzzing until found your code. Now my buzzer starts to morse "Fridge Open" if someone leaves the door open :p.
Reply 4 years ago
I tried it, but it doesnt make any sound :( , I have same problem with constant buzzing, code I copy/paste from KjartanA's comment and connected like this:
Reply 4 years ago
And Im using Wemos D1, does anybody know what Im doing wrong? :(
Reply 4 years ago
Well I made mistake with wrong pinMode, but it still constantly buzzing WHY? :(
3 years ago
Thankyou so much Samuel. After 1 hour of trials I got it correct. :)
4 years ago
My Friends !! We leave the YL-44 Buzzer in HIGH mode and not LOW, and it does not bother or get warm.
digitalWrite (buzzPin, HIGH);
5 years ago
please read this problem.
module get warm and too many noises are sense able even after analogWrite(..., 0)
https://forum.arduino.cc/index.php?topic=516567.0
5 years ago
I'm looking for a buzzer than can be turned on when the control signal is high...
On ebay I found a buzzer that says 'High Level Trigger for Arduino', I assume this to mean when the control signal is HIGH, the buzzer will sound, right?
However, if it has a pnp (2TY) transistor shouldn't the base control signal be LOW for the buzzer to sound? Only if it had an npn (ex. 2N2222) transistor THEN the base control signal is HIGH for the buzzer to sound.
Also is it possible for the VCC and the control signal to be 12V instead of 5V? Or would the buzzer and/or limiting current resistor have to change?
7 years ago on Introduction
I did the same configuration.
Get a very loud noise and a beep at the frequence you indicate.
Do you know why I am getting the noise ?
Reply 7 years ago
YL-44 is not intended to be used with a PWM-pin. Instead you set the I/O-pin LOW to get the buzzer going. And HIGH to make it stop buzzing. If you use PWM there will be a constant buzzing from the unit and just small changes when the PWM changes.
There may be different types of the unit out there. At least this tutorial would indicate that.
Reply 6 years ago
+1
My 3 PIN buzzer does not work in PWM mode, works only as KjartanA says.