Home / Active buzzer
Side quest · electronics · ~15 min

Beep with an active buzzer

An active buzzer is the easiest noise-maker in electronics: two wires, and turning a pin on makes it beep. No special library, no frequency maths. We'll get a beep, fire off an SOS alarm, then make a button beep on demand.

01Active vs passive

There are two kinds of small buzzer, and they look almost identical. Getting the right one matters:

TypeWhat it doesHow you drive it
ActiveHas a built-in tone generator. One fixed pitch.Just turn the pin HIGH — it beeps
PassiveNo tone generator. You feed it the pitch.Needs tone() / a changing signal

This guide is for the active one. Two easy ways to spot it: it usually has a sticker on top and is a little taller, and it often has a + marked by one leg. If you flip it over and see a green circuit board with a copper coil, that's a passive buzzer — set it aside for now.

The one-sentence rule

Active = on/off beeps (this guide). Passive = melodies, but you have to generate every note in code.

02What you need

  • An active buzzer (the one with the sticker / + mark)
  • An Arduino Uno + USB cable
  • 2 jumper wires (male-to-female if you're plugging straight into the buzzer's legs)
  • For the last example only: a pushbutton + 2 more wires

03Wiring it up

Just two wires. The buzzer has a long leg (+) and a short leg (−), exactly like an LED:

An active buzzer with its plus leg wired to Arduino pin 8 and its minus leg to GND
FIG. 07 — ACTIVE BUZZER, 2 WIRES
Buzzer legWire to Arduino
+ (long leg)pin 8
(short leg)GND
Current check

A small active buzzer sips about 25–30 mA, which an Arduino pin can supply directly. If you ever use a big, loud buzzer, drive it through a transistor instead so you don't overload the pin — but for the little ones, straight to the pin is fine.

04Make it beep

Here's the whole idea: HIGH = beep, LOW = silence. This makes a short beep once a second:

first_beep.ino
const int BUZZER = 8;

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

void loop() {
  digitalWrite(BUZZER, HIGH);   // beep
  delay(200);                   // ...for 0.2 seconds
  digitalWrite(BUZZER, LOW);    // silence
  delay(800);                   // ...for 0.8 seconds, then repeat
}

That's genuinely all there is to an active buzzer. Everything else is just patterns of beeps and silences.

05SOS alarm

Same trick, more interesting timing. SOS in Morse code is three short beeps, three long beeps, three short beeps — ··· ——— ···. It uses the exact same timing rules as the LED Morse page, just sent to your ears instead of your eyes:

sos_buzzer.ino
const int BUZZER = 8;

// Timing, all based on one "unit" (a dot length).
const int UNIT = 200;
const int DOT  = UNIT;          // short beep : 1 unit
const int DASH = UNIT * 3;      // long beep  : 3 units
const int GAP_SYMBOL = UNIT;     // silence between beeps
const int GAP_LETTER = UNIT * 3; // silence between letters

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

// One beep of a given length, then a short gap.
void beep(int ms) {
  digitalWrite(BUZZER, HIGH);
  delay(ms);
  digitalWrite(BUZZER, LOW);
  delay(GAP_SYMBOL);
}

void loop() {
  beep(DOT);  beep(DOT);  beep(DOT);    // S = ...
  delay(GAP_LETTER);
  beep(DASH); beep(DASH); beep(DASH);   // O = ---
  delay(GAP_LETTER);
  beep(DOT);  beep(DOT);  beep(DOT);    // S = ...
  delay(2000);                          // pause, then repeat
}

Want a faster or slower alarm? Change UNIT. Want a different message? Beep out any letters using the chart on the Morse page.

06Button-triggered beep

Now let's make it beep only when you say so. Add a pushbutton between pin 2 and GND — no resistor needed, because we'll use the Arduino's built-in one:

A pushbutton wired between Arduino pin 2 and GND
FIG. 08 — PUSHBUTTON (BUZZER STAYS ON PIN 8)
Button legWire to Arduino
One legpin 2
Diagonally opposite legGND

The buzzer stays exactly where it was (+ on pin 8, − on GND). Then:

button_beep.ino
const int BUZZER = 8;
const int BUTTON = 2;

void setup() {
  pinMode(BUZZER, OUTPUT);
  pinMode(BUTTON, INPUT_PULLUP);   // built-in resistor; not pressed = HIGH
}

void loop() {
  if (digitalRead(BUTTON) == LOW) {  // pressed pulls the pin LOW
    digitalWrite(BUZZER, HIGH);      // beep while held
  } else {
    digitalWrite(BUZZER, LOW);       // silent when released
  }
}
Why INPUT_PULLUP?

A floating input pin reads random noise. INPUT_PULLUP switches on a tiny resistor inside the Arduino that holds the pin HIGH by default, so a press cleanly reads LOW. It saves you wiring a separate resistor — that's why the button only needs two wires.

07If it won't beep

What you hearUsually meansTry this
Total silenceLegs swapped, or wrong pin+ (long leg) → pin 8, − (short) → GND
Only a faint tickIt's a passive buzzerActive beeps on HIGH; passive needs tone()
Very quiet beepProtective sticker still onPeel the sticker off the top
Beeps non-stop (button build)Button legs wired on the same sideUse two diagonally opposite legs
Nothing on button pressMissing INPUT_PULLUPCheck pin 2's mode in setup()

Next: the 1602A LCD