In this project, we will learn how to build a DIY MP3 player with ESP32, using the ESP32 Audio module, we can make an MP3 player with extra web radio and alarm clock function.

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, let's start!

1. Supplies:
1.1 Hardware:
• MakePython ESP32 (WROVER, you can get it from this link: 

• MakePython Audio (you can get it from this link: 
• Micro SD card
• USB cable
• Audio/headphones with 3.5mm audio connector

1.2 Software:
• Arduino IDE
• Download music (.mp3 or .wav) to the SD card.

2. Hardware Connection

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

3. Programming Environment

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

3.2 Install Library
• Adafruit SSD1306 and dependent libraries.
• 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.

4. About Code

4.1 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.

4.2 Web Radio
• You can get the code from the link:   
• Web radio needs to connect to the Internet, you need to change the WIFI information.

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)


4.3 Alarm Clock
• You can get the code from here:  
• Modify the alarm time in the following code:

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();


5. 3D Printed 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

6: 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.

7. Video show:
Check this video to learn how we build the ESP32 MP3 Player.


If you have any further questions or need some PCBA customizations based on those MakePython IoT boards, feel free to contact