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.


<p>If you have a unit that need digital input to work (as my YL-44). You could try this code for some fun:</p><p>/* Buzzer type YL-44 with VCC, GND and I/O pin<br> * YL-44 will have sound ON when I/O is LOW<br> * Written by Kjartan, LA6SRA, 2015<br> */<br><br>int buzzPin= 12; // I/O-pin from buzzer connects here <br>const int wpm = 20; // Morse speed in WPM<br>const int dotL = 1200/wpm; // Calculated dot-length<br>const int dashL = 3*dotL; // Dash = 3 x dot<br>const int sPause = dotL; // Symbol pause = 1 dot<br>const int lPause = dashL; // Letter pause = 3 dots<br>const int wPause = 7*dotL; // Word pause = 7 dots<br><br>void setup()<br>{<br> pinMode(buzzPin,OUTPUT); // Set buzzer-pin as output<br>}<br>void loop()<br>{<br> dash();<br> dot();<br> dash();<br> dot();<br> delay(lPause-sPause); // Subtracts pause already taken</p><p>dash();<br> dash();<br> dot();<br> dash();<br> delay(wPause-sPause); // Subtracts pause already taken<br> <br>}<br><br>void dot(){<br> digitalWrite(buzzPin, LOW); // Tone ON<br> delay(dotL); // Tone length<br> digitalWrite(buzzPin, HIGH); // Tone OFF<br> delay(sPause); // Symbol pause<br> return;<br>}<br><br>void dash(){<br> digitalWrite(buzzPin, LOW); // Tone ON<br> delay(dashL); // Tone length<br> digitalWrite(buzzPin, HIGH); // Tone OFF<br> delay(sPause); // Symbol pause<br> return;<br>}</p>
<p>Thank you so much! Had really bad problems with constant buzzing until found your code. Now my buzzer starts to morse &quot;Fridge Open&quot; if someone leaves the door open :p.</p>
<p>I did the same configuration.</p><p>Get a very loud noise and a beep at the frequence you indicate.</p><p>Do you know why I am getting the noise ?</p>
<p>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. </p><p>There may be different types of the unit out there. At least this tutorial would indicate that. </p>
<p>+1</p><p>My 3 PIN buzzer does not work in PWM mode, works only as KjartanA says.</p>

About This Instructable




Bio: Hello, My name is Samuel, I am a student. I love micro controllers like arduino, they are my favorite interest. I also do geocaching, a ... More »
More by samuel123abc:Real time clock using DS3231 (EASY) Controlling 120-240 VAC with a relay using arduino Nokia 5110 graphics tutorial 
Add instructable to: