Arduino Soundboard With Df Player: Supported Communication

by Nowals in Circuits > Arduino

1646 Views, 4 Favorites, 0 Comments

Arduino Soundboard With Df Player: Supported Communication

3.png
6.png
5.png
4.png

Tutorial to build a soundboard with an Arduino and a DFPlayer.

This can serve as a soundboard or as a talker, a form of assisted communication.

For the project more than 20 buttons were used for audio files and due to limited programming knowledge a simple code with digital pins was used.


The project is explained using an example with four buttons, but more words can be added according to the Arduino model (Uno or Mega), depending on the number of digital pins.


The code used saves the use of resistors between the buttons and GND by using the command „INPUT_PULLUP“.


Supplies

1. Arduino Uno/ Mega....... https://amzn.to/3GpkQlt


2. Df Player Mini ................ https://amzn.to/3fn25De


3. Speaker........................... https://amzn.to/3fj7Bqu


4. Jumper wires ................. https://amzn.to/3qo3Qq8


5. Bread Board.................... https://amzn.to/3tuCpgt


6. 1k Resistor....................... https://amzn.to/3reTIiP


Helpful links:

Df Player Mini Code and Explanation: https://wiki.dfrobot.com/DFPlayer_Mini

Schematics

mp3-player.png

Connections:

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.


Audio

In order for the audio files to be played correctly, they should be saved in the format 0001, 0002, .... should be saved.

NOTE: If you are using Mac OS X to copy the mp3, the file system will automatically add hidden files like: „._0001.mp3“ for index, which this module will handle as valid mp3 files. It is really annoying. So you can run following command in terminal to eliminate those files.


dot_clean /Volumes/<SDVolumeName>


Please replace the to the volume name of your SD card.


Code


Test:

To test whether the Df Player works, a simple code can be used, which can be found here under "Sample Code":

https://wiki.dfrobot.com/DFPlayer_Mini


Player:

If the test code works, the definitive code can be used.


#include „Arduino.h“
#include „SoftwareSerial.h“
#include „DFRobotDFPlayerMini.h“

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

int BUTTON_PIN [23] = { 2, 3, 4, 5, 6, 7, 8, 9,
                       12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
                       22, 23, 24, 25, 26}; // 10 and 11 left out because they are used by the Df Player)

int PLAY_FILE [23] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
                       22, 23}; // Amount of numbers, according to your audio files

void printDetail(uint8_t type, int value);

void setup()
{
 for(int i=0; i<23; i++) pinMode(BUTTON_PIN[i], INPUT_PULLUP);
 mySoftwareSerial.begin(9600);
 Serial.begin(115200);


 Serial.println();
 Serial.println(F(„DFRobot DFPlayer Mini Demo“));
 Serial.println(F(„Initializing DFPlayer ... (May take 3~5 seconds)“));

 if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
   Serial.println(F(„Unable to begin:“));
   Serial.println(F(„1.Please recheck the connection!“));
   Serial.println(F(„2.Please insert the SD card!“));
   while(true){
     delay(0); // Code to compatible with ESP8266 watch dog.
   }
 }
 Serial.println(F(„DFPlayer Mini online.“));

}

// Control/state variables:
int current_song = -1;
int btn_label = 0;

void action(int btn_label) {
 if(btn_label >= 0 && btn_label < 22) {
     Serial.println(btn_label);
     myDFPlayer.play(PLAY_FILE[btn_label]);
     delay(1500);
     myDFPlayer.stop();
     //current_song = -1;
   } else {
     if(current_song == btn_label)
      {
       myDFPlayer.stop();
       delay(1000);
       current_song = -1;
      }
     else
      {
        myDFPlayer.play(PLAY_FILE[btn_label]); // btn_label - 1 ??????
        delay(1000);
        current_song = btn_label;
      }
     Serial.println(btn_label);
   }
 }

void loop()
{
 for(int i=0; i<23; i++)
   if(!digitalRead(BUTTON_PIN[i])) action(i);
}

Troubleshooting and Debugging


  • Check connections


  • Test code from Df Player again


  • Upload the code, open the Serial Monitor, use the following code to see if the button and digital pin are communicating:

#include „Arduino.h“
#include „SoftwareSerial.h“

void setup() {
   pinMode(12, INPUT_PULLUP); // enable internal pull-up
   Serial.begin(9600);
   Serial.begin(115200);
}

int buttonStatus = 0;
void loop() {
 int pinValue = digitalRead(12);
 delay(10); // quick and dirty debounce filter
 if (buttonStatus != pinValue) {
   buttonStatus = pinValue;
   Serial.println(buttonStatus);
 }
}

Additional

similar projects with good explanation:


http://educ8s.tv/arduino-mp3-player/

https://www.instructables.com/Play-Audio-With-Arduino-DF-Player-Mini/

https://create.arduino.cc/projecthub/ronfrtek/arduino-mp3-player-07ad15


If a box is needed for this, there are various open source options that work with lasercut.