How To Connect A Piezo Emitter (piezo Beeper) To Arduino

Table of contents:

How To Connect A Piezo Emitter (piezo Beeper) To Arduino
How To Connect A Piezo Emitter (piezo Beeper) To Arduino

Video: How To Connect A Piezo Emitter (piezo Beeper) To Arduino

Video: How To Connect A Piezo Emitter (piezo Beeper) To Arduino
Video: How to use Piezo Buzzers | Arduino Tutorials 2024, May
Anonim

You can generate sounds using Arduino in different ways. The simplest of them is to connect a piezo emitter (or a piezo sounder) to the board. But as always, there are some nuances here. In general, let's figure it out.

We connect the piezo emitter to the Arduino
We connect the piezo emitter to the Arduino

Necessary

  • - Computer;
  • - Arduino;
  • - piezo emitter (piezo buzzer).

Instructions

Step 1

A piezo emitter, or piezoelectric emitter, or piezo buzzer is an electro-acoustic sound reproducing device that uses the inverse piezoelectric effect. To explain it in a simple way - under the action of an electric field, a mechanical movement of the membrane arises, which causes the sound waves we hear. Typically, such sound emitters are installed in household electronic equipment as sound alarms, in desktop personal computers, telephones, toys, loudspeakers and much more.

The piezo emitter has 2 leads, and the polarity matters. Therefore, we connect the black pin to ground (GND), and the red one to any digital pin with PWM function (PWM). In this example, the positive terminal of the emitter is connected to terminal "D3".

Connecting the piezo tweeter to the Arduino
Connecting the piezo tweeter to the Arduino

Step 2

The piezo buzzer can be used in a variety of ways. The simplest one is to use analogWrite function. An example of a sketch is shown in the illustration. This sketch alternately turns the sound on and off at a frequency of 1 time per second.

We set the pin number, define it as an output. The analogWrite () function takes as arguments a pin number and a level, which can be from 0 to 255. This value will change the volume of the piezo tweeter within a small range. By sending the value "0" to the port, turn off the piezo sounder.

Unfortunately, you cannot change the key of the sound using analogWrite (). The piezo emitter will always sound at a frequency of approximately 980 Hz, which corresponds to the frequency of the pulse width modulated (PWM) pins on Arduino UNO boards and the like.

Using the built-in function
Using the built-in function

Step 3

Now let's extract the sound from the piezo emitter using the built-in tone () function. An example of a simple sketch is shown in the illustration.

The tone function takes a pin number and an audio frequency as arguments. The lower frequency limit is 31 Hz, the upper limit is limited by the parameters of the piezo emitter and human hearing. To turn off the sound, send the noTone () command to the port.

Please note that if several piezo emitters are connected to the Arduino, only one will work at a time. To turn on the emitter on another pin, you need to interrupt the sound on the current one by calling the noTone () function.

An important point: the tone () function is superimposed on the PWM signal on the "3" and "11" pins of the Arduino. Keep this in mind when designing your devices, because function tone (), called, for example, on pin "5", can interfere with the work of pins "3" and "11".

Recommended: