Arduino keeps disconnecting

i am trying to make a arduino send a infrared signal when it receives a specific word from the terminal. It is working now but it disconnects after the word has been send once. I can’t figure out how to avoid this. The code reads the infrared codes from sd card files.
A file looks like this:
1234/
123/
45568/
546/
etc.

#include <SD.h>

int ircoderry[77];


#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>


WidgetTerminal terminal(V1);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void setup() {
  pinMode(9, OUTPUT); 
  pinMode(4, OUTPUT);


  SD.begin(4); //sdkaart activeren



  Blynk.begin("d1180c442b4f470fa8c5874aaeb35344");
  }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

BLYNK_WRITE(V1)
{

  String terminalout = param.asStr();
  if (String(F("au")) == terminalout) { 
    terminal.println(F("k"));
    arrayer(F("aanuitt.txt")); 
  }
  terminal.flush(); 
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


void arrayer(String filee) {
  File dataFile = SD.open(filee);
  char numcom[6]; 
  if (dataFile) { 
    for (byte indexx = 0; indexx <= 77; indexx++) { 
      for (byte index = 0; index <= 6; index++) {
        delayMicroseconds(1000);
        char fille = dataFile.read();
        if (fille != '/') {
          numcom[index] = fille;
        }
        else { 
          ircoderry[indexx] = atoi(numcom); 
          index = 7; 
        }
      }
    }
    
    dataFile.close(); 
    irsend(); 
  }
 
  else {
    dataFile.close();
  }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void loop() {
  Blynk.run();

}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void pulseIR(long microsecs) {
 

  cli();

  while (microsecs > 0) {
    // 38 kHz is about 13 microseconds high and 13 microseconds low
    digitalWrite(9, HIGH);  
    delayMicroseconds(10);         
    digitalWrite(9, LOW);   
    delayMicroseconds(10);    

    // so 26 microseconds altogether
    microsecs -= 26;
  }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void irsend() {
  for (byte indexxx = 0; indexxx <= 77; indexxx++) {
    delayMicroseconds(ircoderry[indexxx]);
    
    indexxx++;
    
    pulseIR(ircoderry[indexxx]);
  }
}

I’ve not been through your code in great detail, but I think your issue is the way that the Arduino handles the Ethernet/SD card shield. You can’t actually use both devices at the same time, so you have to disable one before enabling the other.
I think that maybe accessing the SD card is disabling your Ethernet port, hence the disconnection.

Can’t you simply hard-code the IR codes in your code, maybe using a case select statement?

If not, then you need to handle activating the Ethernet hardware and deactivating the SD card hardware (and vice versa) within your code.

Pete.

Thank you for your reaction. I wil try it and see if it wiil work. I can’t put the codes in the sketch itself because it will take up to much room as there is a lot of them.