Introduction: ESP32 Audio Player

Due to the epidemic, I spent more time at home than usual in the past six months. It is inevitable that a person would be bored at home, so I made an audio player with ESP32 to pass the time. ESP32 can be used as an independent system to run applications, just plug in the cable, power the device, and program it. With downloading different programs, the player can realize SD card playing music function, Internet radio function, and music alarm clock function.

Now I want to show my results and tell you how to do it.



  1. MakePython ESP32 (WROVER, you can get it from this link:
  2. MakePython Audio (you can get it from this link:
  3. Micro SD card
  4. USB cable
  5. Audio/headphones with 3.5mm audio connector


  1. Arduino IDE
  2. Download music (.mp3 or .wav) to the SD card.

Step 1: Connection

  • Connect two boards according to the pins. The VCC is connected to 3v3.

Step 2: Programming Environment

  • ESP32 Support

Follow the Installation Instructions to add ESP32 support if you are not yet doing it:

  • Install Library
  1. Adafruit SSD1306 and dependent libraries.
  2. ESP32-audioI2S.

You can get the zip file from the Github:

Unzip this file. Open your Arduino IDE and navigate to Sketch > Include Library > Manage Libraries > Add .ZIP Library.

Then open the folder: "\Project_MakePython_Audio_Music\old-src\esp32_mp3\ESP32-audioI2S". And you will see a prompt that the library installed successfully.

Step 3: About Code

Audio Play

  • Open file "/Project_MakePython_Audio_Music/music_player.ino". You can get the code from Github:
  • Notice: MicroPython Audio can be downloaded without unplugging. When uploading the program, please rotate the switch next to the 3.5mm Audio interface to the Audio socket for downloading successfully.

  • Modify or add text in the display.

void lcd_text(String text)
  • Change the initial volume:
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(14); // 0...21
  • Switch songs:
if (digitalRead(Pin_next) == 0)
if (file_index < file_num - 1)
file_index = 0;
button_time = millis();
if (digitalRead(Pin_previous) == 0)
if (file_index > 0)
file_index = file_num - 1;
button_time = millis();
  • Upload the code.

Web Radio

const char *ssid = "Makerfabs";
const char *password = "20160704";
  • Add, delete or modify the radio address in the following code:

String stations[] = {
"", // 128k aac
  • Connect to the web radio station:

void open_new_radio(String station)


const char *ntpServer = "";
const long gmtOffset_sec = 8 * 60 * 60; //China+8
const int daylightOffset_sec = 0;
String clock_time = "17:39:00";
String clock_time2 = "17:42:00";
  • Init and get the time,and the “gmtOffset” is used to set the time zone.
//init and get the time
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
Serial.println(F("Alread get npt time."));
  • Modify the alarm clock music:
void loop()
if (millis() - button_time > 600)
if (alarm_flag == 0)
if (showtime() != 0)
alarm_flag = 1;
display.setCursor(0, 24);
button_time = millis();

Step 4: Case

  • The case can be obtained from:

  • 3D design

design the case as you like. If don’t want to design it temporarily, you can get the design file from here:

  • 3D printing

Transfer your print files to the printer using an SD card. 3D printing can complete the production of the case quickly.

  • Assembly

Assembling the case and the two boards, and you can get a new audio player.

Step 5: Operation

  • Power the ESP32 via Micro USB and the LCD screen displays the basic information of the song.
  • The lower left switch can switch songs or radio channel, and press inward to pause playback.
  • The switch on the left can increase or decrease the volume, press inward to mute or stop the alarm.

Step 6: Show