How to Build a Bluetooth Speaker with ESP 32

In this tutorial, we’ll build a simple Bluetooth audio Player using the ESP32. Once completed, you can stream music directly from your phone to a speaker through the ESP32 

This project is perfect for:

  • IoT learners
  • Embedded beginners
  • DIY audio enthusiasts

Components Required

  • ESP32
  • MAX98357A I2S amplifier module
  • Speaker (4Ω or 8Ω)
  • Jumper wires
  • Breadboard (optional)
ESP 32
MAX98357A

How It Works?

The ESP32 receives audio via Bluetooth (A2DP profile), then sends digital audio data through I2S to an amplifier.

Phone → Bluetooth → ESP32 → I2S → Amplifier → Speaker

Circuit Diagram

ESP32 Pin MAX98357A
GPIO14 BCLK
GPIO15 LRC (WS)
GPIO22 DIN
GND GND
5V VIN

Required Libraries

Make sure you install on Arduino IDE:

  • Arduino IDE
  • ESP32 Board Package
  • Library: ESP32-A2DP
  • Library: AudioTools

Code:

#include "AudioTools.h"
#include "BluetoothA2DPSink.h"

I2SStream i2s;
BluetoothA2DPSink a2dp_sink(i2s);

void setup() {
Serial.begin(115200);

// Configure I2S
auto cfg = i2s.defaultConfig();
cfg.pin_bck = 14; // BCLK
cfg.pin_ws = 15; // LRCLK
cfg.pin_data = 22; // DATA

i2s.begin(cfg);

// Start Bluetooth
a2dp_sink.start("MyMusic");
}

void loop() {
}

Uploading the Code

  • Connect ESP32 via USB
  • Select Board: ESP32 Dev Module
  • Choose correct COM port
  • Click Upload

Connecting Your Phone

  • Turn ON Bluetooth
  • Search for “MyMusic”
  • Connect to it
  • Play any song 

Your speaker should start playing audio wirelessly!

Leave a Reply

Your email address will not be published. Required fields are marked *