Stereo MP3 Player with Arduino and DFPlayer Module

Author : Dinesh Kumar Wickramasinghe

Introduction and Images

Hello everyone, Here again with an interesting project. If you already got bored dealing with sensors, motors, relays like stuff, here is a cool project for you. Here are some images of the project.

We are going to build a Stereo MP3 player with Arduino. Yes that's true. Using low cost DFPlayer module, we can easily do this project.

Using the link below, you can find more details of this module :

References : https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299

The DF Player module has all the features which a MP3 player should have. Including advance equalizers, looping and shuffling functions. But here I will show you how to build a simple player with Play/Pause and Next/Preview functions. Later you can add more features.

DF Player Mini

We will do this project in two steps. First we will build a simple MP3 player with a single speaker and then I will show you how to upgrade it as a Stereo player using a simple amplifier module and two speakers.


What you need?
  • Arduino Uno (or any)
  • DF Player module
  • 1K Resistor
  • Three micro push buttons (You can add more later)
  • Small Speaker (Two for the stereo player)
  • PAM8403 Small Amplifier Module (For the stereo player)
Library

There is an interesting library available for us to easily dealing with DFPlayer. Without using a library also we can write code but then we have to write all signals (commands) manually. So we will use this library.

Download Library

If you want to learn more about this library and the DF player features, Please read this article from DFRobot. I also referred this article while doing this project.

https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299

Scematic

Here is the schematic for the simple MP3 player

Arduino DFPlayer MP3 Player

Here is the schematic for the Stereo MP3 player with PAM8403 audio amplifier module. Please note that you can use any other compatible Amplifier circuit. I used PAM8403 because it is very low cost and easy to use. Also works with 5V (can work with Arduino power)

Arduino DFPlayer Stereo MP3 Player

You can see there are three push buttons for Next, Previous and Play / Pause.

Source Code

Here is the source code for this project. You can see in the code some additional functions I’ve commented. So you can later use them and build a more advanced player. Also see the library documentation for more functions.


#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;

int buttonNext = 2;
int buttonPause = 3;
int buttonPrevious = 4;

boolean isPlaying = false;

void setup() {
    pinMode(buttonPause, INPUT);
    digitalWrite(buttonPause, HIGH);
    pinMode(buttonNext, INPUT);
    digitalWrite(buttonNext, HIGH);
    pinMode(buttonPrevious, INPUT);
    digitalWrite(buttonPrevious, HIGH);

    mySoftwareSerial.begin(9600);
    Serial.begin(9600);

    delay(1000);

    Serial.println();
    Serial.println("DFPlayer Mini Demo");
    Serial.println("Initializing DFPlayer...");

    if (!myDFPlayer.begin(mySoftwareSerial)) {
        Serial.println("Unable to begin:");
        Serial.println("1.Please recheck the connection!");
        Serial.println("2.Please insert the SD card!");
        while (true);
    }
    Serial.println(F("DFPlayer Mini online."));

    myDFPlayer.setTimeOut(500);

    //----Set volume----
    myDFPlayer.volume(10); //Set volume value (0~30).
    //myDFPlayer.volumeUp(); //Volume Up
    //myDFPlayer.volumeDown(); //Volume Down

    //----Set different EQ----
    myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
    //  myDFPlayer.EQ(DFPLAYER_EQ_POP);
    //  myDFPlayer.EQ(DFPLAYER_EQ_ROCK);
    //  myDFPlayer.EQ(DFPLAYER_EQ_JAZZ);
    //  myDFPlayer.EQ(DFPLAYER_EQ_CLASSIC);
    //  myDFPlayer.EQ(DFPLAYER_EQ_BASS);

    myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);

    myDFPlayer.play(1); //Play the first song
    isPlaying = true;
    Serial.println("Playing..");
}

void loop() {
    if (digitalRead(buttonPause) == LOW) {
        if (isPlaying) {
            myDFPlayer.pause();
            isPlaying = false;
            Serial.println("Paused..");
        } else {
            isPlaying = true;
            myDFPlayer.start();
            Serial.println("Playing..");
        }
        delay(500);
    }
    if (digitalRead(buttonNext) == LOW) {
        if (isPlaying) {
            myDFPlayer.next();
            Serial.println("Next Song..");
        }
        delay(500);
    }

    if (digitalRead(buttonPrevious) == LOW) {
        if (isPlaying) {
            myDFPlayer.previous();
            Serial.println("Previous Song..");
        }
        delay(500);
    }
}
                    
Running the Player

Copy some MP3 Files to your MicroSD card and insert it to the MicroSD slot of the DF player module. Now power up your device setup

Comments Area
Add your questions and comments here. Comments will be published after the admin approval
Published By : jboy
Added Date :1/2/2020 3:29:36 AM
can i build the stereo mp3 player without writing those codes
Published By : Leigh Halford
Added Date :11/22/2019 8:14:01 PM
Hi I have built this, including amplifier, many thanks. The music starts to play good. All buttons work as they should. As it starts the RX led lights up which I believe is correct. However after about 6 seconds, the light turns off the bluetooth and the sound stops and it makes a clicking sound. Do you have any suggestions?
Published By : Sulaiman Khan
Added Date :11/17/2019 12:44:40 PM
This code is working properly But I need a little hepl I am unable to understane the excute_CMD command and that's why I am facing a problem. I want to play a specific song like press push button 1 play song 1 press push button play song 2 press push button three play song 3 and so on So I will be thankful to you if you could help me out this problem

 

Similar Projects

Go Top