Yx5300 mp3 module

hi all ,

just after some help what im looking for is for a motion sensor to active "track 1 " and then for it to stop and play "track 2" upon a phone being picked up (so when a switch is lifted est )

but when track to is playing i dont want the motion of people to re trigger track 1

im really new to this anyone who can help id be greatly appreciate

below is the code iv started to write


// void setup() {
  Serial.begin(9600);     // start serial interface
  pinMode (Sensor, INPUT);
  pinMode (Switch, INPUT_PULLUP);



mp3.begin(9600);// start MP3-comunication at baud 9600
  delay(500); //wait for init
  Serial.println ("Mp3 Config Started ");
  mp3.sendCommand(CMD_SEL_DEV, 0, 2);//select SD card
  delay(500);
  Serial.println("SD Card Selected");
  Serial.println("Sensor Config.........");
 
  delay(10000);//int
    Serial.println("Sensor Config Completed ");
  pinMode (Sensor, INPUT);
  pinMode (Switch, INPUT);
}

// the loop function runs over and over again forever
void loop() {
  if (digitalRead(Switch) == LOW)  { ;// message to play when phone answered 


    mp3.play(1);
    delay(500);
    Serial.print ("RING");
  }


else { 

  if (digitalRead (Switch) == HIGH){
    Serial.println ("stoped"); 
    mp3.stop();
  }
}



}

Couple questions:
A) What kind of Arduino are you using for the YX5300 module?
B) What kind of motion sensor? WIth link to specs if possible?
C) Does this code work at all? I would assume not?
D) Is this a one time program till you reset the Arduino, or does it loop at some point?
Guessing some type of escape room prop here?

Hi halloweenrick

Useing nanos

Motion sensor is a rcwl-0516

I've had next to no luck I'm afraid

It needs to be a loop if possible

It is indeed a game prop so we need it to run then reset for the next player...

Hopefully you able to help

So that RCWL-0516 doppler radar has its own example sketch available here:
https://create.arduino.cc/projecthub/hiotron/rcwl-0516-doppler-radar-sensor-interfacing-with-arduino-4c6ef0

int Sensor = 12;  
int LED = 3; 

void setup() {
  Serial.begin(9600);
  pinMode (Sensor, INPUT); 
  pinMode (LED, OUTPUT);   
  Serial.println("Waiting for motion");
}

void loop() {
     int val = digitalRead(Sensor); //Read Pin as input
     if((val > 0) && (flg==0))
     {
        digitalWrite(LED, HIGH);
        Serial.println("Motion Detected");
        flg = 1;
     }
     if(val == 0)
     {
        digitalWrite(LED, LOW);
        Serial.println("NO Motion"); 
        flg = 0;
     } 

PLEASE do not use an Arduino Nano for this. The Arduino Uno would be a much better choice. It shouldn't be a space issue as you don't need to "hide" the Arduino in the phone.

With the example sketch above, you should be on your way. All you need to do is add the other input (your phone switch) on the pin of your choice and change the output LED to your YX5300 Track 1 and then Track 2. I would think the easiest way to do this would be to reset the Arduino after every game to keep the background music/motion sensor from interfering.
We try not to entirely write the code for you here, but if you want to write it on your own we will do our best to guide you. We want you to learn the arduino code so you can understand the process.
Should you feel you need more help than that you can post into Jobs and Paid consultancy on this forum and they will help you for a modest fee. This program should be fairly easy to adapt from the example program above though IMHO. I would actually try to get the example program working on your Arduino and RCWL-0516 sensor first with an LED if you can get one and then go from there.

as far as I know the only way to see if the YX5300 is playing is to check the serial where you have connected the player to.

think of a little state machine:

activate a flag when you start a track
deactivate the flag if you get a "finished" byte on the Serial.

based on this flag you can avoid to start another track during the first one is still running.

You didn't post compileable code - therefore we can't support you better and you must write your own working code.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.