Get rid of this:
//Every 5 minutes
time = millis() % 300000L;
if(time >= 0 && time <= 500) {
software_Reset();
delay(2000);
}
Replace this:
char code[10];
with this:
const int CODE_LENGTH=10;
char code[CODE_LENGTH+1]; // +1 provides space for the terminating character
Replace this:
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
with this:
code[bytesread++] = val; // add the digit
code[bytesread] = 0; // terminate the string
In all the places in your code where you use the magic number 10 as the buffer length, replace it with CODE_LENGTH.