Skip to content

How to use a buzzer/piezo speaker with Arduino



Hello there, in this tutorial we’ll use a buzzer or piezo-speaker with its two versions (3 pins module and 2 pins component), 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 proportional sound. It’s a handy module for security systems or used as an alarm for many sensors.

Both buzzers I used are passive buzzers, passive means they require an external AC signal to be able to produce a sound, for our example we gonna use the Arduino “Tone” function to generate an adequate signal, for the active ones all they need is a DC signal… the passive is the most usual, that’s why I used it.

Module version
component version



Wirings:

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

3
Wiring 1 with the buzzer component
2
Wiring 2 with the buzzer module

Codes:

There are few important functions to be able to use the buzzer which are:

“tone” function can have two versions: one with only the pin and its frequency, then the other where you add also the duration.

to shut the buzzer you must use the function below, otherwise it will keep going.

 

Ino Codes: Download here or:

Code 1: Simple buzzing sound with a tone change



Code 2: Gradually sweeping between a frequency range

 

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

Yassine View All

Automation and Electrical Engineer, Electronics amateur trying to share my little projects.

7 thoughts on “How to use a buzzer/piezo speaker with Arduino Leave a comment

  1. Thanks for the Star Wars Arduino code. Another site also had one, but I couldn’t get it to work, but yours worked right off the bat.

Leave a Reply

Discover more from SURTR TECHNOLOGY

Subscribe now to keep reading and get access to the full archive.

Continue reading