Arduino Nano ESP32 - Mini Mp3 Player Module
The Arduino Nano ESP32 is a powerful 3.3V board with built-in WiFi and Bluetooth. In this tutorial, we will pair it with the DIYables Mini Mp3 Player module to build a fully controllable mp3 player. Here is what we will go through:
- Connecting the module to the Nano ESP32 — no resistor needed thanks to 3.3V logic levels.
- Preparing the SD card with properly named mp3 files.
- Writing code to play, pause, resume, stop, and skip tracks.
- Controlling volume through buttons and serial commands.
- Setting up track looping, full shuffle, and folder-based playback.
- Reading the module's status (current track, volume, play state).

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (30 sensors/displays) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Note: No 1K resistor is needed — the Nano ESP32 uses 3.3V logic, which matches the module natively.
Mini Mp3 Player Module Overview
The DIYables Mini Mp3 Player is a self-contained mp3 decoder module powered by the YX5200-24SS chip. Insert a micro SD card with mp3 files, connect a small speaker, and send serial commands to control playback.
The module accepts 9600 baud UART commands and provides these features:
- Full playback control: play, pause, resume, stop, next, previous
- 31 volume levels (0 through 30)
- 6 equalizer presets (Normal, Pop, Rock, Jazz, Classic, Bass)
- Repeat modes: single track loop, folder loop, loop all, shuffle
- Folder-organized playback for categorized audio
- Advertisement insertion (interrupt and resume)
- Real-time status queries
Pinout
| Pin | Function |
|---|---|
| VCC | 3.2V to 5.0V power supply |
| GND | Ground |
| RX | UART input (connect to board TX) |
| TX | UART output (connect to board RX) |
| SPK_1 | Speaker + (onboard 3W amplifier) |
| SPK_2 | Speaker − |
| DAC_R | Right line-level output |
| DAC_L | Left line-level output |
| BUSY | LOW = playing, HIGH = idle |
| IO_1 | Short press → previous, long press → volume down |
| IO_2 | Short press → next, long press → volume up |

Wiring Diagram
The Nano ESP32 operates at 3.3V logic — the same voltage the Mini Mp3 Player uses internally. This means you can connect TX/RX directly without any resistor.
We will use Serial1 on the Nano ESP32 for communication with the module, keeping the default Serial free for the Serial Monitor.
| Mini Mp3 Player | Arduino Nano ESP32 | Notes |
|---|---|---|
| VCC | 3.3V | Module also accepts 5V from VBUS if needed |
| GND | GND | |
| RX | TX1 (D5) | Direct connection — no resistor needed |
| TX | RX1 (D4) | Direct connection |
| SPK_1 | Speaker + | |
| SPK_2 | Speaker − |

This image is created using Fritzing. Click to enlarge image
SD Card Setup
Prepare the micro SD card before inserting it into the module:
- Format as FAT16 or FAT32.
- Copy mp3 files to the root with zero-padded names:
For folder playback:
Remember:
- Track numbering starts at 1 (not 0).
- The module determines track order from the copy sequence, not filenames. Format the card first, then copy files individually in order.
- Folder names: 2 digits, zero-padded (01–99). File names inside: 3 digits, zero-padded (001–255).
Library Installation
- Connect the Nano ESP32 to your computer via USB-C.
- Open the Arduino IDE, select Arduino Nano ESP32 as your board, and choose the correct port.
- Go to the Libraries panel on the left.
- Search for "DIYables_MiniMp3" and install the library by DIYables.
- Click Install.

The library has zero external dependencies.
Nano ESP32 Code — Basic Template
Since the Nano ESP32 has hardware serial ports, we use Serial1 instead of SoftwareSerial:
No SoftwareSerial library needed! Hardware serial is more reliable, especially at the low 9600 baud rate this module uses.
Nano ESP32 Code — Play a Single Track
How To Test
- Load the SD card with mp3 files and insert it into the module.
- Wire the module to the Nano ESP32 as shown above (no resistor!).
- Connect the board via USB-C, select Arduino Nano ESP32, and upload.
You should hear track 001.mp3 through the connected speaker.
Playback Commands
| Method | Purpose | Example |
|---|---|---|
| play(trackNum) | Start a specific track | mp3.play(1) |
| playNext() | Advance to the next track | mp3.playNext() |
| playPrevious() | Go to the previous track | mp3.playPrevious() |
| pause() | Pause the active track | mp3.pause() |
| resume() | Unpause the track | mp3.resume() |
| stop() | Halt playback | mp3.stop() |
Nano ESP32 Code — Play Multiple Tracks
How To Test
- Ensure the SD card has at least 3 tracks. Upload, and the tracks will rotate every 5 seconds.
Nano ESP32 Code — Volume Control
How To Test
- Wire two buttons, upload the sketch, and press buttons while music plays.
Volume Commands
| Method | Purpose | Example |
|---|---|---|
| setVolume(v) | Jump to a specific volume level | mp3.setVolume(20) |
| volumeUp() | Increase by 1 step | mp3.volumeUp() |
| volumeDown() | Decrease by 1 step | mp3.volumeDown() |
| getVolume() | Query the current level | mp3.getVolume() |
Nano ESP32 Code — Pause/Resume Toggle
Nano ESP32 Code — Loop a Track
Repeat & Shuffle Commands
| Method | Purpose | Example |
|---|---|---|
| loopTrack(t) | Keep replaying one track | mp3.loopTrack(1) |
| loopFolder(f) | Replay all tracks in a folder | mp3.loopFolder(1) |
| loopAll() | Replay everything on the card | mp3.loopAll() |
| stopLoop() | End the current repeat mode | mp3.stopLoop() |
| shuffle() | Randomize playback order | mp3.shuffle() |
Nano ESP32 Code — Play from Folder
Folder Methods
| Method | Purpose | Example |
|---|---|---|
| playFolder(f, t) | Select track t from folder f | mp3.playFolder(1, 1) |
| playLargeFolder(f, t) | Large folder mode (up to 3000 tracks) | mp3.playLargeFolder(1, 1500) |
| playFromMP3Folder(t) | Access the special /mp3 folder | mp3.playFromMP3Folder(1) |
Nano ESP32 Code — Serial Monitor Control
Serial Commands
| Input | Result |
|---|---|
| 1–9 | Play that track |
| + / − | Volume up / down |
| p | Pause |
| r | Resume |
| s | Stop |
| n | Next track |
| b | Previous track |
| ? | Display status |
Equalizer Presets
| Constant | ID | Tone | ||
|---|---|---|---|---|
| DIYables_MiniMp3 | EQ_NORMAL | 0 | Neutral | |
| DIYables_MiniMp3 | EQ_POP | 1 | Pop | |
| DIYables_MiniMp3 | EQ_ROCK | 2 | Rock | |
| DIYables_MiniMp3 | EQ_JAZZ | 3 | Jazz | |
| DIYables_MiniMp3 | EQ_CLASSIC | 4 | Classical | |
| DIYables_MiniMp3 | EQ_BASS | 5 | Bass boost |
Status Query Functions
Each query blocks for up to 100 ms. Returns −1 on timeout.
| Method | Returns | Info |
|---|---|---|
| isPlaying() | bool | Whether a track is active |
| getVolume() | int16_t | Volume (0–30) |
| getEQ() | int16_t | EQ preset (0–5) |
| getTrackCount() | int16_t | Total tracks on card |
| getCurrentTrack() | int16_t | Currently playing track |
| getFolderCount() | int16_t | Number of folders |
| getTrackCountInFolder(f) | int16_t | Tracks in folder f |