Arduino UNO R4 - Mini Mp3 Player Module

In this tutorial, you will learn how to use the DIYables Mini Mp3 Player module with the Arduino Uno R4 (both WiFi and Minima variants). We will cover:

Arduino Uno R4 Mini Mp3 Player

Overview of Mini Mp3 Player Module

The DIYables Mini Mp3 Player is a compact mp3 decoder module built around the YX5200-24SS chip. It plays mp3 files directly from a micro SD card and can drive a speaker (up to 3W) through its onboard amplifier, or output line-level audio via DAC pins for use with an external amplifier.

Communication happens over UART at 9600 baud, making it straightforward to control from any Arduino board. Key capabilities include:

  • Play, pause, resume, and stop
  • Volume adjustment from 0 to 30
  • Six equalizer presets: Normal, Pop, Rock, Jazz, Classic, Bass
  • Track looping, folder looping, full shuffle
  • Folder-based playback with numbered directories
  • Interrupt playback with advertisements
  • Query current track, volume, play state, and more

Module Pinout

Pin Description
VCC Power input (3.2V to 5.0V)
GND Ground
RX Serial data in — connect to Arduino TX through a 1K resistor
TX Serial data out — connect to Arduino RX
SPK_1 Speaker positive terminal (direct drive, 3W max)
SPK_2 Speaker negative terminal (direct drive, 3W max)
DAC_R Right channel line output (for external amplifier)
DAC_L Left channel line output (for external amplifier)
BUSY LOW during playback, HIGH when idle
IO_1 Short press = previous track, long press = volume down
IO_2 Short press = next track, long press = volume up
Mini Mp3 Player Pinout

Wiring Diagram

The Arduino Uno R4 operates at 5V logic, so a 1K resistor is required on the module's RX line to protect its 3.3V input.

Mini Mp3 Player Pin Arduino Uno R4 Pin Note
VCC 5V
GND GND
RX Pin 11 Via 1K resistor (required for 5V boards)
TX Pin 10
SPK_1 Speaker +
SPK_2 Speaker −
The wiring diagram between Arduino Uno R4 Mini Mp3 Player

This image is created using Fritzing. Click to enlarge image

See The best way to supply power to the Arduino Uno R4 and other components.

Tip: The Uno R4 has a hardware serial port (Serial1 on pins 0 and 1), but since pin 0/1 are shared with USB, using SoftwareSerial on pins 10/11 is the safer approach.

Preparing the SD Card

  1. Format the micro SD card as FAT16 or FAT32.
  2. Copy your mp3 files to the root directory using zero-padded names:
/001.mp3 /002.mp3 /003.mp3
  1. For folder-based playback, create numbered folders with numbered files:
/01/001.mp3 /01/002.mp3 /02/001.mp3

Key points:

  • Track numbering begins at 1, not 0.
  • The module determines track order by the sequence in which files are copied, not by filename. Always format the card first, then copy files one at a time in the desired order.
  • Folder names: 2-digit, zero-padded (01 through 99).
  • Filenames inside folders: 3-digit, zero-padded (001 through 255).

Installing the Library

  • Plug the Arduino Uno R4 into your computer using a USB-C cable.
  • Open the Arduino IDE and select the correct board and port.
  • Click the Libraries icon on the left sidebar.
  • Type "DIYables_MiniMp3" in the search box and locate the library by DIYables.
  • Click Install to add the latest version of the library.
Arduino Uno R4 Mini Mp3 Player library

This library has no external dependencies.

Arduino Uno R4 Code - Play a Single Track

The sketch below plays one mp3 track from the SD card.

