What is a buzzer and how does it work. What is a buzzer and how it works Personal experience of use

The word "buzzer" comes from the German "summen" - to buzz. In fact, it is a sound-emitting device traditionally used as a signaling device. Today, buzzers are electromechanical and piezoelectric. Both are used in different devices.

Historically, the first appeared electromechanical buzzer, which is an electromechanical relay with normally closed contacts, through which the coil of this relay is connected to a current source.

The principle of operation of the buzzer is very simple. When a current flows in the operating circuit of the buzzer, the relay winding is excited, which means that the magnetic flux in its core increases, under the influence of which the contacts immediately open through which the winding itself was just powered.

When the contacts are opened, the relay winding stops receiving power, the magnetic flux in the core disappears, which means that the moving contact that just closed the relay power circuit is released, and the spring transfers the circuit to the initially closed state.

And now, the contacts are closed again, the coil receives power again and the core again attracts the movable contact of the relay, again opening its own supply circuit. So the process is repeated over and over. The oscillation of the relay armature produces a buzzing sound. The Rumkorf coil works in a similar way.

Of course, a buzzer based on a relay in the course of its operation not only generates strong impulse noise in the power supply circuit, but also emits strong interference into the radio air, therefore, buzzers are used, among other things, for testing various equipment for noise immunity.

The main disadvantage of the electromechanical buzzer is obvious: the presence of a moving element wears out the mechanism, and the spring weakens over time, and therefore the buzzer's operating time between failures is no more than 5000 hours.

However, noteworthy is the first use of the buzzer invented by Johann Wagner in 1839 and later modified by John Mirand, who added a bell to the vibrating hammer. The result is an electric bell, which produces a sound by striking the bell with a hammer. The bell hammer was connected to the relay armature, which directly worked in the buzzer mode.

The first electric doorbells installed in all apartments were similar in structure (see -). Fire alarm bells have a similar design as the first bells that hung at railway stations.

A more modern version of the buzzer is a piezoelectric acoustic emitter, which is an electroacoustic device, and produces audible sound or ultrasound using the inverse piezoelectric effect.

The piezoelectric is applied here on a thin metal plate. On the reverse side of the piezoelectric layer there is a conductive deposition. The sputtering and the plate itself serve as contacts to which power is supplied. To amplify the amplitude of the propagating sound vibrations, a small horn with a hole can be attached to the plate.

The piezoelectric buzzer is powered by alternating current at a voltage of 3 to 10 volts, and the frequency of the current determines the frequency of the sound. The characteristic resonant frequency of piezoelectric sound emitters lies in the range from 1 to 4 kHz, which leads to an easily recognizable buzz with a sound pressure reaching 75 dB at a distance of 1 meter from the emitter. These buzzers are capable of working as microphones or sensors.

Piezoelectric buzzers are used in alarm clocks, toys, household appliances, telephones. The ultrasound obtained with their help is often used in rodent repellents, in air humidifiers, in ultrasonic cleaning, etc.

It will be quite easier to use the device if we implement soundtrack and connect a buzzer to our board. We have slightly changed the arrangement of the elements, so we will update several #define directives, and specifically connect the buzzer to the arduino PWM output. (Full code, as usual at the end of the article)

#define buzzer 11 // Speaker contact

As a result, the buzzer connection diagram will look like this

Why did we choose PWM output? If you apply 5v to the speaker, it will beep once and that's it, or rather it won't even be heard practically. The sound is an analog signal, and the PWM output, without unnecessary headaches, will be able to simulate a stream of pulses


To activate the PWM signal, we can use the analogWrite (output, value) command; , where there are only two arguments - the first is the output number, and the second is a value from 0 to 255, which affects the degree of duty cycle in the PWM signal. I experimented and found the optimal duty cycle of 20 for a normal speaker tone. Accordingly, the duty cycle is 0 - turn off the sound completely.

