Here’s the quick, reliable way to hook a buzzer to an Arduino—whether it’s active (beeps with DC) or passive/piezo (needs a tone).
1) Identify your buzzer
- Active buzzer (5 V, “++/–” or “ACTIVE”): has an internal oscillator. Give it HIGH to beep.
- Passive/piezo buzzer (“PASSIVE”, “Piezo”): no oscillator. You must drive it with a square wave (e.g., tone()).
2) Wiring cheat-sheet
A) Small active buzzer (≤20 mA)
- + → Arduino D8 (any digital pin)
- – → GND
- Code toggles pin HIGH/LOW.
If current >20 mA (check datasheet), use the transistor setup below.
B) Passive/piezo buzzer (direct drive)
- Pin D8 → 100–220 Ω series resistor → buzzer +
- Buzzer – → GND
The series resistor protects the pin and tames harsh resonances. Works well for typical piezos (<5 mA).
C) Active/magnetic buzzer or anything >20 mA (transistor driver)
- 5 V → buzzer +
- Buzzer – → NPN collector (2N2222)
- NPN emitter → GND
- Arduino D8 → 1 kΩ → NPN base, plus 10 kΩ base-to-GND pulldown.
- Flyback diode (e.g., 1N4148) across the buzzer: cathode to 5 V, anode to collector.
Writing HIGH turns the buzzer on. Use this for loud buzzers or 12 V units (with a 12 V supply; Arduino still drives the base).
3) Minimal code
Active buzzer (on/off beep)
const int BUZ = 8;
void setup(){ pinMode(BUZ, OUTPUT); }
void loop(){
digitalWrite(BUZ, HIGH); delay(200);
digitalWrite(BUZ, LOW); delay(300);
}
Passive/piezo (play a tone)
const int BUZ = 8;
void setup(){}
void loop(){
tone(BUZ, 1000); // 1 kHz
delay(500);
noTone(BUZ);
delay(500);
}
Transistor-driven active buzzer
(same as first example; just drive the base through 1 kΩ and keep the diode fitted)
4) Useful tips
- Pin limits: Arduino I/O is typically 20 mA max (40 mA abs. max on classic AVR—don’t rely on it). If in doubt, use the transistor.
- tone() conflicts: On classic Arduino UNO, tone() uses Timer2 and disables PWM on pins 3 & 11 while active.
- Volume/brightness: Higher frequency (~2–4 kHz) is louder for many piezos; experiment with tone(BUZ, freq).
- Cleaner sound: For piezo, avoid analogWrite()—use tone() to set a real frequency.
- Extra loud (advanced): Drive the piezo bridge-style between two pins toggled in opposite phases (effectively ~2× voltage). Do this only if comfortable ensuring the two pins never fight each other.
That’s it—identify the buzzer type, choose direct vs. transistor drive, and use digitalWrite (active) or tone() (passive).

Top comments (0)