Blog
ESP32 Speaker: Amplifiers, Buzzers
A speaker on an ESP32 means one of three things: a buzzer, a line-level output, or an amplifier. Here’s what connects to what, and why “just plug it into a pin” rarely works.
How to Connect Speaker to ESP32?
An 8Ω speaker can’t hang off a GPIO directly — pins source roughly 12mA. The reliable path is an I2S amplifier: MAX98357A with BCLK→26, LRC→25, DIN→22, plus 5V and GND. With AudioOutputI2S in the sketch it plays. For beeps only, a passive buzzer on any output pin works — next answer.
How to Connect Buzzer to ESP32?
Active buzzer: 3.3V, GND, and SIG to any GPIO; digitalWrite high = beep. Passive: same wiring, but you drive the frequency — tone(pin, 440) or ledc PWM. Active buzzers carry an internal oscillator; passive ones don’t, which is why they can play melodies.
Can ESP32 Play Audio?
Yes, three routes. The built-in 8-bit DAC on GPIO25/26 works, sounds hissy, fine for alerts. I2S plus an external amp (MAX98357A, PAM8403) is the good path. Or a self-contained module like DFPlayer Mini that plays from SD on serial commands. Nobody stays on the DAC long.
Do I Need an Amplifier?
For audible volume, yes. A GPIO at 3.3V into 8Ω delivers a few milliwatts — audible at 10cm on a good day. A PAM8403 (2×3W) or MAX98357A (3W at 4Ω) gets you across a room. One warning: I ran a PAM8403 at 5V into a 4Ω speaker at full volume and hit its thermal shutdown mid-song — feed it from a rail that survives bursts; see the power FAQ.
How to Flash WAV onto ESP32?
WAV files go on the flash filesystem, not via esptool: make a data/ folder, upload with the LittleFS or SPIFFS plugin (PlatformIO: uploadfs), then AudioGeneratorWAV plus AudioOutputI2S. Size reality: 44.1kHz 16-bit stereo is about 10MB per minute, so keep clips short or drop to 8-bit 22kHz. The examples page has a working sketch.
Why Is My Speaker Silent or Distorted?
Silent: the amplifier’s enable pin floating (MAX98357A’s SD must sit high), BCLK/LRC/DIN mis-assigned, or volume at zero — AudioOutputI2S.SetGain or ledcWrite. Distorted: clipping — keep samples under full scale, or the 5V rail sags under load; a breadboard jumper is its own source of bad contact. And a buzzer will never play music: it’s a square-wave driver, not a transducer for audio.
Active or Passive Buzzer — Which Should I Use?
Passive, unless you only want a fixed alarm tone. Passive plus tone() gives you melodies and the wiring is identical. Active wins only when you want one beep from one pin with zero code beyond digitalWrite.
How Loud Can a Small ESP32 Speaker Get?
Realistically 85–90dB at 30cm with a 3W amp — room level, not party level. Doubling power adds only 3dB; a better enclosure does more than a bigger amp. A 3W amp at full tilt draws ~0.6A at 5V, so battery projects should expect short runtime.
Can I Play Audio While Wi-Fi Is On?
Yes — I2S runs on DMA, so Wi-Fi and audio coexist; the classic bug is buffer underruns when your loop() renders audio and handles connections at once. Pin the audio task to core 1 with xTaskCreatePinnedToCore and let Wi-Fi keep core 0. It mostly works out of the box, which is how most people ship it.
Can I Test Speaker Projects without Hardware?
Wire a buzzer and test tone() in the ESP32 simulator; the I2S sketch logic runs the same at app.sensbench.com. What you can’t hear in a browser is the actual sound — but you can prove the code path works before soldering.