/* * DIYables Mini Mp3 Player - Play One Track * * Product: DIYables Mini Mp3 Player Module * https://diyables.io/products/mini-mp3-player-module * * Tested with: * - Arduino Uno R3 * - Arduino Uno R4 WiFi / R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3 https://diyables.io/stem-v3 * - DIYables STEM V4 IoT https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT https://diyables.io/stem-v4b-iot * - DIYables STEM V4 Edu https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3 https://diyables.io/atmega2560-board * - DIYables Nano R3 https://diyables.io/nano-board * - DIYables ESP32 Board https://diyables.io/esp32-board * - DIYables ESP32 S3 (Uno) https://diyables.io/esp32-s3-uno * - Expected to work with other Arduino-compatible boards * * Plays track 001 once, then stops. * * Wiring (Arduino Uno R4): * Mini Mp3 RX -> Arduino Pin 11 (via 1K resistor) * Mini Mp3 TX -> Arduino Pin 10 * Mini Mp3 VCC -> 5V * Mini Mp3 GND -> GND * Speaker connected to SPK_1 and SPK_2 pins * * SD Card: Put mp3 files in root, named 001.mp3, 002.mp3, etc. */ #include <DIYables_MiniMp3.h> #include <SoftwareSerial.h> SoftwareSerial mp3Serial(10, 11); // RX, TX DIYables_MiniMp3 mp3; void setup() { Serial.begin(9600); mp3Serial.begin(9600); mp3.begin(mp3Serial); delay(1000); // Wait for the module to initialize mp3.setVolume(25); // Set volume (0 to 30) Serial.println("Playing track 1..."); mp3.play(1); // Play track 001.mp3 } void loop() { // Nothing to do here }

How To Run

  • Prepare an SD card with mp3 files (001.mp3, 002.mp3, etc.) and insert it in the module.
  • Wire the Mini Mp3 Player to the Uno R4 according to the wiring diagram above.
  • Connect the Uno R4 to your computer with a USB-C cable.
  • Open the Arduino IDE, choose Arduino Uno R4 WiFi (or Minima) as the board and select the correct port.
  • Paste the code above into the IDE editor.
  • Press Upload.

You should hear track 001.mp3 through the speaker.

Playback Functions at a Glance

Function What It Does Usage
play(trackNum) Starts a specific track mp3.play(1)
playNext() Skips to the next track mp3.playNext()
playPrevious() Goes back to the previous track mp3.playPrevious()
pause() Pauses the current track mp3.pause()
resume() Resumes a paused track mp3.resume()
stop() Stops playback entirely mp3.stop()

Arduino Uno R4 Code - Play Multiple Tracks in Sequence

This sketch plays several tracks one after another, with a configurable delay between each.

/* * DIYables Mini Mp3 Player - Play Multiple Tracks * * Product: DIYables Mini Mp3 Player Module * https://diyables.io/products/mini-mp3-player-module * * Tested with: * - Arduino Uno R3 * - Arduino Uno R4 WiFi / R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3 https://diyables.io/stem-v3 * - DIYables STEM V4 IoT https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT https://diyables.io/stem-v4b-iot * - DIYables STEM V4 Edu https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3 https://diyables.io/atmega2560-board * - DIYables Nano R3 https://diyables.io/nano-board * - DIYables ESP32 Board https://diyables.io/esp32-board * - DIYables ESP32 S3 (Uno) https://diyables.io/esp32-s3-uno * - Expected to work with other Arduino-compatible boards * * Plays tracks one after another with a delay between them. * * Wiring (Arduino Uno R4): * Mini Mp3 RX -> Arduino Pin 11 (via 1K resistor) * Mini Mp3 TX -> Arduino Pin 10 * Mini Mp3 VCC -> 5V * Mini Mp3 GND -> GND * Speaker connected to SPK_1 and SPK_2 pins * * SD Card: Put mp3 files in root, named 001.mp3, 002.mp3, 003.mp3 */ #include <DIYables_MiniMp3.h> #include <SoftwareSerial.h> SoftwareSerial mp3Serial(10, 11); // RX, TX DIYables_MiniMp3 mp3; int currentTrack = 1; int totalTracks = 3; // Change this to match your SD card unsigned long lastTrackTime = 0; unsigned long trackDuration = 5000; // Wait 5 seconds between tracks (adjust as needed) void setup() { Serial.begin(9600); mp3Serial.begin(9600); mp3.begin(mp3Serial); delay(1000); mp3.setVolume(20); Serial.println("Playing track 1..."); mp3.play(currentTrack); lastTrackTime = millis(); } void loop() { // After trackDuration, play the next track if (millis() - lastTrackTime >= trackDuration) { currentTrack++; if (currentTrack > totalTracks) currentTrack = 1; // Loop back to first track Serial.print("Playing track "); Serial.println(currentTrack); mp3.play(currentTrack); lastTrackTime = millis(); } }

