Skip to content

Buzzer

A passive piezoelectric buzzer that generates audio tones when driven by a rapidly oscillating digital signal.

Component Preview

BuzzerPiezo Buzzer

Unlike an active buzzer (which beeps at a fixed frequency when given 5V), this is a passive buzzer. It requires a rapidly oscillating signal (like a PWM wave) to produce sound. Changing the frequency of the signal changes the pitch of the sound.

ActuatorsAudio OutputPiezoelectric

Overview

The OpenHW Simulator plays the sound through your computer's speakers using the Web Audio API. Use the standard Arduino tone() function for easy frequency control.

Musical Note Frequencies

Here are some common frequencies you can use with the tone() function:

NoteFrequency
C4 (Middle C)262 Hz
D4294 Hz
E4330 Hz
F4349 Hz
G4392 Hz
A4440 Hz

Pin Reference

PinTypeDescription
GND (-)powerNegative terminal — connect to GND.
SIG (+)digitalPositive terminal — connect to a digital/PWM pin.

Configurable Attributes

AttributeTypeDefaultDescription
volumenumber50Master volume for this buzzer in the simulator (0-100).
frequencynumber440Default resonant frequency configuration (internal).

Working Principle

A piezoelectric disc physically deforms when voltage is applied across it. By rapidly applying and removing voltage (e.g., 440 times per second), the disc vibrates and creates a sound wave (440 Hz pitch, or the note A4).

Wiring Diagram

Connect the buzzer's negative pin to GND and the positive pin to a digital output pin on the Arduino (e.g., Pin 3).

Wiring Diagram

Example Arduino Code

cpp
const int buzzerPin = 3;

// Frequencies for C4, D4, E4, F4, G4, A4, B4, C5
int notes[] = {262, 294, 330, 349, 392, 440, 494, 523};
int durations[] = {200, 200, 200, 200, 200, 200, 200, 400};

void setup() {
  pinMode(buzzerPin, OUTPUT);
}

void loop() {
  for (int i = 0; i < 8; i++) {
    tone(buzzerPin, notes[i], durations[i]);
    delay(durations[i] + 30); // Add a slight pause between notes
  }
  
  noTone(buzzerPin);
  delay(1000);
}

Simulation Notes

  • Ensure your browser tab is not muted. Modern browsers block audio playback until the user clicks on the page, so you must interact with the simulator before audio will play.
  • Hardware Conflict: The tone() function uses Timer 2 on the ATmega328P (Arduino Uno). This conflicts with PWM output on pins 3 and 11. You cannot use analogWrite() on pins 3 or 11 while a tone is playing.

Released under the MIT License.