
Buzzers are small devices that produce sound. They are often used in alarms, timers, and notification systems. With ESP8266, you can control buzzers to create beeps, tones, and even simple melodies.
There are two types of buzzers:
👉 In this tutorial, we’ll cover both.
Text description (for D5 / GPIO14):

(If using a passive buzzer, resistor may be used in series for safety.)
// Active Buzzer with ESP8266
int buzzerPin = D5; // GPIO14
void setup() {
pinMode(buzzerPin, OUTPUT);
}
void loop() {
digitalWrite(buzzerPin, HIGH); // Buzzer ON
delay(1000); // Wait 1 second
digitalWrite(buzzerPin, LOW); // Buzzer OFF
delay(1000); // Wait 1 second
}
For a passive buzzer, we use PWM to generate sound frequencies.
// Passive Buzzer with ESP8266
int buzzerPin = D5; // GPIO14
void setup() {
pinMode(buzzerPin, OUTPUT);
}
void loop() {
tone(buzzerPin, 1000); // Play 1kHz tone
delay(1000);
noTone(buzzerPin); // Stop sound
delay(1000);
}
// Simple melody using ESP8266 and passive buzzer
int buzzerPin = D5;
int melody[] = {262, 294, 330, 349, 392, 440, 494}; // Notes C, D, E, F, G, A, B
void setup() {}
void loop() {
for (int i = 0; i < 7; i++) {
tone(buzzerPin, melody[i]); // Play note
delay(500); // Duration
noTone(buzzerPin); // Stop note
delay(100);
}
}
🔊 Plays a sequence of musical notes (C to B).
You now know how to use a buzzer with ESP8266:
This is a great foundation for projects like fire alarms, smart doorbells, or IoT notifications. 🚀
Yes, for small buzzers. For larger ones, use a transistor driver.
Active buzzers beep when powered. Passive buzzers need a PWM frequency signal.
Yes, you can integrate this with a web page or MQTT for remote alerts.






