ABC of Electronics cosycom.com
ARDUINO 13 · Outputs

Controlling a Buzzer / Piezo Speaker

Drive a passive piezo buzzer with the Uno's built-in tone() function, no external oscillator circuit required.

You'll need: a small piezo buzzer, one resistor (around 100Ω, optional but recommended to limit current), and your Uno.

Lesson cb-13 explained that a passive buzzer needs an actual oscillating signal to produce sound, unlike an active buzzer. Rather than building that oscillator externally with a 555 timer, the Uno can generate one directly in software with a single built-in function: tone().

void setup() {
  // nothing to configure -- tone() handles pin setup internally
}

void loop() {
  tone(8, 440);   // play a 440Hz tone (concert A)
  delay(500);
  noTone(8);      // stop
  delay(500);
}

tone(pin, frequency) generates a square wave at the given frequency (in Hz) on the specified pin, for as long as it keeps running — no pinMode() call needed first, since tone() configures the pin itself. noTone(pin) stops it. Together, this plays a half-second beep, half-second silence, repeating.

Try changing 440 to a few different values between roughly 200 and 3000 to hear the pitch change, or wire the button circuit from Lesson ard-05 and call tone() only while the button is pressed — a small combination exercise using two lessons you've already completed.

UNO abcofelectronics
tone() drives the buzzer One function call generates the oscillating signal a passive buzzer needs — no external 555 timer or oscillator circuit required.
TRY THIS
tone() replaces an entire external oscillator circuit with one function call — it configures the pin itself, so no separate pinMode() is needed.