Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.

Active buzzer with Arduino Nano — chirp, double beep and alarm patterns

Wire an active buzzer module to an Arduino Nano on D8 and play three reusable alert patterns, and learn why tone() is the wrong call for it.

Arduino C++Verified — core avr 1.8.8, 3 Nov 2026Compile-only

Community draft — report a mistake

An active buzzer is the simplest way to give a project a voice: tank-full alarms, door-open reminders, gas alerts and keypad clicks. It needs one digital pin; this guide uses D8.

The sketch plays three patterns in turn. Copy the beep() function into your own project and call it with the on time, off time and repeat count.

Wiring

Arduino NanoOnly the pins used are shown · 5 V logicActive buzzer module (high-level trigger)5VGNDD8I/OVCCGND
Every connection
Arduino NanoActive buzzer module (high-level trigger)WireNotes
D8I/Oyellow
5VVCCred
GNDGNDblack

3.3–5 V part, 5 V board. The I/O pin only drives the module's transistor, so a 3.3 V GPIO is enough even when the buzzer runs from 5 V. Check the label: "high-level trigger" beeps when I/O is HIGH; "low-level trigger" modules (with a PNP transistor) beep when I/O is LOW.

Board quirks

  • An active buzzer has its own oscillator: HIGH = beep. tone() chops the supply and makes it buzz badly. For melodies you need a passive buzzer.
  • The module’s transistor does the switching, so the Nano pin only supplies a few mA.
  • Check the label: “low-level trigger” modules beep when I/O is LOW, and will beep all through the bootloader until setup() runs.
  • delay()-based beeps block the sketch. For an alarm that runs alongside sensor reading, switch to a millis() timer.

Code

buzzer-nano.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// Active buzzer module on an Arduino Nano: three alert patterns you can reuse.
// I/O → D8, VCC → 5V, GND → GND. High-level trigger module (I/O HIGH = beep).
// An active buzzer has its own oscillator — use digitalWrite, not tone().
const uint8_t BUZZER_PIN = 8;

void beep(unsigned int onMs, unsigned int offMs, uint8_t times) {
  for (uint8_t i = 0; i < times; i++) {
    digitalWrite(BUZZER_PIN, HIGH);
    delay(onMs);
    digitalWrite(BUZZER_PIN, LOW);
    delay(offMs);
  }
}

void setup() {
  pinMode(BUZZER_PIN, OUTPUT);
  Serial.begin(115200);
}

void loop() {
  Serial.println(F("Pattern 1: single chirp (key press)"));
  beep(60, 0, 1);
  delay(2000);
  Serial.println(F("Pattern 2: double beep (door open)"));
  beep(150, 150, 2);
  delay(2000);
  Serial.println(F("Pattern 3: fast alarm (tank full / gas)"));
  beep(100, 100, 10);
  delay(4000);
}

Expected serial output

Serial Monitor · 115200Output
Pattern 1: single chirp (key press)
Pattern 2: double beep (door open)
Pattern 3: fast alarm (tank full / gas)

Common errors

Buzzer beeps continuously

A low-level trigger module, or I/O and VCC swapped. Invert the logic or check the pin labels.

Sound is a weak click

It is a passive buzzer. Use tone(8, 2000) for it, or buy an active one (sealed back, longer leg = +).

↑↓ to move · Enter to open