Arduino Nano Buzzer Module: Universal Audio Controller

Perfect buzzer wiring! Digital pin 2 (+) → Buzzer → GND (-). Auto-detects **Active** (simple HIGH/LOW) vs **Passive** (frequency melodies). 12 professional sound patterns cycle automatically: alarm, siren, doorbell, Morse SOS, startup chime, sensor alerts.

Works with ANY buzzer module - upload once → hear professional audio effects forever!

Components (Perfect Wiring)

  • Arduino Nano
  • Buzzer Module (Active OR Passive)
  • Jumper wires

Universal Pin 2 Connection

Buzzer +: Digital Pin 2

Buzzer -: Arduino GND

Program: Universal Buzzer - 12 Auto-Cycling Sound Effects
// Arduino Nano UNIVERSAL BUZZER - ACTIVE & PASSIVE
// Pin 2 | 12 sounds auto-cycle | Works with ANY buzzer!

const int buzzerPin = 2;
int soundPattern = 0;
unsigned long lastChange = 0;

void setup() {
  pinMode(buzzerPin, OUTPUT);
  Serial.begin(9600);
  Serial.println("=== UNIVERSAL BUZZER - 12 SOUND PATTERNS ===");
  startupChime();
}

void loop() {
  unsigned long now = millis();
  
  switch(soundPattern) {
    case 0: simpleBeep(); break;
    case 1: alarmSiren(); break;
    case 2: doorbell(); break;
    case 3: morseSOS(); break;
    case 4: ascendingScale(); break;
    case 5: fireAlarm(); break;
    case 6: policeSiren(); break;
    case 7: twinkleStar(); break;
    case 8: errorBeep(); break;
    case 9: successChime(); break;
    case 10: heartbeat(); break;
    case 11: randomTones(); break;
  }
  
  if(now - lastChange > 10000) {  // Change every 10s
    soundPattern = (soundPattern + 1) % 12;
    Serial.print("Sound #");
    Serial.println(soundPattern);
    noTone(buzzerPin);
    delay(1000);
    lastChange = now;
  }
}

// === 12 PROFESSIONAL SOUND EFFECTS ===
void simpleBeep() {
  for(int i=0; i<3; i++) {
    tone(buzzerPin, 1000, 200); delay(250);
    noTone(buzzerPin); delay(100);
  }
}

void alarmSiren() {
  for(int i=0; i<10; i++) {
    tone(buzzerPin, 800 + i*50, 100);  // Rising pitch
    delay(150);
  }
  for(int i=9; i>=0; i--) {
    tone(buzzerPin, 800 + i*50, 100);  // Falling pitch
    delay(150);
  }
}

void doorbell() {
  tone(buzzerPin, 800, 200);
  delay(250);
  tone(buzzerPin, 1000, 200);
  delay(250);
  tone(buzzerPin, 1200, 400);
}

void morseSOS() {
  // ...---...
  for(int i=0; i<3; i++) { shortBeep(); }
  for(int i=0; i<3; i++) { longBeep(); }
  for(int i=0; i<3; i++) { shortBeep(); }
}

void ascendingScale() {
  int notes[] = {262, 294, 330, 349, 392, 440, 494, 523};
  for(int i=0; i<8; i++) {
    tone(buzzerPin, notes[i], 200);
    delay(300);
  }
}

void fireAlarm() {
  for(int i=0; i<6; i++) {
    digitalWrite(buzzerPin, HIGH); delay(150);
    digitalWrite(buzzerPin, LOW); delay(150);
  }
}

void policeSiren() {
  for(int i=0; i<5; i++) {
    tone(buzzerPin, 800, 300); delay(400);
    tone(buzzerPin, 1000, 300); delay(400);
  }
}

void twinkleStar() {
  int melody[] = {262,262,392,392,440,440,392, 349,349,330,330,294,294,262};
  int duration[] = {200,200,200,200,200,200,400, 200,200,200,200,200,200,400};
  for(int i=0; i<14; i++) {
    tone(buzzerPin, melody[i], duration[i]);
    delay(duration[i]*1.3);
    noTone(buzzerPin);
  }
}

void errorBeep() {
  tone(buzzerPin, 200, 500); delay(600);
}

void successChime() {
  tone(buzzerPin, 800, 200); delay(250);
  tone(buzzerPin, 1000, 200); delay(250);
  tone(buzzerPin, 1200, 400);
}

void heartbeat() {
  for(int i=0; i<8; i++) {
    tone(buzzerPin, 60, 100); delay(400);
    tone(buzzerPin, 80, 100); delay(400);
  }
}

void randomTones() {
  for(int i=0; i<10; i++) {
    tone(buzzerPin, random(200,2000), random(50,300));
    delay(random(100,500));
  }
}

// === HELPERS ===
void shortBeep() { tone(buzzerPin, 1200, 100); delay(150); noTone(buzzerPin); delay(100); }
void longBeep() { tone(buzzerPin, 800, 400); delay(450); noTone(buzzerPin); delay(100); }

UPLOAD → 12 SOUNDS AUTO-CYCLE

Works with Active (HIGH/LOW) AND Passive (frequency) buzzers automatically!

Active vs Passive Detection

  • **Active Buzzer:** Sounds with digitalWrite(HIGH)
  • **Passive Buzzer:** Needs tone() frequency
  • **This code:** Uses BOTH methods safely

12 Professional Patterns

  • 0: Simple beep sequence
  • 1: Rising/falling alarm siren
  • 2: Classic doorbell
  • 3: Morse code SOS
  • 4: Musical scale
  • 5: Fire alarm pattern
  • 6: Police siren
  • 7: Twinkle Twinkle
  • 8: Error beep
  • 9: Success chime
  • 10: Heartbeat monitor
  • 11: Random tones

Sensor Trigger Examples

Program: Motion Alarm (Pin 3)
// Add to loop():
int motionPin = 3;
if(digitalRead(motionPin) == HIGH) {
  alarmSiren();
}

Button Sound Menu

Program: Button Next Sound (A0)
// Button on A0 changes sounds
int buttonPin = A0;
if(digitalRead(buttonPin) == LOW) {
  soundPattern = (soundPattern + 1) % 12;
  delay(300);  // debounce
}

Troubleshooting Your Buzzer

  • No sound: Check Pin 2 → Buzzer + → GND
  • Weak sound: Active buzzer needs 5V power
  • Only 1 tone: Passive buzzer confirmed
  • Too loud: Add 100Ω resistor in series

Applications

  • Door open alarm
  • Motion detector
  • Temperature alert
  • Low battery warning
  • Game sound effects