ESP32 - Mini Mp3 Player Module
The ESP32 is a versatile 3.3V microcontroller with WiFi, Bluetooth, and multiple hardware serial ports. Combined with the DIYables Mini Mp3 Player module, you can build anything from a simple sound effect board to a WiFi-controlled jukebox.
This tutorial walks you through:
- Connecting the Mini Mp3 Player to an ESP32 — directly, without a resistor.
- Loading mp3 files onto the SD card correctly.
- Playing, pausing, resuming, stopping, and skipping tracks.
- Adjusting volume with physical buttons.
- Repeating tracks, shuffling, and organizing audio into folders.
- Monitoring playback status from your code.

Components Needed
Or you can buy the following kits:
| 1 | × | DIYables ESP32 Starter Kit (ESP32 included) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
No resistor required. The ESP32 operates at 3.3V — the same voltage the Mini Mp3 Player's UART expects.
The Mini Mp3 Player Module
The DIYables Mini Mp3 Player is a tiny board built on the YX5200-24SS chip. It decodes mp3 files from a micro SD card, and can directly drive a speaker through its built-in 3W amplifier. Alternatively, use the DAC pins to feed an external amplifier for louder output.
Everything is controlled via serial commands at 9600 baud:
- Transport: play, pause, resume, stop, next, previous
- Volume: 31 levels (0–30)
- Equalizer: Normal, Pop, Rock, Jazz, Classic, Bass
- Repeat: loop single track, loop folder, loop all tracks, random shuffle
- Folders: play from numbered directories on the card
- Advertisements: temporarily interrupt playback, then continue
- Queries: read track number, volume, play state, track count
Pin Description
| Pin | Purpose |
|---|---|
| VCC | 3.2V to 5.0V power input |
| GND | Ground |
| RX | Serial data input (connect to ESP32 TX pin) |
| TX | Serial data output (connect to ESP32 RX pin) |
| SPK_1 | Speaker + (built-in amp, 3W max) |
| SPK_2 | Speaker − |
| DAC_R | Right channel line output |
| DAC_L | Left channel line output |
| BUSY | LOW = playing, HIGH = stopped |
| IO_1 | Short press → prev track; long press → vol down |
| IO_2 | Short press → next track; long press → vol up |

Wiring
The ESP32 uses 3.3V logic natively, so you wire the serial lines directly — no level shifting or resistors needed.
We recommend using Serial2 (available by default on most ESP32 DevKit boards):
| Mini Mp3 Player | ESP32 | Notes |
|---|---|---|
| VCC | 3.3V | Or 5V from VIN if available |
| GND | GND | |
| RX | GPIO 17 (TX2) | Direct connection |
| TX | GPIO 16 (RX2) | Direct connection |
| SPK_1 | Speaker + | |
| SPK_2 | Speaker − |

This image is created using Fritzing. Click to enlarge image
Tip: If your ESP32 variant does not expose GPIO 16/17 (some DevKit-C V4 boards use them for PSRAM), you can reassign Serial2 pins in code:
If you're unfamiliar with how to supply power to the ESP32 and other components, you can find guidance in the following tutorial: The best way to Power ESP32 and sensors/displays.
Getting the SD Card Ready
- Format as FAT16 or FAT32.
- Place mp3 files at the root:
- For organized playback, use numbered folders:
Critical notes:
- Track numbers start at 1.
- The module indexes tracks by the order they were copied to the card, not by filename. Always format first, then copy sequentially.
- Folder names: 01–99 (2-digit), file names: 001–255 (3-digit).
Installing the Library
- Connect the ESP32 to your computer.
- In the Arduino IDE, select your ESP32 board variant and the correct port.
- Open the Libraries manager.
- Search "DIYables_MiniMp3" and install the library by DIYables.

Zero dependencies — works out of the box.
Starter Code Template
ESP32 Code — Play a Track
Try It
- Load the SD card, wire the module, connect the ESP32 via USB.
- Select your ESP32 board in the IDE and upload.
Playback Control
| Method | What Happens | Code Example |
|---|---|---|
| play(n) | Plays track number n | mp3.play(1) |
| playNext() | Moves to the next track | mp3.playNext() |
| playPrevious() | Goes back one track | mp3.playPrevious() |
| pause() | Freezes playback | mp3.pause() |
| resume() | Picks up where you left off | mp3.resume() |
| stop() | Ends playback completely | mp3.stop() |
ESP32 Code — Multiple Tracks
ESP32 Code — Next/Previous
ESP32 Code — Pause/Resume
ESP32 Code — Loop a Track
Repeat & Shuffle
| Method | Behavior | Example |
|---|---|---|
| loopTrack(n) | Endlessly repeat track n | mp3.loopTrack(1) |
| loopFolder(f) | Repeat all tracks in folder f | mp3.loopFolder(1) |
| loopAll() | Repeat all tracks | mp3.loopAll() |
| stopLoop() | Cancel active loop | mp3.stopLoop() |
| shuffle() | Randomize playback | mp3.shuffle() |
ESP32 Code — Folder Playback
Folder API
| Method | Description | Example |
|---|---|---|
| playFolder(f, t) | Play track t from folder f | mp3.playFolder(1, 1) |
| playLargeFolder(f, t) | Large folder (15 folders, 3000 tracks) | mp3.playLargeFolder(1, 2000) |
| playFromMP3Folder(t) | Play from /mp3 folder | mp3.playFromMP3Folder(1) |
ESP32 Code — Serial Monitor Control
| Command | Effect |
|---|---|
| 1–9 | Play track |
| + / − | Volume |
| p / r / s | Pause / Resume / Stop |
| n / b | Next / Previous |
| ? | Status |
Equalizer Options
| Constant | ID | Character | ||
|---|---|---|---|---|
| DIYables_MiniMp3 | EQ_NORMAL | 0 | Neutral | |
| DIYables_MiniMp3 | EQ_POP | 1 | Bright | |
| DIYables_MiniMp3 | EQ_ROCK | 2 | Punchy | |
| DIYables_MiniMp3 | EQ_JAZZ | 3 | Warm | |
| DIYables_MiniMp3 | EQ_CLASSIC | 4 | Balanced | |
| DIYables_MiniMp3 | EQ_BASS | 5 | Deep |
Checking Module Status
These functions block for up to 100 ms while waiting for the module's reply. They return −1 if no response arrives.
| Function | Return | Description |
|---|---|---|
| isPlaying() | bool | true during active playback |
| getVolume() | int16_t | Current volume (0–30) |
| getEQ() | int16_t | Active EQ (0–5) |
| getTrackCount() | int16_t | Total tracks on SD |
| getCurrentTrack() | int16_t | Track number playing now |
| getFolderCount() | int16_t | Total folders on SD |
| getTrackCountInFolder(f) | int16_t | Tracks in folder f |