How To Run

  • Make sure the SD card contains at least 3 tracks (001.mp3, 002.mp3, 003.mp3).
  • Upload the code to the Uno R4.

Tracks 1 through 3 will play in a repeating cycle with a 5-second gap.

Arduino Uno R4 Code - Volume Control with Buttons

Wire two push buttons to adjust volume up and down in real time.

/* * DIYables Mini Mp3 Player - Volume Control * * Product: DIYables Mini Mp3 Player Module * https://diyables.io/products/mini-mp3-player-module * * Tested with: * - Arduino Uno R3 * - Arduino Uno R4 WiFi / R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3 https://diyables.io/stem-v3 * - DIYables STEM V4 IoT https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT https://diyables.io/stem-v4b-iot * - DIYables STEM V4 Edu https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3 https://diyables.io/atmega2560-board * - DIYables Nano R3 https://diyables.io/nano-board * - DIYables ESP32 Board https://diyables.io/esp32-board * - DIYables ESP32 S3 (Uno) https://diyables.io/esp32-s3-uno * - Expected to work with other Arduino-compatible boards * * Use two buttons to increase/decrease the volume. * Press button on pin 2 to volume up, pin 3 to volume down. * * Wiring (Arduino Uno R4): * Mini Mp3 RX -> Arduino Pin 11 (via 1K resistor) * Mini Mp3 TX -> Arduino Pin 10 * Mini Mp3 VCC -> 5V * Mini Mp3 GND -> GND * Speaker connected to SPK_1 and SPK_2 pins * Button UP -> Pin 2 (other leg to GND) * Button DOWN -> Pin 3 (other leg to GND) * * SD Card: Put mp3 files in root, named 001.mp3, 002.mp3, etc. */ #include <DIYables_MiniMp3.h> #include <SoftwareSerial.h> SoftwareSerial mp3Serial(10, 11); // RX, TX DIYables_MiniMp3 mp3; const int BUTTON_VOL_UP = 2; const int BUTTON_VOL_DOWN = 3; int volume = 15; // Start at half volume void setup() { Serial.begin(9600); mp3Serial.begin(9600); pinMode(BUTTON_VOL_UP, INPUT_PULLUP); pinMode(BUTTON_VOL_DOWN, INPUT_PULLUP); mp3.begin(mp3Serial); delay(1000); mp3.setVolume(volume); mp3.loopTrack(1); // Play track 1 on repeat Serial.print("Volume: "); Serial.println(volume); } void loop() { // Volume Up button (pressed = LOW because of INPUT_PULLUP) if (digitalRead(BUTTON_VOL_UP) == LOW) { if (volume < 30) { volume++; mp3.setVolume(volume); Serial.print("Volume: "); Serial.println(volume); } delay(200); // Simple debounce } // Volume Down button if (digitalRead(BUTTON_VOL_DOWN) == LOW) { if (volume > 0) { volume--; mp3.setVolume(volume); Serial.print("Volume: "); Serial.println(volume); } delay(200); // Simple debounce } }

How To Run

  • Connect two buttons as described in the code comments, then upload.
  • Press the buttons while music plays to raise or lower the volume. The Serial Monitor shows the current level.

Volume Functions

