MAX98357A I2S 3W Class D Audio Amplifier DAC – Wiring, Code & Troubleshooting
The MAX98357A combines an I2S digital audio interface, DAC and mono Class D speaker amplifier on one compact module. It can be connected directly to a compatible Arduino board, ESP32, Raspberry Pi or other I2S source and used to drive a 4Ω or 8Ω speaker.
This guide focuses on the practical essentials: wiring the module, running a simple audio test and troubleshooting common problems.
MAX98357A Overview
The module needs three I2S signals: BCLK, LRC and DIN. Unlike some digital audio devices, the MAX98357A does not require an MCLK connection.
The MAX98357A uses a bridge-tied Class D output. Connect the speaker only between the + and − speaker terminals. Neither terminal is ground.
At 5V the MAX98357A is specified for up to 3.2W into 4Ω or 1.8W into 8Ω at 10% THD+N. Lower-distortion output is approximately 2.5W into 4Ω or 1.4W into 8Ω at 1% THD+N. Actual volume depends on supply voltage, speaker impedance and audio level.
Wiring
Module Pinout
| Pin | Function | Connect To |
|---|---|---|
| Vin | Amplifier power | 2.5–5.5V DC |
| GND | Power and signal ground | Controller GND |
| BCLK | I2S bit clock | I2S BCLK / SCK |
| LRC | I2S left/right clock | I2S LRCLK / WS / FS |
| DIN | Digital audio input | Controller I2S data output |
| GAIN | Gain selection | Leave at module default for first test |
| SD | Shutdown / channel selection | Leave at module default for first test |
| + / − | Speaker output | 4Ω or 8Ω speaker |
Arduino Wiring
Arduino provides an I2S library for its SAMD21-based boards. The official Arduino example covers the Arduino Zero, MKR family and Nano 33 IoT.
| MAX98357A | Arduino Zero | Arduino MKR | Nano 33 IoT |
|---|---|---|---|
| Vin | 5V | 5V | 5V |
| GND | GND | GND | GND |
| LRC | D0 | D3 | A2 |
| BCLK | D1 | D2 | A3 |
| DIN | D9 | A6 | D4 |
The ATmega328P-based UNO R3 does not provide the native I2S peripheral used by the Arduino example below. Use an I2S-capable Arduino board such as the Zero, a supported MKR board or Nano 33 IoT for this straightforward setup. Other Arduino families may support I2S, but their pins and software APIs can differ.
ESP32 Wiring
The following is a practical example for a conventional ESP32 development board. ESP32 I2S pins can be assigned in software, so other GPIO choices may also be used when suitable for the specific ESP32 board.
| MAX98357A | ESP32 | Function |
|---|---|---|
| Vin | 5V | Amplifier supply |
| GND | GND | Common ground |
| LRC | GPIO 25 | Word select |
| BCLK | GPIO 26 | Bit clock |
| DIN | GPIO 22 | Audio data output |
Raspberry Pi Wiring
For Raspberry Pi boards using the standard 40-pin GPIO connector:
| MAX98357A | Raspberry Pi | Physical Pin |
|---|---|---|
| Vin | 5V | 2 or 4 |
| GND | GND | 6 |
| BCLK | GPIO 18 / PCM_CLK | 12 |
| LRC | GPIO 19 / PCM_FS | 35 |
| DIN | GPIO 21 / PCM_DOUT | 40 |
The speaker amplifier can draw much more current than the digital circuitry. If the controller's 5V rail or USB supply cannot provide adequate current, use a suitable external 5V supply for Vin and connect its GND to the controller GND.
Code & Testing
Arduino Zero / MKR / Nano 33 IoT Test
In Arduino IDE, install the appropriate Arduino SAMD Boards package through Boards Manager. The I2S library is included with the SAMD core, so a separate MAX98357A library is not required.
Upload this sketch to generate a simple 440Hz square-wave test tone:
#include <I2S.h>
const int SAMPLE_RATE = 8000;
const int TONE_HZ = 440;
const int AMPLITUDE = 500;
const int HALF_PERIOD_SAMPLES =
SAMPLE_RATE / (TONE_HZ * 2);
int sample = AMPLITUDE;
int sampleCount = 0;
void setup() {
Serial.begin(9600);
Serial.println("MAX98357A I2S test");
if (!I2S.begin(I2S_PHILIPS_MODE, SAMPLE_RATE, 16)) {
Serial.println("Failed to initialise I2S!");
while (true) {
// Stop here if I2S could not start.
}
}
Serial.println("Playing 440 Hz test tone.");
}
void loop() {
if (sampleCount >= HALF_PERIOD_SAMPLES) {
sample = -sample;
sampleCount = 0;
}
// Send identical samples to the left and right I2S channels.
I2S.write(sample);
I2S.write(sample);
sampleCount++;
}
Expected Arduino Result
You should hear a continuous tone from the speaker. Sending the same sample to both I2S channels also makes this a useful first test regardless of whether the module is configured for the left channel, right channel or mono mix.
ESP32 Arduino Test
Install the current ESP32 by Espressif Systems board package in Arduino IDE. Current Arduino-ESP32 releases provide the ESP_I2S.h interface used below.
#include <ESP_I2S.h>
#include <math.h>
const int I2S_BCLK = 26;
const int I2S_LRC = 25;
const int I2S_DOUT = 22;
const uint32_t SAMPLE_RATE = 44100;
const float TONE_HZ = 440.0f;
const int16_t AMPLITUDE = 4000;
const float TWO_PI_F = 6.28318530718f;
I2SClass I2S;
void setup() {
Serial.begin(115200);
delay(500);
I2S.setPins(I2S_BCLK, I2S_LRC, I2S_DOUT);
if (!I2S.begin(
I2S_MODE_STD,
SAMPLE_RATE,
I2S_DATA_BIT_WIDTH_16BIT,
I2S_SLOT_MODE_STEREO)) {
Serial.println("Failed to initialise I2S!");
while (true) {
delay(1000);
}
}
Serial.println("Playing 440 Hz test tone.");
}
void loop() {
static float phase = 0.0f;
int16_t buffer[128 * 2];
for (int frame = 0; frame < 128; frame++) {
int16_t sample =
(int16_t)(sinf(phase) * AMPLITUDE);
// Same sample in left and right channels.
buffer[frame * 2] = sample;
buffer[frame * 2 + 1] = sample;
phase += TWO_PI_F * TONE_HZ / SAMPLE_RATE;
if (phase >= TWO_PI_F) {
phase -= TWO_PI_F;
}
}
I2S.write(
(uint8_t *)buffer,
sizeof(buffer)
);
}
Expected ESP32 Result
You should hear a steady 440Hz tone. The Serial Monitor at 115200 baud should show that the test has started.
Raspberry Pi Test
Raspberry Pi OS includes a MAX98357A device-tree overlay. On current Raspberry Pi OS installations, edit:
sudo nano /boot/firmware/config.txt
Add:
dtoverlay=max98357a
Save the file and reboot:
sudo reboot
After rebooting, check that the audio device has appeared:
aplay -l
Then run a test tone:
speaker-test -c2 -t sine -f 440
Expected Raspberry Pi Result
You should hear a test tone from the speaker. Press Ctrl+C to stop the test. Older Raspberry Pi OS releases may use /boot/config.txt instead of /boot/firmware/config.txt.
GAIN and SD Pins
For normal first-time testing, leave GAIN and SD at the module's existing configuration.
| GAIN Connection | MAX98357A Gain |
|---|---|
| 100kΩ to GND | 15dB |
| GND | 12dB |
| Floating | 9dB |
| Vin | 6dB |
| 100kΩ to Vin | 3dB |
SD is also the MAX98357A's channel-select input. Its voltage determines left-channel, right-channel or mono-mix operation, while pulling it low shuts the amplifier down. Breakout boards can include their own resistor network on this pin, so leave it at the module default unless you specifically need to change the channel or control shutdown.
Troubleshooting
No sound
- Check that Vin is between 2.5V and 5.5V.
- Confirm the amplifier and controller share a common GND.
- Check that LRC, BCLK and DIN have not been swapped.
- DIN must connect to the controller's I2S data output.
- Make sure the speaker is connected between + and −, not between an output and GND.
- Check that SD has not been pulled low, which shuts the amplifier down.
Arduino sketch will not compile
- Confirm the correct board is selected in Arduino IDE.
- Install the Arduino SAMD Boards package when using Zero, MKR or Nano 33 IoT.
- The classic UNO R3 does not support this SAMD hardware-I2S example.
- Other Arduino families can require a different I2S library or API.
Arduino tone test runs but there is no audio
- Use the fixed hardware I2S pins for the selected Arduino board.
- Zero: LRC D0, BCLK D1, DIN D9.
- MKR: LRC D3, BCLK D2, DIN A6.
- Nano 33 IoT: LRC A2, BCLK A3, DIN D4.
ESP32 tone test does not work
- Make sure the wiring matches the GPIO numbers in the sketch.
- Check that the selected GPIO pins are available on your particular ESP32 board.
- Confirm the current ESP32 by Espressif Systems board package is installed.
- Watch the Serial Monitor for an I2S initialisation error.
Audio is distorted at high volume
- Reduce the digital audio volume or sample amplitude.
- Check that the 5V supply remains stable while audio is playing.
- Avoid long, thin power wires when driving a speaker loudly.
- A 4Ω speaker places a heavier load on the amplifier than an 8Ω speaker.
- The headline 3.2W specification is measured at 10% THD+N, so lower-distortion usable power is less.
Controller resets when audio becomes loud
- The amplifier may be causing the supply voltage to dip.
- Use a power source with adequate current capacity.
- If necessary, power the amplifier from a separate regulated 5V source.
- Always connect the external supply GND to the controller GND.
Music is missing one stereo channel
- The MAX98357A is a mono amplifier.
- The SD / MODE voltage controls whether it reproduces the left channel, right channel or a mono combination.
- For simple mono applications, send the same audio to both I2S channels where practical.
Raspberry Pi does not show the amplifier
- Check that
dtoverlay=max98357ais in the active boot configuration file. - Reboot after editing the configuration.
- Run
aplay -land check whether a new playback device appears. - Run
dtoverlay -h max98357ato check the overlay supplied with the installed Raspberry Pi OS image.
MAX98357A breakout-board layouts and fitted resistor networks can vary between suppliers. Follow the labels printed on your module, keep Vin within 2.5–5.5V and never connect either bridge-tied speaker output to ground. Arduino I2S pins and software support also vary between board families, so use the wiring and library appropriate to the exact controller.