• Home
  • News
  • Using the MAX98357A with the ESP32-S3

Using the MAX98357A with the ESP32-S3

Cartoon ESP32 S3 connected to amplifier and speaker playing music while a sunglasses wearing camel dances happily in desert scene

The MAX98357A is a compact digital Class D amplifier that pairs perfectly with the ESP32-S3. It takes digital audio directly over I2S and drives a speaker without needing a separate DAC.

It is important not to confuse I2S with I2C. I2C is for small configuration data. I2S is a dedicated digital audio protocol. The ESP32-S3 sends audio using three pins:

• BCLK for timing each bit
• LRC to indicate left or right channel
• DIN for the actual audio data

No MCLK is required, which keeps wiring simple.

How the Amplifier Works

The MAX98357A converts incoming digital audio into a 330 kHz PWM signal. The speaker’s coil smooths this high frequency signal into audible sound.

Its outputs are bridge tied, meaning neither speaker terminal connects to ground. Always connect the speaker across the two output pins only.

Power and Output

The amplifier runs from 2.5 V to 5.5 V. Supplying 5 V gives higher output power, up to about 2.5 W into a 4 ohm speaker at low distortion.

If running at 5 V, ensure your power supply can handle around 650 mA.

Gain and SD Pins

The GAIN pin sets amplification level. The default is 9 dB when left floating. You can adjust it between 3 dB and 15 dB by connecting resistors to ground or Vin. A power cycle may be required after changing it.

The SD pin controls shutdown and channel selection. Different voltage levels select stereo mix, left only, right only, or full shutdown.

Together, the ESP32-S3 and MAX98357A form a simple, efficient digital audio solution ideal for robots, classroom builds, and embedded sound projects.

Parts List

Wire up the circuit

In order to run the project firstly the MAX98357A module needs to be connected as shown in the diagram below. The circuit diagram below is shown for clarity and the actual connection on the breadboard follow.

The circuit looks as shown below on the set up that was used to create this tutorial.

Running the Code

In order to get started you will need to follow this tutorial, which will ensure that your environment and ESP32 are configured correctly.

Next, you will need to find a sound to use. There are several free sites available for personal use:

The sound format will need to be in mono channel in WAV format, called sample.wav. You can change the name of the file at the bottom of the following code if required.

Now create a file called main.py on the ESP32-S3 with the following content.

Next, click the run button and you should hear the sound that you have uploaded through the speaker.

Main Topic

ESP32 microcontroller

Photo shows an ESP32 on breadboards atop a black mat, with jumper wires nearby and the title The ESP32 visible.

ESP32 microcontroller overview explains processing power memory wireless connectivity variants and compares it with Raspberry Pi Pico for practical projects

Other Tutorials in this Topic

Cartoon illustration of ESP32-S3 connected to small colour display showing Tinkimo logo on breadboard with simple wires and clean background

Controlling an ST7789 Display With an ESP32-S3

Learn how an ESP32-S3 drives an ST7789 colour display to show images smoothly using simple code and…

Cartoon robot happily learning ESP32 S3 programming with Thonny on laptop holding board at bright desk classroom scene simple friendly

Getting Started With The ESP32-S3

A friendly introduction to getting started with the ESP32 S3 using Thonny showing simple coding and playful…

Cartoon robot uses an ESP32 and ultrasonic sensor to measure distance to a cone with playful sound waves background illustration

Getting Started with an Ultrasonic Sensor Module on…

Learn how an ESP32 uses an ultrasonic sensor to measure distance using sound waves in simple beginner…

Cartoon penguin adjusts PWM speed dial controlling conveyor belt full of colorful fish using ESP32 and motor driver board

ESP32 Motor Control Using the L9110 Control Board

Learn how the ESP32 uses PWM and an H bridge motor driver to control motor speed and…

Cartoon zebra pushes small robot while oscilloscope shows encoder waveforms and laptop displays motor counts in workshop setting

Using a Motor Shaft Encoder With The ESP32

Explains quadrature encoders, state machines, decoder tables and interrupts to measure motor direction, distance travelled and wheel…