Function What It Does Usage
setVolume(level) Sets volume directly (0–30) mp3.setVolume(25)
volumeUp() Raises volume by 1 mp3.volumeUp()
volumeDown() Lowers volume by 1 mp3.volumeDown()
getVolume() Returns the current volume mp3.getVolume()

Arduino Uno R4 Code - Next and Previous Track Buttons

Two buttons let you skip forward or backward through your playlist.

/* * DIYables Mini Mp3 Player - Next/Previous with Buttons * * Product: DIYables Mini Mp3 Player Module * https://diyables.io/products/mini-mp3-player-module * * Tested with: * - Arduino Uno R3 * - Arduino Uno R4 WiFi / R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3 https://diyables.io/stem-v3 * - DIYables STEM V4 IoT https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT https://diyables.io/stem-v4b-iot * - DIYables STEM V4 Edu https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3 https://diyables.io/atmega2560-board * - DIYables Nano R3 https://diyables.io/nano-board * - DIYables ESP32 Board https://diyables.io/esp32-board * - DIYables ESP32 S3 (Uno) https://diyables.io/esp32-s3-uno * - Expected to work with other Arduino-compatible boards * * Use two buttons to play next/previous tracks. * Displays the current track number on the Serial Monitor. * * Wiring (Arduino Uno R4): * Mini Mp3 RX -> Arduino Pin 11 (via 1K resistor) * Mini Mp3 TX -> Arduino Pin 10 * Mini Mp3 VCC -> 5V * Mini Mp3 GND -> GND * Speaker connected to SPK_1 and SPK_2 pins * Button NEXT -> Pin 2 (other leg to GND) * Button PREV -> Pin 3 (other leg to GND) * * SD Card: Put mp3 files in root, named 001.mp3, 002.mp3, etc. */ #include <DIYables_MiniMp3.h> #include <SoftwareSerial.h> SoftwareSerial mp3Serial(10, 11); // RX, TX DIYables_MiniMp3 mp3; const int BUTTON_NEXT = 2; const int BUTTON_PREV = 3; void setup() { Serial.begin(9600); mp3Serial.begin(9600); pinMode(BUTTON_NEXT, INPUT_PULLUP); pinMode(BUTTON_PREV, INPUT_PULLUP); mp3.begin(mp3Serial); delay(1000); mp3.setVolume(20); mp3.play(1); // Start with track 1 Serial.println("Press NEXT or PREV button to change track"); } void loop() { if (digitalRead(BUTTON_NEXT) == LOW) { Serial.println("Next track"); mp3.playNext(); delay(300); // Simple debounce } if (digitalRead(BUTTON_PREV) == LOW) { Serial.println("Previous track"); mp3.playPrevious(); delay(300); // Simple debounce } }

How To Run

  • Wire NEXT and PREV buttons to pins 2 and 3.
  • Upload the sketch and press the buttons to navigate tracks.

Arduino Uno R4 Code - Pause and Resume Toggle

A single button toggles playback between paused and playing.

