user83071: i need help on how to use busy pin in df player to arduino.... while playing one sound or df player is busy, i don't want to trigger df player by ultrasound sensors to play another song. here is my code without busy pin use in df player
#include "Arduino.h"
#include "SoftwareSerial.h"

#include "DFRobotDFPlayerMini.h"

const byte SENSOR_COUNT = 5;
byte triggerPins[SENSOR_COUNT] = {2,4,6,8,10};
byte echoPins[SENSOR_COUNT]    = {3,5,7,9,11};


SoftwareSerial mySoftwareSerial(12, 13); // RX, TX

DFRobotDFPlayerMini myDFPlayer;

void printDetail(uint8_t type, int value);

void setup()
{
  mySoftwareSerial.begin(9600);
  Serial.begin(115200);

  for( byte i=0; i<SENSOR_COUNT; i++ )
  {
    pinMode(triggerPins[i], OUTPUT);
    pinMode(echoPins[i], INPUT);
  }

  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);
  }
  Serial.println(F("DFPlayer Mini online."));

  myDFPlayer.volume(10);  //Set volume value. From 0 to 30

}

int currentSound = -1;
void loop()
{

  for( byte i=0; i<SENSOR_COUNT; i++ ) // loop through all distance sensors
  {
    if( detectPresence(i) ) // check if there is an object near it
    {
      if(currentSound!=i) // check that it's a different sensor than the one that was last triggered
      {
        Serial.print("play song number ");
        Serial.println(i);
        myDFPlayer.play(i+1); // play song nr `i+1`
      }
      currentSound = i;
    }
  }


  if (myDFPlayer.available()) {
    printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
  }

}

// detectPresence will return TRUE if there is an object close to it.
bool detectPresence(byte sensorNr)
{
  if( sensorNr>=SENSOR_COUNT )
    return false;
  long duration, distance;
  //digitalWrite(triggerPins[sensorNr], LOW);  // Added this line
  //delayMicroseconds(10); // Added this line
  digitalWrite(triggerPins[sensorNr], HIGH);
  delayMicroseconds(15); // Added this line
  digitalWrite(triggerPins[sensorNr], LOW);
  duration = pulseIn(echoPins[sensorNr], HIGH);
  distance = duration/58;

  return distance<30;// choose your own value here, from which distance it should trigger a sound
}

void printDetail(uint8_t type, int value){

  switch (type) {
    case TimeOut:
      Serial.println(F("Time Out!"));
      break;
    case WrongStack:
      Serial.println(F("Stack Wrong!"));
      break;
    case DFPlayerCardInserted:
      Serial.println(F("Card Inserted!"));
      break;
    case DFPlayerCardRemoved:
      Serial.println(F("Card Removed!"));
      break;
    case DFPlayerCardOnline:
      Serial.println(F("Card Online!"));
      break;
    case DFPlayerPlayFinished:
      Serial.print(F("Number:"));
      Serial.print(value);
      Serial.println(F(" Play Finished!"));
      break;
    case DFPlayerError:
      Serial.print(F("DFPlayerError:"));
      switch (value) {
        case Busy:
          Serial.println(F("Card not found"));
          break;
        case Sleeping:
          Serial.println(F("Sleeping"));
          break;
        case SerialWrongStack:
          Serial.println(F("Get Wrong Stack"));
          break;
        case CheckSumNotMatch:
          Serial.println(F("Check Sum Not Match"));
          break;
        case FileIndexOut:
          Serial.println(F("File Index Out of Bound"));
          break;
        case FileMismatch:
          Serial.println(F("Cannot Find File"));
          break;
        case Advertise:
          Serial.println(F("In Advertise"));
          break;
        default:
          break;
      }
      break;
    default:
      break;
  }
}


user42015: The busy pin is just a pin, that gets driven LOW, when a song is playing, and HIGH when nothing is playing. So connect it to a free digital IO pin on your Arduino and set that pin to input with:
pinMode(busy_pin, INPUT);

