How to Use a Buzzer (or Piezo Speaker) - Arduino Tutorial

453,743

53

21

Introduction: How to Use a Buzzer (or Piezo Speaker) - Arduino Tutorial

About: Arduino Tutorials by Codebender.cc Team

In this tutorial you will learn how to use a buzzer or piezo speaker with Arduino. Buzzers can be found in alarm devices, computers, timers and confirmation of user input such as a mouse click or keystroke.

You will also learn how to use tone() and noTone() function.

So, let's get started!

Step 1: What You Will Need

For this tutorial you will need:

  • Arduino uno
  • Breadboard
  • Buzzer / piezo speaker
  • 100 Ohm resistor (optional)

Step 2: The Circuit

The connections are pretty easy, see the image above with breadboard circuit schematic.

Step 3: The Code

Here's the "Tone" code, embedded using codebender!

How it works? It's simple, tone(buzzer, 1000) sends a 1KHz sound signal to pin 9, delay(1000) pause the program for one second and noTone(buzzer) stops the signal sound. The loop() routine will make this run again and again making a short beeping sound.

(you can also use tone(pin, frequency, duration) function)

Try downloading the codebender plugin and clicking on the Run on Arduino button to program your Arduino with this sketch. And that's it, you've programmed your Arduino board!

You can keep playing with that by clicking the "Edit" button and start making your own modifications to the code.

For example, try to change sound signal "1000" (1KHz) to "500" (500Hz) or delay time and see how it changes the program.

Step 4: Well Done!

You have successfully completed one more Arduino "How to" tutorial and you learned how to use:

  • buzzer / piezo speaker
  • tone(), noTone() functions

I hope you liked this, let me know in the comments.

There will be more of them, so make sure to click Follow button!

1 Person Made This Project!

Recommendations

  • Microcontroller Contest

    Microcontroller Contest
  • Automation Contest

    Automation Contest
  • Make it Glow Contest

    Make it Glow Contest

21 Comments

1
Jendrej
Jendrej

1 year ago on Step 2

The 5V output from Arduino isn’t connected to anything on the breadboard in this scheme…

0
RandyF55
RandyF55

2 years ago

Just what I needed. Thanks!

0
MashamiP
MashamiP

2 years ago

nice thank you so much I need more for buzzer

0
JoshuaD178
JoshuaD178

3 years ago

just use the 100ohms resistor, the noise pitch increases and its annoying

0
lordduplo
lordduplo

3 years ago

Can someone help me, i wanne use millis() instead of delay

0
shiivam777kumar
shiivam777kumar

3 years ago

Can I increase/Decrease the volume without touching the resistor? That is by modifying the code?

0
Codingpro
Codingpro

Reply 3 years ago

No need to use a resistor, just use a knob. Middle to 5v, one side to the piezo, none to the other

0
AmiR18
AmiR18

4 years ago

Is it very harmful if I don't use the resistor ?

0
Codingpro
Codingpro

Reply 3 years ago

It depends on your piezo. if it is b1g, it shouldn't need it. that is why they said optional.

0
vaibhav30111
vaibhav30111

3 years ago

is there a difference between a buzzer and a piezo sounder?

0
yachtSamba.
yachtSamba.

4 years ago

I have two buzzers, one active and one passsive, and i don't know which is which. i plugged them both in one after another, and the first one made a muffled sound till i unplugged the 5V. The other one makes a long, high pitched noise without the one second pauses, but makes a very quiet, but with one-second intervals noise when i unplug the 5V. Cansomeone please tell me which is which?

0
surendharS6
surendharS6

Reply 3 years ago

I'd use active piezo buzzer

0
Ingliba Istorla Sinkaberalsd
Ingliba Istorla Sinkaberalsd

Reply 3 years ago

Um, you're just a juiceical so therefore you cannot use a {potato} for brekfest! OKAY! so I am just tired of it! because I was a caattile

0
PratikP76
PratikP76

4 years ago

can you suggest me which piezo speaker i should buy? i mean specific component

0
CleteK
CleteK

4 years ago

How do I make it louder?

0
VarunD15
VarunD15

Reply 4 years ago

Reduce the resistance..better just take it off.....