/* * DIYables Mini Mp3 Player - Pause and Resume * * Product: DIYables Mini Mp3 Player Module * https://diyables.io/products/mini-mp3-player-module * * Tested with: * - Arduino Uno R3 * - Arduino Uno R4 WiFi / R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3 https://diyables.io/stem-v3 * - DIYables STEM V4 IoT https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT https://diyables.io/stem-v4b-iot * - DIYables STEM V4 Edu https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3 https://diyables.io/atmega2560-board * - DIYables Nano R3 https://diyables.io/nano-board * - DIYables ESP32 Board https://diyables.io/esp32-board * - DIYables ESP32 S3 (Uno) https://diyables.io/esp32-s3-uno * - Expected to work with other Arduino-compatible boards * * Demonstrates pausing and resuming playback using a single button. * Press the button to toggle between pause and resume. * * Wiring (Arduino Uno R4): * Mini Mp3 RX -> Arduino Pin 11 (via 1K resistor) * Mini Mp3 TX -> Arduino Pin 10 * Mini Mp3 VCC -> 5V * Mini Mp3 GND -> GND * Speaker connected to SPK_1 and SPK_2 pins * Button -> Pin 2 (other leg to GND) * * SD Card: Put mp3 files in root, named 001.mp3, 002.mp3, etc. */ #include <DIYables_MiniMp3.h> #include <SoftwareSerial.h> SoftwareSerial mp3Serial(10, 11); // RX, TX DIYables_MiniMp3 mp3; const int BUTTON_PIN = 2; bool paused = false; void setup() { Serial.begin(9600); mp3Serial.begin(9600); pinMode(BUTTON_PIN, INPUT_PULLUP); mp3.begin(mp3Serial); delay(1000); mp3.setVolume(20); mp3.play(1); Serial.println("Playing. Press button to pause/resume."); } void loop() { if (digitalRead(BUTTON_PIN) == LOW) { if (paused) { mp3.resume(); Serial.println("Resumed"); } else { mp3.pause(); Serial.println("Paused"); } paused = !paused; delay(300); // Simple debounce } }

How To Run

  • Wire a button to pin 2, then upload.
  • Press the button once to pause, press again to resume.

Arduino Uno R4 Code - Loop a Track

This sketch repeats a single track endlessly.

/* * DIYables Mini Mp3 Player - Loop Track * * Product: DIYables Mini Mp3 Player Module * https://diyables.io/products/mini-mp3-player-module * * Tested with: * - Arduino Uno R3 * - Arduino Uno R4 WiFi / R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3 https://diyables.io/stem-v3 * - DIYables STEM V4 IoT https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT https://diyables.io/stem-v4b-iot * - DIYables STEM V4 Edu https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3 https://diyables.io/atmega2560-board * - DIYables Nano R3 https://diyables.io/nano-board * - DIYables ESP32 Board https://diyables.io/esp32-board * - DIYables ESP32 S3 (Uno) https://diyables.io/esp32-s3-uno * - Expected to work with other Arduino-compatible boards * * Loops (repeats) a track continuously with EQ setting. * * Wiring (Arduino Uno R4): * Mini Mp3 RX -> Arduino Pin 11 (via 1K resistor) * Mini Mp3 TX -> Arduino Pin 10 * Mini Mp3 VCC -> 5V * Mini Mp3 GND -> GND * Speaker connected to SPK_1 and SPK_2 pins * * SD Card file structure: * /001.mp3 * /002.mp3 * ... */ #include <DIYables_MiniMp3.h> #include <SoftwareSerial.h> SoftwareSerial mp3Serial(10, 11); // RX, TX DIYables_MiniMp3 mp3; void setup() { Serial.begin(9600); mp3Serial.begin(9600); mp3.begin(mp3Serial); delay(1000); // Wait for the module to initialize mp3.setVolume(25); // Volume: 0 to 30 mp3.setEQ(DIYables_MiniMp3::EQ_NORMAL); Serial.println("Playing track 1 on loop..."); mp3.loopTrack(1); } void loop() { // Your code here }

How To Run

  • Upload the code. Track 001.mp3 will loop continuously.

Repeat and Shuffle Functions

Function What It Does Usage
loopTrack(trackNum) Repeats one track forever mp3.loopTrack(1)
loopFolder(folder) Repeats every track in a folder mp3.loopFolder(1)
loopAll() Repeats all tracks on the card mp3.loopAll()
stopLoop() Cancels any active loop mp3.stopLoop()
shuffle() Plays all tracks in random order mp3.shuffle()

Arduino Uno R4 Code - Play from a Folder

Play tracks from specific numbered folders on the SD card.