(Note: You yourself need to define busy_pin, since I don't know where you will connect it). Then just read this pin in the if statement together with detectPresence(i):
if(!digitalRead(busy_pin) && detectPresence(i))

The ! is to make the expression true, when digitalRead(busy_pin) returns 0 (LOW). This way the code will not even check for presence, when there is currently a song playing.

83071: <p>i need help on how to use busy pin in df player to arduino.... while playing one sound or df player is busy, i don't want to trigger df player by ultrasound sensors to play another song. here is my code without busy pin use in df player</p>
<pre class="lang-cpp prettyprint-override"><code>#include &quot;Arduino.h&quot;
#include &quot;SoftwareSerial.h&quot;

#include &quot;DFRobotDFPlayerMini.h&quot;

const byte SENSOR_COUNT = 5;
byte triggerPins[SENSOR_COUNT] = {2,4,6,8,10};
byte echoPins[SENSOR_COUNT]    = {3,5,7,9,11};


SoftwareSerial mySoftwareSerial(12, 13); // RX, TX

DFRobotDFPlayerMini myDFPlayer;

void printDetail(uint8_t type, int value);

void setup()
{
  mySoftwareSerial.begin(9600);
  Serial.begin(115200);

  for( byte i=0; i&lt;SENSOR_COUNT; i++ )
  {
    pinMode(triggerPins[i], OUTPUT);
    pinMode(echoPins[i], INPUT);
  }

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

  if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    Serial.println(F(&quot;Unable to begin:&quot;));
    Serial.println(F(&quot;1.Please recheck the connection!&quot;));
    Serial.println(F(&quot;2.Please insert the SD card!&quot;));
    while(true);
  }
  Serial.println(F(&quot;DFPlayer Mini online.&quot;));

  myDFPlayer.volume(10);  //Set volume value. From 0 to 30

}

int currentSound = -1;
void loop()
{

  for( byte i=0; i&lt;SENSOR_COUNT; i++ ) // loop through all distance sensors
  {
    if( detectPresence(i) ) // check if there is an object near it
    {
      if(currentSound!=i) // check that it's a different sensor than the one that was last triggered
      {
        Serial.print(&quot;play song number &quot;);
        Serial.println(i);
        myDFPlayer.play(i+1); // play song nr `i+1`
      }
      currentSound = i;
    }
  }


  if (myDFPlayer.available()) {
    printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
  }

}

// detectPresence will return TRUE if there is an object close to it.
bool detectPresence(byte sensorNr)
{
  if( sensorNr&gt;=SENSOR_COUNT )
    return false;
  long duration, distance;
  //digitalWrite(triggerPins[sensorNr], LOW);  // Added this line
  //delayMicroseconds(10); // Added this line
  digitalWrite(triggerPins[sensorNr], HIGH);
  delayMicroseconds(15); // Added this line
  digitalWrite(triggerPins[sensorNr], LOW);
  duration = pulseIn(echoPins[sensorNr], HIGH);
  distance = duration/58;

  return distance&lt;30;// choose your own value here, from which distance it should trigger a sound
}

void printDetail(uint8_t type, int value){

  switch (type) {
    case TimeOut:
      Serial.println(F(&quot;Time Out!&quot;));
      break;
    case WrongStack:
      Serial.println(F(&quot;Stack Wrong!&quot;));
      break;
    case DFPlayerCardInserted:
      Serial.println(F(&quot;Card Inserted!&quot;));
      break;
    case DFPlayerCardRemoved:
      Serial.println(F(&quot;Card Removed!&quot;));
      break;
    case DFPlayerCardOnline:
      Serial.println(F(&quot;Card Online!&quot;));
      break;
    case DFPlayerPlayFinished:
      Serial.print(F(&quot;Number:&quot;));
      Serial.print(value);
      Serial.println(F(&quot; Play Finished!&quot;));
      break;
    case DFPlayerError:
      Serial.print(F(&quot;DFPlayerError:&quot;));
      switch (value) {
        case Busy:
          Serial.println(F(&quot;Card not found&quot;));
          break;
        case Sleeping:
          Serial.println(F(&quot;Sleeping&quot;));
          break;
        case SerialWrongStack:
          Serial.println(F(&quot;Get Wrong Stack&quot;));
          break;
        case CheckSumNotMatch:
          Serial.println(F(&quot;Check Sum Not Match&quot;));
          break;
        case FileIndexOut:
          Serial.println(F(&quot;File Index Out of Bound&quot;));
          break;
        case FileMismatch:
          Serial.println(F(&quot;Cannot Find File&quot;));
          break;
        case Advertise:
          Serial.println(F(&quot;In Advertise&quot;));
          break;
        default:
          break;
      }
      break;
    default:
      break;
  }
}
</code></pre>
 42015: <p>The busy pin is just a pin, that gets driven LOW, when a song is playing, and HIGH when nothing is playing. So connect it to a free digital IO pin on your Arduino and set that pin to input with:</p>
<pre><code>pinMode(busy_pin, INPUT);
</code></pre>
<p>(Note: You yourself need to define <code>busy_pin</code>, since I don't know where you will connect it). Then just read this pin in the if statement together with <code>detectPresence(i)</code>:</p>
<pre><code>if(!digitalRead(busy_pin) &amp;&amp; detectPresence(i))
</code></pre>
<p>The <code>!</code> is to make the expression true, when <code>digitalRead(busy_pin)</code> returns 0 (LOW). This way the code will not even check for presence, when there is currently a song playing.</p>
