All I did was copy and paste Terrypin's code. I then removed SoftwareSerial because when i asked you said yes, i then replaced it with Serial1 and got that result.
int pirPin = 3; // my edit
// int pirPin = 12; // Arduino pin the PIR sensor is connected to
int rxPin = 10; // my edit
// int rxPin = 3; // Arduino pin the TX pin of mp3 player is connected to
int txPin = 11; // my edit
// int txPin = 2; // Arduino pin the RX pin of mp3 player is connected to
int ledPin = 13; //Arduino built-in LED, and a more visible one
int motionStatus = 0; // variable to store the PIR's current reading (high or low)
int pirState = 0; // variable to store the PIR's state change
int track = 1; // variable to store current track number
Serial1 fxSerial(rxPin, txPin); // Software Serial object
DFRobotDFPlayerMini fxPlayer;
void setup()
{
pinMode(pirPin, INPUT); // set Arduino pin that PIR is connected to as an INPUT
pinMode(rxPin, INPUT); // set Arduino pin that mp3 player TX is connected to as an INPUT
pinMode(txPin, OUTPUT); // set Arduino pin that mp3 player RX is connected to as an OUTPUT
pinMode(ledPin, OUTPUT); // my edit
Serial.begin(115200); // my preference
// Serial.begin(9600); // initialize Serial Monitor (for looking at PIR readings)
fxSerial.begin(9600); // initialize Serial communication for mp3 player
fxPlayer.begin(fxSerial); // tells mp3 player to use fxSerial for communication
delay(1000); // my edit
fxPlayer.volume(15); // my edit // mp3 player volume (pick a value 10-30)
delay(8000); // my edit, allow say 8 secs for PIR sensor to settle
}
void loop()
{
motionStatus = digitalRead(pirPin); // read the PIR pin's current output (is it HIGH or LOW?)
// if PIR pin output is HIGH:
if (motionStatus == HIGH)
{
if (pirState == LOW)
{
Serial.println("Motion Detected"); // print result to the serial monitor
digitalWrite(ledPin, LOW); // turn OFF built-in LED
pirState = HIGH; // update the previous PIR state to HIGH
fxPlayer.play(track); // play up to 3 s of current track
// delay(1000); // // my edit length in MILLIseconds of the current track
// delay(5000); // length in microseconds of the longest track
track++; // add 1 to the current track for the next loop
// if track number tries to exceed 5 (I have 5 total in my case)
if (track > 5)
{ // change this value to match your total # of tracks
track = 1; // reset track number to 1
}
}
}
// or else if PIR pin output is LOW:
else
{
// if (pirState == LOW)
if (pirState == HIGH)
{
Serial.println("Motion Ended"); //print result to the serial monitor
digitalWrite(ledPin, HIGH); // turn ON built-in LED
pirState = LOW; // update the previous PIR state to LOW
}
}
}