Pitch, and where it is loudest
The frequency you pass to tone() is the pitch you hear, and an octave up is twice the frequency. The buzzer plays all of them, but not equally loud: it has a resonance at 2.7 kHz, where its maker measures at least 80 dB at 10 cm, and the octave around middle C comes out about 20 dB quieter.
Frequency is pitch
A tone is a number of cycles a second. The A that orchestras tune to is 440 of them, 440 Hz. Each octave up doubles it: the next A is 880 Hz, then 1760 Hz. Between each pair of octaves are twelve notes, each about 6 % higher than the last.
The top trace is the wave tone() puts on SIGNAL: always half HIGH and half
LOW, only faster or slower. The buzzer turns each cycle into one push of the
disc, so it follows whatever frequency you give it.
| Note | Octave 4 | Octave 5 | Octave 6 | Octave 7 |
|---|---|---|---|---|
| C | 262 | 523 | 1047 | 2093 |
| E | 330 | 659 | 1319 | 2637 |
| G | 392 | 784 | 1568 | 3136 |
| A | 440 | 880 | 1760 | 3520 |
Frequencies in hertz, rounded to the whole number tone() takes.
Where it is loudest
The lower trace is the buzzer's datasheet: how loud it is at 10 cm across the range, at 3.6 V with a 50 % square wave. It is not flat. At 2.7 kHz there is a peak about 15 dB above the frequencies around it. That is the resonance: the disc and the air in its case ring at that pitch by themselves, so a push that arrives in time with the ringing adds to it.
That is why the part's value is printed as "2.7kHz" in the parts list, why the maker measures its loudness there, at least 80 dB at 10 cm from 5 V, and why an alarm or a keypress beep should use it.
Low notes are the price. Middle C, 262 Hz, is about 20 dB under the peak on the curve. The curve is read by eye off the datasheet and is good to a couple of decibels, but the shape is the point: a tune in the fourth octave is thin and quiet, the same tune two octaves up is clear. This book's melody plays in the sixth.
There is a second, sharper peak near 7.8 kHz. It is above any melody and unpleasant to listen to, and nothing here uses it.
When it does not work
They are quieter, not broken. On the datasheet's curve the octave around middle C, 262 Hz, sits about 20 dB under the peak at 2.7 kHz. Move the tune up one or two octaves by doubling or quadrupling every frequency, and it will be clearer as well as louder.
That is the buzzer's resonance, the pitch it is built to be loudest at. For a quieter beep, pick a pitch away from it, 1 to 2 kHz, or lower the duty cycle as the volume article shows. Putting tape over the side port also muffles it.
tone() takes whole hertz, which is fine for any note a buzzer plays, so the likely cause is the sketch: two entries with the same number, or a note name mapped to the wrong frequency. Print each frequency to the Serial Monitor as it plays.
Edit this page — content/books/passive-buzzer/pitch-and-resonance.mdx
Questions about this product
See what other owners have asked, and read their solutions.
Passive Buzzer
Loading discussions…
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.