5.4 Experimental principle
The principle is simple in this experiment, which is summarized as follows. The buzzer can make a sound, since the current on the buzzer is powered on the electromagnetic coil, which can make coil generate magnetic field. Then it can drive vibrating diaphragm to generate a sound. This is the reason why the buzzer must need the current. Its schematic principle is drawn in Figure 5-3. In our such experiment, port 9 on the Arduino board can provide a voltage for the passive buzzer. Then it can generate a sound. It is worth noting that, the rated voltage for the buzzer is 5V, while the Arduino’s max voltage is 5V as well. Therefore, the circuit cannot connect serially a resistor. If connected, then the buzzer doesn’t work.
5.5 Experiment and code
In fact, the circuit connection of such experiment is very simple, which is seen in Figure 5-3. After run Program 5, Arduino can generate alarm sound.
Figure 5-3 Experimental circuit
01 // Program 5: how to use Arduino and buzzer generate alarm sound
Here, a new Arduino function “tone” is introducted. Its syntax is:
tone(pin, frequency, duration)
pin：which is defined on the Arduino board
frequency: the voice frequency, unit is Hz, unsigned int
duration：voice lasting time, unit is ms (optional), unsigned long
5.6 Key points and summaries
1) The buzzer can be divided into active and passive. The active one can make a sound by directly connecting power, while the passive one can generate a sound only for the changing frequency. Therefore, the buzzer can make a sound on the Arduino board by PWM technique. But, it cannot connect serially a resistor.
2) The principle of buzzer is that, when the current passes through the electromagnetic coil, it will generate a magnetic field, which can drive the vibrating diaphragm make a sound periodically.