Best way to play multiple audio files (each on its own speaker) simultaneously

Hey everyone, I have been struggling with a way to execute a project I am trying to build. It has me flummoxed as to the best approach. I would appreciate your knowledge and of you could impart. I have a project where I looking to have one button play four different tracks simultaneously on four different speakers. The track are all 60 seconds long. During this time the button would not be able to give input until the audio tracks were over (so the track doesn't stop and start over). I don't need any other functionality.

I have had a couple of different approaches to solving this:

My first attempt was going to use five different Arduinos and four SD card modules. One Primary Arduino would start the other four and provide the timed button lockout. The other four would each play their own track stored on the SD card module. It would require two different bits of code. One for the Primary Arduino and one for the Secondaries.

My second iteration of the concept was to use only one arduino and four dfplayers. I am VERY amateur at this and usually I find code that does what I want and then reverse engineer it to figure out what it is doing. I can't find ANY code for playing multiple DFPlayers simultaneously.

Any insight you could provide into this project I would be very appreciative of.

-KBed-

Hi,
Experiment..
You will need 4 DFPlayers, so write some code for ONE player and get it running, THEN attempt 2 players on the one UNO, then three then four.

Go for it, Google how to use the DF player and make some code.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

I have all that ready to go. I can't just add them all to the same pins, can I? I assumed that I would need to create different outputs from the arduino for each.

HI,
Can you please show us your code?

Can we please have a circuit diagram?
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Yes. Simple as that.

And if you always play four tracks on four (not eight) speakers simultaneously and they are always the same tracks, you might need only two DFPlayers. Put two tracks together, one on left channel, one on right channel. Then you kind of start only two tracks. But that's two stereo tracks on four speakers, making each speaker play its own track.

I love this idea and hadn't thought about using the stereo channels to each carry a different track. I think I want to use four dfplayers as it will make changing the audio tracks much easier if I need to do this in the future as I wouldn't need to mix mono tracks into a stereo track...unless you think there is a problem with using for simultaneously.

So, for the last few weeks I have just been looking around for and experimenting with the basic code and wiring. Everything is a slight variation on the same basic setup.

I don't know enough to write my own code and barely know enough to modify code, thus my post here.

The code I plan to modify is this:

> Blockquote

#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
 
void setup () {
 Serial.begin (9600);
 mp3_set_serial (Serial); //set Serial for DFPlayer-mini mp3 module 
 delay(1);
 mp3_set_volume (10);  // set volume of speaker (0~30)
}
 
void loop () {        
 
 mp3_play (1); //play 0001.mp3
 delay (60000); //60 sec, time delay to allow 0001.mp3 to finish playing
 
}

> Blockquote

I like that it has no skip or forward functions that I don't need. I do have a basic question, though...where do I wire the button that makes this initially play? I think this is programmed to play as soon as the unit is turned on. I need it to always be on and to wait for the input button.

Here is the wiring diagram.
dfplayer-with-arduino-hardware-serial

I am really trying to build a project a few steps above my skill level. I apologize for my naivete.

You should avoid using pins 0, 1 on Uno. They are used for uploading your code and using the serial monitor. If you try to use them for other purposes, there is a danger of damage, and the player might interfere with code upload and debugging with serial monitor. Uno is not ideal for this project because it does not have any spare Serial (UART) ports, but you can use Software Serial library to make an extra port.

I am wondering if you need an Arduino at all for this project. The player can be triggered to play track #1 by connecting a button directly to one of its pins.

For your 4 player setup, the same button could trigger all 4 players together.

I have the arduino for the timing cutoff (which I also have to figure out how to put into the code, I saw it on another piece of code but haven't lifted it yet) . If I didn't have something to disable the audio from being reset if you pushed the button again before the audio was over you would restart the audio. I need it to play all the way through before it stops.

and thank you about pins 0 and 1. I will change that.

actually, I don't see in the code where those pins are specified. I thought you always had to specify your pins.

Serial always uses pins 0, 1 on Uno, so that's why the pin numbers are not in the code. When you create a Software Serial object, you can specify the pins you want to use and then pass that object to mp3_set_serial().

I just noticed your code above contains a line to use the Software Serial library, but then does not use it! That's one less line of code for you to add.

#include <SoftwareSerial.h>

On any spare Uno pin you like. Connect the button from the pin to ground. Use pinMode(pin, INPUT_PULLUP) which will prevent the pin from floating and giving random readings when the button is not pressed. Then, in loop() you can simply wait for the button to be pressed:

while(digitalRead(pin) == HIGH);

You might get some ideas from this thread:
https://forum.arduino.cc/t/help-playing-three-sequential-tracks-on-three-different-speakers/947890/6

Not to dissuade your use of an Arduino. I am sure you have seen the use of chipcorders originally developed by ISD. They are used in assorted applications like greeting cards. They have come a long way and a 60 second flavor is inexpensive and common. Today the chips are produced by Novoton as their Digital ChipCorder Series. The actual chips can be found on dozens of small readily available modules. A Google of "recordable sound modules" should bring some up. Make your sound tracks whatever you want and if sync is important just create your files using Audigy which is free and a cool tool.

Matter of fact you could likely create your 60 second sound clips in Audigy and then load them and use your Arduino for playback. Pretty sure Audigy can mix the tracks for you, I never tried it.

My bad it's actually called [Audacity Free, open source, cross-platform audio software](https://Free, open source, cross-platform audio software) . Something to consider anyway.

Ron

Thank you....that other thread is also mine, from when I started this project. It was for the first version I was going to build, which was before I changed the project from being sequentially played to being simultaneously played.

I haven't read through it in awhile as I thought it no longer applied but I will take a look and see if there is any nuggets of useful info for me to digest.

Thank you for the suggestion. Correct me if I am wrong but isn't a recordable sound module essentially the same as the dfplayer, only with a predetermined memory instead of a removable one?

Also, thank you for the Audacity referral. I have the sound editing taken care of. That is actually something I am well versed in. My reluctance to use the stereo channels was more about convenience than ability. That is actually the only aspect of this build I am knowledgable enough to handle unassisted. ...but your suggestions are VERY appreciated.

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

//Start 4 serial ports
SoftwareSerial mySeria1(3, 4);  // RX, TX dfplayer 1
SoftwareSerial mySeria2(5, 6);  // RX, TX dfplayer 2
SoftwareSerial mySeria3(7, 8);  // RX, TX dfplayer 3
SoftwareSerial mySeria4(9, 10); // RX, TX dfplayer 4

// We declare variables for the 4 dfplayer
DFRobotDFPlayerMini DFPlayer1;
DFRobotDFPlayerMini DFPlayer2;
DFRobotDFPlayerMini DFPlayer3;
DFRobotDFPlayerMini DFPlayer4;


void setup() {
  // definition of the button connected to pin 2 and GND
  pinMode (2, INPUT_PULLUP);

  //We initialize the 4 serial channels
  mySeria1.begin(9600);
  mySeria2.begin(9600);
  mySeria3.begin(9600);
  mySeria4.begin(9600);

  // initialize the 4 players
  DFPlayer1.begin(mySeria1);
  DFPlayer2.begin(mySeria2);
  DFPlayer3.begin(mySeria3);
  DFPlayer4.begin(mySeria4);

  //Default volume at 15
  DFPlayer1.volume(15);  //Set volume value (0~30).
  DFPlayer2.volume(15);  //Set volume value (0~30).
  DFPlayer3.volume(15);  //Set volume value (0~30).
  DFPlayer4.volume(15);  //Set volume value (0~30).
}

void loop() {
  if (digitalRead (2) == LOW) {
    DFPlayer1.play(1);
    DFPlayer2.play(1);
    DFPlayer3.play(1);
    DFPlayer4.play(1);
  }
  delay (250);
  while (digitalRead (2) == HIGH);
}


For example.

OMG, dude, this is awesome. It looks so simple and THANK YOU for simply describing what every step of the code does. I am pretty sure I can figure out the diagram, it seems pretty straight forward. As I have more questions, and I am sure that I will, I will post them here. Thank you so much.

According to my basic understanding of what is required this looks like I could also get all this using a Nano. Is that correct or am I missing something?

what is the function of these two lines?

delay (250);
while (digitalRead (2) == HIGH);