Arduino MP3 Player project

Hi guys, its nick again, welcome to today’s tutorial. Today I will be showing us how to easily build an mp3 player using the Arduino and the DFPlayer mini-module for around 10$.

This project relies heavily on the DFPlayer Mini MP3 Player which is a small and low price MP3 module with an embedded amplifier which gives it a simplified output through which it can be connected directly to a speaker or an earphone jack. The module can be used as a stand-alone module with attached battery, speaker, and push buttons or used in combination with an Arduino UNO or any other microcontroller with RX/TX capabilities.

Some of the features of the Dfplayer mini include:

  • Full support for FAT16 , FAT32 file system, maximum support 32G of the TF card, support 32G of U disk, 64M bytes NORFLASH
  • Works in a variety of control modes including, I/O control mode, serial mode, AD button control mode
  • Can Play with advertising sound waiting function, the music can be suspended. when advertising is over the music continue to play
  • Audio data sorted by folder, it supports up to 100 folders, every folder can hold up to 255 songs
  • 30 level adjustable volume, 6 -level EQ adjustable

DFplayermini

For this tutorial, we will be building a simple mp3 player which will have 3 buttons, The first button will be used to Play/Pause the music currently being played, while the second one will be used to load the next song(the next button) and the last one will be used to load the previous song ( the previous button). The music files to be played using the DFplayer mini are pre-stored on an SD card which is inserted into the DF player mini.

For this tutorial, we will be using the Arduino Uno, but you can use any other Arduino or microcontroller to build this project. Ready? let’s build!

Required Parts and Where to Buy

The following parts are needed to build this project and each part can be bought by clicking on the link in front of it.

1. DFPlayer Mini ▶ https://educ8s.tv/part/DFPlayer

2. Cheap Arduino Uno ▶ https://educ8s.tv/part/ArduinoUno

3. Small Breadboard ▶ https://educ8s.tv/part/SmallBreadboard

4. Buttons ▶ https://educ8s.tv/part/Buttons

5. Speaker▶ https://educ8s.tv/part/SmallSpeaker

6. Resistor ▶ https://educ8s.tv/part/Resistors

7. Wires ▶ https://educ8s.tv/part/Wires

8. Jumper wires ▶ https://educ8s.tv/part/JumperWires

Full disclosure: All of the links above are affiliate links. I get a small percentage of each sale they generate. Thank you for your support!

[adsense]

Schematics

Connect the components as shown in the image below.

As shown above, the connection between the Arduino and the DFplayer mini is pretty simple. The pin connections are described below to make it easier to follow.

DFplayer Mini – Arduino

Rx(via resistor) ▶  D11

Tx  ▶ D10

VCC  ▶ 5v

Gnd ▶ Gnd

A speaker is connected to the speaker output(pin 6 and 8) of the DF player mini to air the sound being played.

You probably noticed that the pushbuttons were connected without a pull-up or pull-down resistor, check this (https://youtu.be/UodfePdNfg8) educ8s.tv tutorial to know how to use the pushbuttons without pull up or pull down resistors on the Arduino.

Go over the schematics once again to ensure everything is as it should be before proceeding to the code.

Code

The code for this project is a fairly simple one, we will be using the Arduino software serial library which comes pre-installed on the Arduino IDE as the communication between the Arduino and the DFplayer mini is over serial as earlier stated and to avoid code uploading issues that may arise from using the hardware serial(pin D0 and D1), we will be using a software serial connection. Although the DFplayer mini has its own library that enables us to write the code easily, it is not used for this tutorial, Instead, we created functions which can be called to perform the tasks involved with this project. Additional functions can be found in the description of the video on youtube.

The first thing we do in the code is, as usual, include the libraries needed for the project; in this case, the software serial library.

///              MP3 PLAYER PROJECT
/// https://educ8s.tv/arduino-mp3-player/
//////////////////////////////////////////


#include "SoftwareSerial.h"

Then we declare the pins on the Arduino to which our pushbuttons and Dfplayer mini are connected.

SoftwareSerial mySerial(10, 11);
# define Start_Byte 0x7E
# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0xEF
# define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]

# define ACTIVATED LOW

int buttonNext = 2;
int buttonPause = 3;
int buttonPrevious = 4;
boolean isPlaying = false;

 

Next, we move to the void setup function. here we set the pin mode of the pushbuttons, turn on the Arduino internal pull up resistors, initialize the serial communication among other things.

void setup () {

pinMode(buttonPause, INPUT);
digitalWrite(buttonPause,HIGH);
pinMode(buttonNext, INPUT);
digitalWrite(buttonNext,HIGH);
pinMode(buttonPrevious, INPUT);
digitalWrite(buttonPrevious,HIGH);

mySerial.begin (9600);
delay(1000);
playFirst();
isPlaying = true;


}

 

With the setup function done, we write the loop function. This, as usual, contains the set of code that will run forever. The void loop function works by reading the state of the pushbuttons after which it calls the function corresponding to the pushbutton state to either play, pause, play next mp3 or play the previous one.

void loop () { 

 if (digitalRead(buttonPause) == ACTIVATED)
  {
    if(isPlaying)
    {
      pause();
      isPlaying = false;
    }else
    {
      isPlaying = true;
      play();
    }
  }


 if (digitalRead(buttonNext) == ACTIVATED)
  {
    if(isPlaying)
    {
      playNext();
    }
  }

   if (digitalRead(buttonPrevious) == ACTIVATED)
  {
    if(isPlaying)
    {
      playPrevious();
    }
  }
}

 

The full code for the project can be downloaded from the link below.

——————–
CODE OF THE PROJECT
——————–

 

 

That’s it for this tutorial guys, thanks for watching and reading. Don’t forget to hit the subscribe button, share, and like, its one of the few ways through which you can support educ8s.tv.

Feel free to drop any question you might have as regards this project and if you created a replica or even modified it to something better, don’t forget to share with us via the comments section. See you next time.

——————–
SUBSCRIBE ON YOUTUBE
——————–

Never miss a video: Subscribe to educ8s.tv