AnalogWrite (buzzer, 20); // Turn on the sound on the PWM output analogWrite (buzzer, 0); // Turn off the sound on the PWM output

It must be remembered that we should not use delay when creating sound effects, so we will again be bound to the millis () controller time variable.


Let's try to depict the code in a diagram. By pressing a button, we will activate the speaker - and then, under certain conditions, turn it off, or do cycles.

We will introduce an error flag that we will apply when the reset button is pressed, the password is entered incorrectly and a simple 3 seconds when the user suddenly stopped entering the password

Bool keyError; // Password error flag

We will also introduce a variable that we will compare with the controller time millis ().

Uint32_t beep; // Variable delay buzzer after pressing a button or action

In the loop () we will constantly check all our functions.

Key_beep_off (); // Mute the buzzer key_beep_ok (); // Buzzer sound when the lock is opened key_beep_error (); // Buzzer error sound

In a key loop key_scan (), if the press was recorded, then we will start the sound signal and reset the time variable.

Beep \u003d millis (); // Set the buzzer time variable to the controller time analogWrite (buzzer, 20);

If it's just a pressed key, with no action, then we need a very short sound. How do we know if a click did not take an action? We will check the status of the closed lock, and the time variable within 150ms. If the status of the lock is closed, then after 150ms, turn off the sound. So we get a short sound when any button is pressed.

Void key_beep_off () // Turn off the buzzer if the lock remains closed after 150ms (if (millis () - beep\u003e 150 && lockType \u003d\u003d 1 && digitalRead (lock) \u003d\u003d LOW || millis () - beep\u003e 200 && lockType \u003d\u003d 0 && digitalRead (lock) \u003d\u003d HIGH) (analogWrite (buzzer, 0); // Turn off the sound on the PWM output))

Now the sound of an error. I suggest making two short signals for understanding, usually this sound is understandable to the user. Everything is very simple here. We need to use the error flag keyError... While its value is 1, we will fulfill the conditions with a time interval of 150ms, and at the end we will simply reset it. We just do 3 ifs, in each of which we bind to the time. 1) Turn on the speaker -\u003e 2) turn it off -\u003e 3) turn it on. Then we remove the flag keyError \u003d\u003d 0.

Void key_beep_error () // Keyboard error function - double beep (if (keyError \u003d\u003d 1) (if (millis () - beep\u003e 0 && millis () - beep< 150) // Интервал времени от 0 до 150мс - звук есть { analogWrite(buzzer, 20); // Включаем звук на ШИМ выходе } if (millis() - beep > 150 && millis () - beep< 300) // Интервал времени от 150 до 3000мс - звука нет { analogWrite(buzzer, 0); // Выключаем звук на ШИМ выходе } if (millis() - beep > 300 && millis () - beep< 450) // Интервал времени от 300 до 450мс - звук есть { analogWrite(buzzer, 20); // Включаем звук на ШИМ выходе } if (millis() - beep > 450) // After 450ms (analogWrite (buzzer, 0); // Turn off the sound on the PWM output keyError \u003d 0; // Reset the open error flag)))

Then we need to raise the flag in some parts of the code keyError \u003d\u003d 1 and reset the beep variable. We need to insert this code into the processing of the # key, it should also be executed if the password is entered incorrectly, and it should be reset if it is idle for 3 seconds.

Beep \u003d millis (); // Set the buzzer time variable to the controller time keyError \u003d 1; // Activate the buzzer error flag

Now let's analyze the sound of the speaker when the lock is opened. In order for the user to understand that the lock is still open (this is especially important in the case of a magnetic lock), we will play short beeps. The beep loop should continue while the lock is open, for this we had the openTime variable. Those. we can read the state of the lock, and beep while beep< openTime. Далее мы организуем цикл включения и выключения динамика, по схожему принципу, как в коде ошибки, но он у нас будет повторять, пока открыт замок. Чтобы цикл повторно запустился, в конце нам нужно обновить переменную beep.