/* * DIYables Mini Mp3 Player - Play from Folder * * Product: DIYables Mini Mp3 Player Module * https://diyables.io/products/mini-mp3-player-module * * Tested with: * - Arduino Uno R3 * - Arduino Uno R4 WiFi / R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3 https://diyables.io/stem-v3 * - DIYables STEM V4 IoT https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT https://diyables.io/stem-v4b-iot * - DIYables STEM V4 Edu https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3 https://diyables.io/atmega2560-board * - DIYables Nano R3 https://diyables.io/nano-board * - DIYables ESP32 Board https://diyables.io/esp32-board * - DIYables ESP32 S3 (Uno) https://diyables.io/esp32-s3-uno * - Expected to work with other Arduino-compatible boards * * Plays tracks from specific folders on the SD card. * * Wiring (Arduino Uno R4): * Mini Mp3 RX -> Arduino Pin 11 (via 1K resistor) * Mini Mp3 TX -> Arduino Pin 10 * Mini Mp3 VCC -> 5V * Mini Mp3 GND -> GND * Speaker connected to SPK_1 and SPK_2 pins * * SD Card file structure: * /01/001.mp3 <- playFolder(1, 1) * /01/002.mp3 <- playFolder(1, 2) * /02/001.mp3 <- playFolder(2, 1) * /02/002.mp3 <- playFolder(2, 2) * * IMPORTANT: * - Numbering starts from 1, NOT 0 * - Folder names must be 2-digit zero-padded (01-99) * - Track names must be 3-digit zero-padded (001-255) * - Format SD card as FAT32, then copy files one by one in order * - Track order is determined by the order files were copied, * NOT by filename. So copy them in the correct sequence. */ #include <DIYables_MiniMp3.h> #include <SoftwareSerial.h> SoftwareSerial mp3Serial(10, 11); // RX, TX DIYables_MiniMp3 mp3; void setup() { Serial.begin(9600); mp3Serial.begin(9600); mp3.begin(mp3Serial); delay(1000); mp3.setVolume(20); // Play track 1 from folder 01 Serial.println("Playing folder 01, track 001..."); mp3.playFolder(1, 1); delay(5000); // Play track 2 from folder 01 Serial.println("Playing folder 01, track 002..."); mp3.playFolder(1, 2); delay(5000); // Play track 1 from folder 02 Serial.println("Playing folder 02, track 001..."); mp3.playFolder(2, 1); } void loop() { // Nothing to do here }

How To Run

  • Set up the SD card with folders (01, 02) containing numbered files (001.mp3, 002.mp3).
  • Upload the sketch. It plays tracks from folder 01 then folder 02.

Folder Playback Functions

Function What It Does Usage
playFolder(folder, track) Plays a track from a folder (up to 99 folders, 255 tracks) mp3.playFolder(1, 1)
playLargeFolder(folder, track) Plays from a folder (up to 15 folders, 3000 tracks) mp3.playLargeFolder(1, 1500)
playFromMP3Folder(trackNum) Plays from the /mp3 folder mp3.playFromMP3Folder(1)

Arduino Uno R4 Code - Serial Monitor Control

Type single-character commands in the Serial Monitor to control every aspect of playback. No extra hardware needed.

