Arduino - MP3 Player
In this tutorial, we will learn how to make a MP3 player using Arduino, MP3 player module, Micro SD Card, and speaker. The MP3 files (music, or recorded audio) are stored in the micro SD Card. Then, Arduino can control the MP3 player module to read a selected song from SD Car, convert it to audio signal, snd send the signal to the speaker. In detail, we will learn:
How it works
How to connect speaker, MP3 player modules to Arduino
How to program Arduino to play a song stored in the micro SD Card
How to add the play/pause/next/previous buttons
Then, you can modify the code to add a potentiometer or rotatry encoder to change the volume.
Or you can buy the following sensor kit:
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.
A serial MP3 player module has three interfaces:
The interface to Arduino includes 4 pins:
RX pin: data pin, needs to be connected a TX pin of Arduino (Hardware or Software Serial)
TX pin: data pin, needs to be connected a RX pin of Arduino (Hardware or Software Serial)
VCC pin: power pin, needs to be connected to VCC (5V)
GND pin: power pin, needs to be connected to GND (0V)
The interface to the speaker is a 3.5mm Aux output female jack.
The interface to the Micro SD Card is a Micro SD Card Socket in the back of the module.
image source: diyables.io
A speaker usually has two interfaces:
Audio signal interface: it is 3.5mm Aux male connector that connects to the MP3 player module
Poweer interface: it can be USB, 5V power adapter or any other power interface
What we need to prepare:
Pre-store a list of songs or recorded audio that we want to play to micro SD Card.
Insert the micro SD Card to the MP3 player module
Connect the MP3 player module to Arduino
Connect the speaker to the MP3 player module to a
Connect the speaker to a power source.
Each MP3 file stored on Micro SD Card will have an index. The index is the order of stored song, start from 0.
Then we can program Arduino to send command to the MP3 player module. It supports the following commands:
Play
Pause
Play Next
Play Previous
Change volume
When the MP3 player module, it reads the MP3 file from the micro SD Card, converts the MP3 files to audio signal and outputs the audio signal to the speaker via the 3.5mm Aux interface.

This image is created using Fritzing. Click to enlarge image
The below code plays the first song stored on the Micro SD Card.
#include <SoftwareSerial.h>
#define CMD_PLAY_NEXT 0x01
#define CMD_PLAY_PREV 0x02
#define CMD_PLAY_W_INDEX 0x03
#define CMD_SET_VOLUME 0x06
#define CMD_SEL_DEV 0x09
#define CMD_PLAY_W_VOL 0x22
#define CMD_PLAY 0x0D
#define CMD_PAUSE 0x0E
#define CMD_SINGLE_CYCLE 0x19
#define DEV_TF 0x02
#define SINGLE_CYCLE_ON 0x00
#define SINGLE_CYCLE_OFF 0x01
#define ARDUINO_RX 7
#define ARDUINO_TX 6
SoftwareSerial mp3(ARDUINO_RX, ARDUINO_TX);
void setup() {
Serial.begin(9600);
mp3.begin(9600);
delay(500);
mp3_command(CMD_SEL_DEV, DEV_TF);
delay(200);
}
void loop() {
mp3_command(CMD_PLAY, 0x0000);
}
void mp3_command(int8_t command, int16_t dat) {
int8_t frame[8] = { 0 };
frame[0] = 0x7e;
frame[1] = 0xff;
frame[2] = 0x06;
frame[3] = command;
frame[4] = 0x00;
frame[5] = (int8_t)(dat >> 8);
frame[6] = (int8_t)(dat);
frame[7] = 0xef;
for (uint8_t i = 0; i < 8; i++) {
mp3.write(frame[i]);
}
}
Copy the above code and open with Arduino IDE
Click Upload button on Arduino IDE to upload code to Arduino
Enjoy the music
See the result on Serial Monitor.
The below code is an upgrade of the previous code. It adds foyr buttons to let you interact with MP3 player.
#include <SoftwareSerial.h>
#include <ezButton.h>
#define CMD_PLAY_NEXT 0x01
#define CMD_PLAY_PREV 0x02
#define CMD_PLAY_W_INDEX 0x03
#define CMD_SET_VOLUME 0x06
#define CMD_SEL_DEV 0x09
#define CMD_PLAY_W_VOL 0x22
#define CMD_PLAY 0x0D
#define CMD_PAUSE 0x0E
#define CMD_SINGLE_CYCLE 0x19
#define DEV_TF 0x02
#define SINGLE_CYCLE_ON 0x00
#define SINGLE_CYCLE_OFF 0x01
#define ARDUINO_RX 7
#define ARDUINO_TX 6
SoftwareSerial mp3(ARDUINO_RX, ARDUINO_TX);
ezButton button_play(2);
ezButton button_pause(3);
ezButton button_next(4);
ezButton button_prev(5);
void setup() {
Serial.begin(9600);
mp3.begin(9600);
delay(500);
mp3_command(CMD_SEL_DEV, DEV_TF);
delay(200);
button_play.setDebounceTime(50);
button_pause.setDebounceTime(50);
button_next.setDebounceTime(50);
button_prev.setDebounceTime(50);
}
void loop() {
button_play.loop();
button_pause.loop();
button_next.loop();
button_prev.loop();
if (button_play.isPressed()) {
Serial.println("Play mp3");
mp3_command(CMD_PLAY, 0x0000);
}
if (button_pause.isPressed()) {
Serial.println("Pause mp3");
mp3_command(CMD_PAUSE, 0x0000);
}
if (button_next.isPressed()) {
Serial.println("Play next mp3");
mp3_command(CMD_PLAY_NEXT, 0x0000);
}
if (button_prev.isPressed()) {
Serial.println("Play previous mp3");
mp3_command(CMD_PLAY_PREV, 0x0000);
}
}
void mp3_command(int8_t command, int16_t dat) {
int8_t frame[8] = { 0 };
frame[0] = 0x7e;
frame[1] = 0xff;
frame[2] = 0x06;
frame[3] = command;
frame[4] = 0x00;
frame[5] = (int8_t)(dat >> 8);
frame[6] = (int8_t)(dat);
frame[7] = 0xef;
for (uint8_t i = 0; i < 8; i++) {
mp3.write(frame[i]);
}
}
The wiring diagram for the above code:

This image is created using Fritzing. Click to enlarge image
Now, you can modify the projects to add more functions, for example:
Add a RFID reader and card to make RFID MP3 player, see
Arduino RFID tutorial
We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.
※ OUR MESSAGES
You can share the link of this tutorial anywhere. Howerver, please do not copy the content to share on other websites. We took a lot of time and effort to create the content of this tutorial, please respect our work!
Follow Us
Share with your friends!