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.

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

Leave a Reply

%d bloggers like this: