Ultrasonic sensor not detecting for a second time

Hello there, My project consists of an ultrasonic sensor that detects the movement of someone and activates LEDs and a Christmas music on a YX5300. This works well for the first time but when I try to do it again, nothing happens. I have tried to put while loops but it doesn't work. If anybody knows how to fix this I would be delighted.Here is the code:

#include <SoftwareSerial.h>

#define ARDUINO_RX 6//should connect to TX of the Serial MP3 Player module
#define ARDUINO_TX 5//connect to RX of the module
SoftwareSerial mySerial(ARDUINO_RX, ARDUINO_TX);
static int8_t Send_buf[8] = {0} ;
#define NEXT_SONG 0X01 
#define PREV_SONG 0X02 

#define CMD_PLAY_W_INDEX 0X03 //DATA IS REQUIRED (number of song)

#define VOLUME_UP_ONE 0X04
#define VOLUME_DOWN_ONE 0X05
#define CMD_SET_VOLUME 0X06//DATA IS REQUIRED (number of volume from 0 up to 30(0x1E))
#define SET_DAC 0X17
#define CMD_PLAY_WITHVOLUME 0X22 //data is needed  0x7E 06 22 00 xx yy EF;(xx volume)(yy number of song)

#define CMD_SEL_DEV 0X09 //SELECT STORAGE DEVICE, DATA IS REQUIRED
                #define DEV_TF 0X02 //HELLO,IM THE DATA REQUIRED
                
#define SLEEP_MODE_START 0X0A
#define SLEEP_MODE_WAKEUP 0X0B

#define CMD_RESET 0X0C//CHIP RESET
#define CMD_PLAY 0X0D //RESUME PLAYBACK
#define CMD_PAUSE 0X0E //PLAYBACK IS PAUSED



#define STOP_PLAY 0X16

#define PLAY_FOLDER 0X17// data is needed 0x7E 06 17 00 01 XX EF;(play the 01 folder)(value xx we dont care)

#define SET_CYCLEPLAY 0X19//data is needed 00 start; 01 close

#define SET_DAC 0X17//data is needed 00 start DAC OUTPUT;01 DAC no output
#define trigPin 10
#define echoPin 12

float starttime = millis();
float endtime = starttime;

int red1 = 2;
int red2 = 3;
int green1 = 4;
int green2 = 7;
void setup()
{
  Serial.begin(9600);//Start our Serial coms for serial monitor in our pc
  mySerial.begin(9600);//Start our Serial coms for THE MP3
  delay(500);//Wait chip initialization is complete
  sendCommand(CMD_SEL_DEV, DEV_TF);//select the TF card  
  delay(200);//wait for 200ms
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(red1, OUTPUT);
  pinMode(red2,OUTPUT);
  pinMode(green1, OUTPUT);
  pinMode(green2,OUTPUT);
}
void loop()
{
  float duration, distance;
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(2);
 
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
 
  duration = pulseIn(echoPin, HIGH);
  distance = (duration / 2) * 0.0344;
  
  
  while(distance >= 0 && distance <= 100){
    sendCommand(CMD_PLAY_WITHVOLUME, 0X0F01);
  
    //play the first song with volume 15 class
    while ((endtime - starttime) <=30000){
    digitalWrite(red1,HIGH);
    digitalWrite(red2,HIGH);
    delay(50);
    digitalWrite(red1,LOW);
    digitalWrite(red2,LOW);
    delay(50);
    digitalWrite(green1,HIGH);
    digitalWrite(green2,HIGH);
    delay(50);
    digitalWrite(green1,LOW);
    digitalWrite(green2,LOW);
    delay(50);
    
    endtime = millis();
    
    }
  duration = pulseIn(echoPin, HIGH);
  distance = (duration / 2) * 0.0344;


//the programm will send the play option each 100 seconds to the catalex chip
}
  
  
  }
    

void sendCommand(int8_t command, int16_t dat)
{
 delay(20);
 Send_buf[0] = 0x7e; //starting byte
 Send_buf[1] = 0xff; //version
 Send_buf[2] = 0x06; //the number of bytes of the command without starting byte and ending byte
 Send_buf[3] = command; //
 Send_buf[4] = 0x00;//0x00 = no feedback, 0x01 = feedback
 Send_buf[5] = (int8_t)(dat >> 8);//datah
 Send_buf[6] = (int8_t)(dat); //datal
 Send_buf[7] = 0xef; //ending byte
 
 for(uint8_t i=0; i<8; i++)//
 {
   mySerial.write(Send_buf[i]) ;//send bit to serial mp3
   Serial.print(Send_buf[i],HEX);//send bit to serial monitor in pc
 }
 Serial.println();

}

Thanks

@marcopy, please do not cross-post. Other thread removed.

It is because I thought it would fit better in the other category but I couldn't remove the post

Click Report to moderator then ask for the thread to be moved.