/* * DIYables Mini Mp3 Player - Serial Command Control * * Product: DIYables Mini Mp3 Player Module * https://diyables.io/products/mini-mp3-player-module * * Tested with: * - Arduino Uno R3 * - Arduino Uno R4 WiFi / R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3 https://diyables.io/stem-v3 * - DIYables STEM V4 IoT https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT https://diyables.io/stem-v4b-iot * - DIYables STEM V4 Edu https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3 https://diyables.io/atmega2560-board * - DIYables Nano R3 https://diyables.io/nano-board * - DIYables ESP32 Board https://diyables.io/esp32-board * - DIYables ESP32 S3 (Uno) https://diyables.io/esp32-s3-uno * - Expected to work with other Arduino-compatible boards * * Control the Mp3 player by typing commands in the Serial Monitor. * Great for testing all functions without extra hardware. * * Commands (type in Serial Monitor, then press Enter): * 1-9 Play track 1 to 9 * + Volume up * - Volume down * p Pause * r Resume * s Stop * n Next track * b Previous track (back) * ? Show current status * * Wiring (Arduino Uno R4): * Mini Mp3 RX -> Arduino Pin 11 (via 1K resistor) * Mini Mp3 TX -> Arduino Pin 10 * Mini Mp3 VCC -> 5V * Mini Mp3 GND -> GND * Speaker connected to SPK_1 and SPK_2 pins * * SD Card: Put mp3 files in root, named 001.mp3, 002.mp3, etc. */ #include <DIYables_MiniMp3.h> #include <SoftwareSerial.h> SoftwareSerial mp3Serial(10, 11); // RX, TX DIYables_MiniMp3 mp3; void setup() { Serial.begin(9600); mp3Serial.begin(9600); mp3.begin(mp3Serial); delay(1000); mp3.setVolume(20); Serial.println("=== DIYables Mini Mp3 Player ==="); Serial.println("Commands:"); Serial.println(" 1-9 Play track number"); Serial.println(" + Volume up"); Serial.println(" - Volume down"); Serial.println(" p Pause"); Serial.println(" r Resume"); Serial.println(" s Stop"); Serial.println(" n Next track"); Serial.println(" b Previous track"); Serial.println(" ? Show status"); Serial.println("================================"); } void loop() { if (Serial.available()) { char cmd = Serial.read(); switch (cmd) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': Serial.print("Playing track "); Serial.println(cmd - '0'); mp3.play(cmd - '0'); break; case '+': Serial.println("Volume up"); mp3.volumeUp(); break; case '-': Serial.println("Volume down"); mp3.volumeDown(); break; case 'p': Serial.println("Paused"); mp3.pause(); break; case 'r': Serial.println("Resumed"); mp3.resume(); break; case 's': Serial.println("Stopped"); mp3.stop(); break; case 'n': Serial.println("Next track"); mp3.playNext(); break; case 'b': Serial.println("Previous track"); mp3.playPrevious(); break; case '?': { Serial.println("--- Status ---"); int16_t vol = mp3.getVolume(); Serial.print("Volume: "); Serial.println(vol); int16_t track = mp3.getCurrentTrack(); Serial.print("Current track: "); Serial.println(track); bool playing = mp3.isPlaying(); Serial.print("Playing: "); Serial.println(playing ? "Yes" : "No"); int16_t total = mp3.getTrackCount(); Serial.print("Total tracks: "); Serial.println(total); Serial.println("--------------"); break; } default: break; } } }

How To Run

  • Upload the code, then open the Serial Monitor at 9600 baud.
  • Enter any command from the table below:
Key Action
1–9 Play track number 1 through 9
+ Turn volume up
Turn volume down
p Pause playback
r Resume playback
s Stop playback
n Skip to next track
b Go back to previous track
? Print current status

Equalizer Modes

Six built-in EQ presets are available:

Constant ID Sound Profile
DIYables_MiniMp3EQ_NORMAL 0 Flat / neutral
DIYables_MiniMp3EQ_POP 1 Pop
DIYables_MiniMp3EQ_ROCK 2 Rock
DIYables_MiniMp3EQ_JAZZ 3 Jazz
DIYables_MiniMp3EQ_CLASSIC 4 Classical
DIYables_MiniMp3EQ_BASS 5 Bass emphasis
mp3.setEQ(DIYables_MiniMp3::EQ_ROCK);

Querying Playback Status

The following functions let you read the module's state at runtime. Each call blocks for up to 100 ms while waiting for a reply. A return value of −1 indicates an error or timeout.

Function Return Type Description
isPlaying() bool true while a track is actively playing
getVolume() int16_t Current volume level (0–30)
getEQ() int16_t Active EQ preset (0–5)
getTrackCount() int16_t Number of tracks on the SD card
getCurrentTrack() int16_t Track number currently playing
getFolderCount() int16_t Number of folders on the SD card
getTrackCountInFolder(folder) int16_t Tracks inside a specific folder

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!