Skip to main content
A piezoelectric buzzer.

Pins

1
signal
Negative (Black) pin
2
signal
Positive (Red) pin

Attributes

mode
string
default:"smooth"
Buzzer operation mode: “smooth” or “accurate”
volume
string
default:"1.0"
Volume (loudness) of the sound, between “0.01” and “1.0”

Operation modes

The buzzer can operate in two modes: “smooth” (the default) and “accurate”. Smooth mode sounds better and is suitable for simple, single-frequency tones. Use it when playing a melody or playing tones with Arduino’s tone() function. Complex and polyphonic sounds may not play correctly (or not play at all) in smooth mode. Accurate mode should be used when you need to play complex sounds. It will accurately play the sound you feed in. However, it’ll add audible click noises to your sound. These noises are due to fluctuations in the simulation speed - it’s not always able to provide the complete sound buffer in real time.

Arduino example

Connect pin 1 of the buzzer to Arduino GND pin, and pin 2 of the buzzer to Arduino pin 8. Then use the tone() function to play a sound:
tone(8, 262, 250); // Plays 262Hz tone for 0.250 seconds

Simulator examples

  • Simon game - A memory game with 4 push buttons
  • Diatonic piano - An 8-note piano, use keys 1-8 to press the buttons and play the notes.
  • Alarm clock - Uses the buzzer to play the alarm sound

Build docs developers (and LLMs) love