A passive buzzer is a tiny speaker: it makes whatever pitch you drive it at. With the Uno’s built-in tone() function it can play notes, melodies and sirens. That makes it the better choice over an active buzzer when you want an alarm people actually notice.
Wire I/O to D8 and power the module from 5V. The thing to plan for on the Uno is that tone() takes over Timer2. While it plays, PWM on D3 and D11 stops, and it can’t share a sketch with IRremote.
The sketch plays the Indian sargam (Sa Re Ga Ma Pa Dha Ni Sa) up and down, then a rising and falling siren — a good starting point for a doorbell or a gas alarm.
Wiring
| Arduino Uno R3 | Passive buzzer module | Wire | Notes |
|---|---|---|---|
| D8 | I/O | yellow | <code>tone()</code> works on any digital pin. |
| 5V | VCC | red | |
| GND | GND | black |
3.3–5 V part, 5 V board. On the 3-pin module the I/O pin only drives a transistor, so a 3.3 V GPIO is enough even with the buzzer on 5 V. The 2-pin bare buzzer or KY-006 can run straight from a GPIO through a 100 Ω resistor at low volume.
Board quirks
- A passive buzzer has no oscillator: the Uno must send it a square wave at the note’s frequency, which is what
tone()does. On plain 5 V it only clicks once. tone()uses the Uno’s Timer2. While a note plays,analogWrite()on D3 and D11 doesn’t work, and IRremote (also Timer2) can’t be used in the same sketch.- Only one tone at a time on the Uno — a second
tone()on another pin is ignored untilnoTone(). - Passive buzzers are loudest near their resonance, about 2–4 kHz. Low notes like Sa (262 Hz) sound quiet; that is the buzzer, not the code.
- Some KY-006 boards print the pins as
Sand−with an unlabelled middle pin. S is I/O, − is GND, the middle one is VCC.
Code
// Passive buzzer module on an Arduino Uno R3, played with tone().
// I/O → D8, VCC → 5V, GND → GND.
// tone() uses Timer2: while it plays, PWM on D3 and D11 stops working.
const uint8_t BUZZER_PIN = 8;
// Sargam in C: Sa Re Ga Ma Pa Dha Ni Sa' (Hz)
const uint16_t SARGAM[] = {262, 294, 330, 349, 392, 440, 494, 523};
const char* const NAMES[] = {"Sa", "Re", "Ga", "Ma", "Pa", "Dha", "Ni", "Sa'"};
void setup() {
Serial.begin(9600);
Serial.println(F("Passive buzzer on D8 - playing the sargam"));
}
void loop() {
for (uint8_t i = 0; i < 8; i++) {
Serial.print(NAMES[i]);
Serial.print(' ');
tone(BUZZER_PIN, SARGAM[i], 300);
delay(350); // tone() returns at once; wait for the note plus a short gap
}
Serial.println();
delay(600);
for (int8_t i = 7; i >= 0; i--) {
tone(BUZZER_PIN, SARGAM[i], 200);
delay(230);
}
Serial.println(F("Siren"));
for (uint8_t r = 0; r < 3; r++) {
for (uint16_t f = 600; f < 1400; f += 20) {
tone(BUZZER_PIN, f);
delay(5);
}
for (uint16_t f = 1400; f > 600; f -= 20) {
tone(BUZZER_PIN, f);
delay(5);
}
}
noTone(BUZZER_PIN);
delay(2000);
}// Passive buzzer module on an Arduino Uno R3, played with tone().
// I/O → D8, VCC → 5V, GND → GND.
// tone() uses Timer2: while it plays, PWM on D3 and D11 stops working.
const uint8_t BUZZER_PIN = 8;
// Sargam in C: Sa Re Ga Ma Pa Dha Ni Sa' (Hz)
const uint16_t SARGAM[] = {262, 294, 330, 349, 392, 440, 494, 523};
const char* const NAMES[] = {"Sa", "Re", "Ga", "Ma", "Pa", "Dha", "Ni", "Sa'"};
void setup() {
Serial.begin(9600);
Serial.println(F("Passive buzzer on D8 - playing the sargam"));
}
void loop() {
for (uint8_t i = 0; i < 8; i++) {
Serial.print(NAMES[i]);
Serial.print(' ');
tone(BUZZER_PIN, SARGAM[i], 300);
delay(350); // tone() returns at once; wait for the note plus a short gap
}
Serial.println();
delay(600);
for (int8_t i = 7; i >= 0; i--) {
tone(BUZZER_PIN, SARGAM[i], 200);
delay(230);
}
Serial.println(F("Siren"));
for (uint8_t r = 0; r < 3; r++) {
for (uint16_t f = 600; f < 1400; f += 20) {
tone(BUZZER_PIN, f);
delay(5);
}
for (uint16_t f = 1400; f > 600; f -= 20) {
tone(BUZZER_PIN, f);
delay(5);
}
}
noTone(BUZZER_PIN);
delay(2000);
}Expected serial output
Passive buzzer on D8 - playing the sargam
Sa Re Ga Ma Pa Dha Ni Sa'
SirenPassive buzzer on D8 - playing the sargam Sa Re Ga Ma Pa Dha Ni Sa' Siren
Common errors
Only a click, no tone
You are using digitalWrite(), or it is an active buzzer driven with tone(). Use tone(pin, frequency) for passive buzzers.
LED on D3 or D11 stopped dimming
Timer2 is busy with tone(). Move the LED to D5, D6, D9 or D10.
“multiple definition of __vector_7” when compiling
Another library also uses Timer2 (IRremote, some servo or timer libraries). Use only one of them, or a different library for the buzzer.