PIR Sensor random Sound effect player issues

Hello All,

Not sure if this is the right catagory so apologies if not, but I'm trying to trigger a random sound effect out of 5 sounds using a PIR sensor and the arduino compatible media player from Jaycar (https://www.jaycar.com.au/arduino-compatible-mp3-audio-player-with-button-controls/p/XC3748?srsltid=AfmBOooBuqUNFwm0-nNfAX90-AVeUHdUdB6yvK7fHP4gzo4JoqVDAeGw)

But im having no luck, the serial monitor is registering the motion but its not triggering the sounds inless I manually press play but then the sound comes out patchy and broken (Seperate issue but any help is appreciated).

#include "SerialMP3Player.h"
#include <SoftwareSerial.h>

int pirPin = 12; // Arduino pin the PIR sensor is connected to
int RX = 3; // Arduino pin the TX pin of mp3 player is connected to
int TX = 2; // Arduino pin the RX pin of mp3 player is connected to


SerialMP3Player mp3(RX,TX);

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 = 3; // variable to store current track number

void setup()
{
  pinMode(pirPin, INPUT); // set Arduino pin that PIR is connected to as an INPUT
  pinMode(RX, INPUT); // set Arduino pin that mp3 player TX is connected to as an INPUT
  pinMode(TX, OUTPUT); // set Arduino pin that mp3 player RX is connected to as an OUTPUT


  delay(3000);  //wait a bit
  
  Serial.begin(9600);    //serial debug
  Serial.println("Starting up");
  mp3.begin(9600);
  mp3.sendCommand(CMD_SEL_DEV, 0, 2);

}

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
      pirState = HIGH; // update the previous PIR state to HIGH
      
      
      musicplay(); // play current track from micro SD card
      
      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 == HIGH) {
      Serial.println ("Motion Ended"); //print result to the serial monitor
      pirState = LOW; // update the previous PIR state to LOW
    }
  }
}

void musicplay(){

mp3.play(track);

}

I’m unfamiliar with that library. You might consider using an alternative player: DFRobot’s DFR Player. Get that working first using one of the many basic examples, without PIR etc.

How do you power this mp3 module, from specification it is 5V and 5W max so it can draw a max of 1Ampere, does you power supply handle this?

Hello, i have Tried the DFR library examples but none are compiling due to Serial1 not being declared. Has this happened in th epast or a common issue with the Library?

Hello, I am powering it directly through the arduino 5V pin which i have done in the past for another project which works fine with an ultrasonic sensor instead of the PIR

I believe it can power the pir, but the small arduino ( which board? ) regulator can't deliver the current required by the mp3. Try powering the mp3 from a different power source

A I see, its currently running on an Uno like the other project so roughly 500mah though would power be the reason its not triggering with the code? or is that more for the sound because i believe i may have fixed it (it was an export setting that wasnt properly set)

and it is playing manually with the inbuilt play button and no issues with that

But does it play a track when you call the "play.mp3(track)" function?
You should get that much nailed down.

Is that player supposed to be serial device?
You shouldn't define serial pins as output/input
Remove those two lines and try again'

What Arduino? If UNO or Nano for example, use Software Serial.

It doesnt not no, even when isolated to just the function in the loop without the PIR or input trigger

Im not sure, I'll have to double check though ive removed both lines and still noting, Serial Monitor is registering the motion and counting normally to trigger each sound but nothing is playing

It is definitly an Uno and I believe software serial is in there but nothing i alter seems to get it working atm

Then post your actual code, otherwise no one can follow...

The code above is the actual code, I'll repost it below but its the same as above.

#include "SerialMP3Player.h"
#include <SoftwareSerial.h>

int pirPin = 12; // Arduino pin the PIR sensor is connected to
int RX = 3; // Arduino pin the TX pin of mp3 player is connected to
int TX = 2; // Arduino pin the RX pin of mp3 player is connected to


SerialMP3Player mp3(RX,TX);

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

void setup()
{
  pinMode(pirPin, INPUT); // set Arduino pin that PIR is connected to as an INPUT
 
  delay(3000);  //wait a bit
  
  Serial.begin(9600);    //serial debug
  Serial.println("Starting up");
  mp3.begin(9600);
  delay(500);             // wait for init
  mp3.sendCommand(CMD_SEL_DEV, 0, 2);
  delay(500);             // wait for init
}

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
      pirState = HIGH; // update the previous PIR state to HIGH
      
      
      musicplay(); // play current track from micro SD card
      
      delay(5000); // length in microseconds of the longest track
      track++; // add 1 to the current track for the next loop
      Serial.println(track);

      // 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
        Serial.println(track);
      }
    }
  }
    
  // or else if PIR pin output is LOW:
  else {
      
    if (pirState == HIGH) {
      Serial.println ("Motion Ended"); //print result to the serial monitor
      pirState = LOW; // update the previous PIR state to LOW
    }
  }
}

void musicplay(){

mp3.play(track);

}

same it is...

Oops wrong version let me fix it sorry, but Like I said previously in another reply I removed both and still no change or sound

This way your'e out of luck here. There is only one "actual version" and corresponding output for that.

Says some chaps got it going with the YX5300 library referenced there.
IMO, you should focus on this and address the PIR (and everything else) later.

I did see this forum and have tried just getting it to work using the provided examples in the IDE which should play the single sound ive got on the sd card but it still doesnt seem to want to work.