Void key_beep_ok () (if (millis () - beep< openTime && lockType == 1 && digitalRead(lock) == HIGH || millis() - beep < openTime && lockType == 0 && digitalRead(lock) == LOW) { if (millis() - beep > 0 && millis () - beep< 120) // Задаём время от 0 до 120мс - зуммер активен { analogWrite(buzzer, 30); // Включаем звук на ШИМ выходе } if (millis() - beep > 120 && millis () - beep< 300) // Задаём время от 120 до 300 мс - зуммер не активен { analogWrite(buzzer, 0); // Выключаем звук на ШИМ выходе } if (millis() - beep > 300) // Above 300ms, set the buzzer time variable to zero so that the cycle starts again while the lock opening time is in effect (beep \u003d millis (); // Set the buzzer time variable to the controller time)))

We have already gone through enough series of articles on building our access system, so we will assemble everything in hardware and test how our code works


I recorded a short video where we will check the main functions of our device.

The Arduino buzzer, which is often called a buzzer, piezo speaker or even a buzzer, is a frequent visitor to DIY projects. This simple electronic component connects easily enough to Arduino boards, so you can quickly get your circuit to make the sounds you want - beep, beep, or play a melody pretty well. In this article, we will tell you about the difference between active and passive buzzers, analyze the diagram for connecting a piezoelectric element to the Arduino board and show an example of a sketch for controlling a buzzer. You will also find an example of a melody that you can add to your project.

Buzzer, piezo beeper - these are all names of one device. These modules are used for sound notification in those devices and systems, for the functioning of which a sound signal is required. Buzzers are widespread in various household appliances and toys using electronic boards. Piezo beepers convert commands based on the two-bit number system 1 and 0 into audio signals.

Piezoelement "squeaker"

The piezo buzzer is structurally represented by a metal plate coated with conductive ceramic sputtering. The plate and the coating act as contacts. The device is polarized, has its own "+" and "-". The principle of the buzzer is based on the piezoelectric effect discovered by the Curie brothers at the end of the nineteenth century. According to him, when electricity is supplied to the buzzer, it begins to deform. In this case, strikes against a metal plate occur, which produces “noise” of the desired frequency.


It should also be remembered that there are two types of buzzer: active and passive. The principle of operation is the same for them, but in the active one there is no possibility to change the sound frequency, although the sound itself is louder and the connection is easier. More on this below.


Arduino buzzer module

Structurally, the module is executed in a variety of versions. The most recommended for connecting to arduino is a ready-made module with built-in harness. Such modules can be easily purchased from online stores.

Compared with ordinary electromagnetic sound transducers, the piezo buzzer has a simpler design, which makes its use economically feasible. The frequency of the received sound is set by the user in the software (an example of a sketch is presented below).

Where to buy an Arduino squeaker

Our Traditional Review of Deals on Aliexpress

Loud piezo speaker - 3-24 Volt buzzer, suitable for Arduino The simplest passive piezo emitters 12MM * 8.5MM 3-12V, set of 5 pieces
Piezodynamics module with the necessary harness for working with Arduino Tweeters with connectors for connecting to the computer motherboard A set of 10 active speakers - piezo buzzers

Differences between active and passive buzzer

The main difference between active and passive buzzer is that the active buzzer generates sound on its own. To do this, the user just needs to turn it on or off, in other words, by applying voltage to the contacts or de-energizing. A passive buzzer requires a signal source to set the parameters of the sound signal. The Arduino board can act as such a source. An active buzzer will beep louder than its competitor. The frequency of the emitted sound of an active buzzer is 2.5 kHz +/- 300 Hz. The supply voltage for the buzzer varies from 3.5 to 5 V.

An active piezoelectric emitter is also preferable due to the fact that in the sketch you will not need to create an additional piece of code with a delay that affects the workflow. Also, to determine which element is in front of the user, you can measure the resistance between the two wires. Higher values \u200b\u200bwill indicate an active arduino buzzer.

In their geometric shape, the tweeters do not differ in any way, and it is not possible to attribute the element to one type or another according to this characteristic. The buzzer can be visually identified as active if a resistor and amplifier are present on the board. The passive buzzer has only a small piezoelectric element on the board.

Buzzer connections to Arduino

Connecting the piezoelectric module to the Arduino looks quite simple. The current consumption is small, so you can simply connect directly to the desired pin.


Connecting the buzzer to Arduino (port 12)

The electrical diagram for connecting a piezoelectric element without accompanying modules is as follows.

On some buzzer housings, you can find a hole for fixing the board with a screw.

The arduino buzzer has two outputs. Pay attention to their polarity. The dark wire should be connected to ground, the red wire to the digital PWM pin. One pin is configured in the program as an "input". The Arduino monitors the voltage fluctuation on the pin, which is supplied with voltage from the button, resistor and sensors.


Arudino squeaker with contact names

The voltage to the "input" is supplied with different values, the system clearly records only two states - the aforementioned 1 and 0 (logical zero and one). The logical unit will refer to a voltage of 2.3-5 V. The "output" mode is when the Arduino applies a logic zero / one to the output. If we take the logical zero mode, then the voltage value is so small that it is not enough to ignite the LED.


Wiring diagram for tweeter to Arduino

Please note that the inputs are quite sensitive to various kinds of external noise, so the piezo tweeter leg should be connected to the output through a resistor. This will give a high voltage level on the stem.

An example of a sketch for a piezo speaker

To "revive" the buzzer connected to the arduino board, you will need the Arduino IDE software, which you can.

One of the simplest ways to get the buzzer to speak is to use the "analogwrite" function. But it's better to use the built-in functions. The function "tone ()" is responsible for triggering the sound notification; in brackets the user should indicate the parameters of the sound frequency and input number, as well as the time. To mute the sound, use the "noTone ()" function.

Example sketch with tone () and noTone () function

// The pin to which the piezo speaker is connected. int piezoPin \u003d 3; void setup () () void loop () (/ * The function takes three arguments 1) Pin number 2) The frequency in hertz, which determines the pitch 3) Duration in milliseconds. * / tone (piezoPin, 1000, 500); // The sound will stop after 500ms, but the program won't stop! / * Option without set duration * / tone (piezoPin, 2000); // Start sounding delay (500); noTone (); // Stop the sound)

The connection diagram for an example looks like this:


Connecting the buzzer to the 3 pin of Arduino

When you use the tone () function, the following restrictions apply.

You cannot use PWM on pins 3 and 11 at the same time (they use the same internal timer), and you cannot start two melodies simultaneously with two tone () commands - only one will be played at a time. ...

The active buzzer sketch is extremely simple. we set the value 1 to the port to which the buzzer is connected.

Buzzer sketch option without tone ()

An example sketch for a variant without the tone () function is shown in the image below. This code sets the frequency of sound activation once every two seconds.


For the device to work correctly, it is necessary to set the PIN number, define it as "output". The analogWrite function takes the pin number and the level as arguments, which changes its value from 0 to 255. This is because the Arduino PWM pins have an 8-bit DAC (digital to analogue converter). By changing this parameter, the user changes the buzzer volume by a small amount. For complete shutdown, impregnate the value "0" in the port. It should be said that using the "analogwrite" function, the user will not be able to change the key of the sound. For the piezo emitter, the frequency will be 980 Hz. This value coincides with the frequency of operation of pins with pwm on Arduino and analog boards.

Examples of buzzer melodies

In order to diversify the work with a new project, add an "entertaining" element to it, users came up with the idea of \u200b\u200bsetting a certain set of sound frequencies, making it consonant with some famous compositions from songs and films. A variety of sketches for such melodies can be found on the Internet. Let's give an example of a piezo tune for one of the most recognizable tracks "nokia tune" from the legendary Nokia mobile phones. You can make the pitches.h file yourself by copying its contents as indicated in this article on the official website.


When writing your own melodies, knowing the frequencies of the notes and the durations of the intervals used in the standard musical notation is useful.

Frequency of notes for Arduino tweeter

Conclusion

In this article, we examined the issues of using the buzzer in Arduino projects: we figured out the passive and active buzzers, highlighted some theoretical issues on the structure of the piezoelectric element. We learned how to connect a piezo sounder to an arduino and how to program a sketch to work with active, passive modules. As you can see, there is nothing particularly difficult in working with buzzers, and you can easily include audio capabilities in your project. Moreover, in addition to the usual beeps, you can create entire pieces of music.

In this article, we will explain what a buzzer is, its scope, and how to connect it.

Boozer, Buzzer, Piezoelectric Emitter, Beeper or something else? - there are a large number of names for this small squeaking infection, which suggests that something not very good has happened. How often have I just hated this nasty squeak buzzer. I guess I'm not alone in this desire. Surely you heard an extremely unpleasant pleasant sound that the system gave you by mistake (or not) at the entrance / exit from the store. Agree that this is an extremely unpleasant sound. In a further article, I will call them all buzzer, as I am used to this name.

Buzzer is a device that allows you to generate a sound of a certain frequency. Usually the frequency range is in the range from 1 - 10 kHz and if you come across a sound buzzer, then there is a characteristic sound: "piiiiiiip".

It is the easiest way to make a squeak that is heard well and far away. The latter buzzer does especially well, as standard buzzers create sound waves, with an attenuation coefficient of 85-90db per 30 cm. As a result, a small buzzer is enough for a small hangar.

I personally got this copy (model sl1i-12fsp):

With him, I spent all my buzzer tests. It turned out that it is well heard even in a crowd of screaming children, since the signal contains a high frequency, which is not enough in a human voice. This allows you to almost always tell whether it works or not. If you do not have a crowd of children, but have a working fan / engine / something similar, then do not hesitate, you will hear it very well.

Buzzer connection.

Connection to the circuit is carried out like a battery or a diode. The device has “+” and “-” markings. We connect them to a supply voltage of 3 to 20 volts, and enjoy the sound we get. The buzzer has a slight inertia, and after turning off the power, it will sound for some time. Therefore, it will not work to simulate the sound on it, but as an alarm signal, you get what you need.

They are usually controlled by a common emitter bipolar transistor amplifier. This allows you to make even polyphonic sound from your MC (ARDUINO / SMT32 / MSP430). But it should be borne in mind that there are buzzers with a built-in generator. They squeak intermittently, with a certain frequency. This allows the use of different buzzers that indicate different events. They are more expensive, but if you are building something without a microcontroller, then this is a great trick with your ears.

Applications of the Buzzer.

I propose to apply this scheme in the following directions:

1) security systems

2) sensors signaling impacts of any kind.

3) household appliances (for example, in microwave ovens, where the signal about the end of work is given by the buzzer).

4) toys.

5) in any device where sound notification is required.

Personal experience of use.

I have seen buzzers of various designs and characteristics. They always squealed very stable, and did not require practically any expensive audio amplifiers. Many developers love them very much, but I found a number of difficulties when working with them:

1) Extremely disgusting sound when practicing. Of course, if you have a frequency of operation of this part every few days, then nothing else, but during the tests it will beep constantly, which will inevitably affect your receptivity and desire to work.

2) Sufficient power consumption for wearable electronics. It's definitely not worth betting that you will carry such a thing with you.

3) Sufficient inertia. At one time, I spent a lot of time to make a midi keyboard based on a cheap buzzer. After all my efforts, good sound reproduction did not work out, but the music from the old SEGA was restored, which my client was extremely happy about.