ElectronicZoologyfield notes from the garage
Audio • ESP32

How to wire the
MAX98357A I2S amp
with ESP32

Amp: MAX98357A (3.2W mono class-D, I2S)
Board: ESP32 Dev Board (38-pin) or ESP32-C3
Goal: Confirm wiring and I2S are working
MAX98357A I2S Series - Step 1 of 4 - Wiring and tone test
✓ Confirmed Working

What You Need

Software

No audio tools needed for this step - the tone test generates a 440Hz sine wave in code.

How It Works

The MAX98357A is a digital I2S amplifier. It receives audio as a digital signal directly from the ESP32's I2S peripheral, converts it to analogue internally, and drives a speaker - all in one chip. No external DAC, no coupling capacitors, no decoupling capacitors. Just three signal wires and power.

I2S (Inter-IC Sound) carries three signals: a bit clock (BCLK), a word select line (LRCLK) that indicates left or right channel, and a serial data line (DIN). The ESP32 generates all three in hardware. The tone test sketch feeds a 440Hz sine wave directly into the I2S peripheral - no audio file, no conversion, just maths.

Why I2S and not the DAC? The ESP32 has DAC pins, but I2S is the better choice: the signal stays digital all the way to the amp, giving 16-bit resolution, no DC offset, and no noise pickup on the signal wire. The MAX98357A handles the digital-to-analogue conversion internally.

Wiring

MAX98357A PinESP32 Dev BoardESP32-C3Notes
VIN5V5V5V recommended - 3.3V works at lower volume
GNDGNDGND
LRCGPIO14GPIO5I2S word select (LRCLK)
BCLKGPIO27GPIO4I2S bit clock
DINGPIO13GPIO6I2S data out
SDNot connectedNot connectedLeave floating - amp enabled, mono mix of L+R
GAINNot connectedNot connectedLeave floating - 9dB gain

Connect your speaker to the two output terminals on the MAX98357A module. Polarity only affects phase - either orientation will produce sound. Use a speaker rated 1W or above.

No capacitors needed. The signal path is fully digital right up to the amp chip. Three signal wires and power is all you need.
Using an ESP32-C3? The pin numbers and board selection are different. See ESP32-C3 differences →

Tone Test

Flash this sketch. It generates a continuous 440Hz sine wave via I2S - no audio file needed. If you hear a tone, wiring and I2S are confirmed working and you are ready for Step 2.

/*
 * We stand on the shoulders of giants when we build
 * with knowledge gained from others' efforts.
 * That doesn't make us giants. Be humble.
 * Create with care. Open source is the way.
 *
 * MAX98357A I2S - Tone Test
 * --------------------------
 * Generates a 440Hz sine wave via I2S to confirm
 * wiring and amp are working. No audio file needed.
 *
 * Board:   ESP32 Dev Board (38-pin) or ESP32-C3
 * Amp:     MAX98357A
 *
 * Wiring (ESP32 Dev Board):
 *   VIN  -> 5V      GND  -> GND
 *   BCLK -> GPIO27  LRC  -> GPIO14
 *   DIN  -> GPIO13  SD   -> not connected
 *
 * Wiring (ESP32-C3):
 *   VIN  -> 5V      GND  -> GND
 *   BCLK -> GPIO4   LRC  -> GPIO5
 *   DIN  -> GPIO6   SD   -> not connected
 *
 * Open source - MIT Licence
 * Electronic Zoology - field notes from the garage
 * https://electroniczoology.com/guides/how-to-wire-max98357a-i2s-amp-esp32
 */

#include <driver/i2s.h>
#include <math.h>

// ESP32 Dev Board (38-pin)
#define I2S_BCLK   27
#define I2S_LRCLK  14
#define I2S_DOUT   13
// ESP32-C3 - comment out the three lines above and uncomment these:
//#define I2S_BCLK   4
//#define I2S_LRCLK  5
//#define I2S_DOUT   6

#define SAMPLE_RATE 44100
#define FREQUENCY   440
#define AMPLITUDE   20000
#define BUF_SIZE    256

int16_t buf[BUF_SIZE];

void setup() {
  i2s_config_t cfg = {
    .mode                 = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX),
    .sample_rate          = SAMPLE_RATE,
    .bits_per_sample      = I2S_BITS_PER_SAMPLE_16BIT,
    .channel_format       = I2S_CHANNEL_FMT_RIGHT_LEFT,
    .communication_format = I2S_COMM_FORMAT_STAND_I2S,
    .intr_alloc_flags     = ESP_INTR_FLAG_LEVEL1,
    .dma_buf_count        = 8,
    .dma_buf_len          = 64,
    .use_apll             = false,
    .tx_desc_auto_clear   = true,
  };
  i2s_pin_config_t pins = {
    .bck_io_num   = I2S_BCLK,
    .ws_io_num    = I2S_LRCLK,
    .data_out_num = I2S_DOUT,
    .data_in_num  = I2S_PIN_NO_CHANGE,
  };
  i2s_driver_install(I2S_NUM_0, &cfg, 0, NULL);
  i2s_set_pin(I2S_NUM_0, &pins);
}

void loop() {
  static uint32_t phase = 0;
  size_t written;

  for (int i = 0; i < BUF_SIZE; i += 2) {
    int16_t sample = (int16_t)(AMPLITUDE * sinf(2.0f * M_PI * FREQUENCY * phase / SAMPLE_RATE));
    buf[i]     = sample;
    buf[i + 1] = sample;
    phase++;
    if (phase >= SAMPLE_RATE) phase = 0;
  }

  i2s_write(I2S_NUM_0, buf, sizeof(buf), &written, portMAX_DELAY);
}
Tone confirmed - ready for Step 2. Once you hear the tone, move on to Step 2 - How to play audio from ESP32 with MAX98357A →
Prefer analogue audio? The How to play audio from ESP32 with PAM8403 guide covers a DAC-based alternative - no I2S required.
New board, not sure it works? How to check a new ESP32 → - confirm chip, flash, and RAM before wiring audio.