Arduino Nano, solar tracker stop working after a while

Hallo all,
I write some code to create a solar tracker, it works fine but after a while (hours?) stop working.

Following the code

/* 
  Solar Tracker Code
*/

// Intervallo di esecuzione della funzione
int secondiIntervallo = 30;

// Più il numero è alto e più avrà tolleranza
int tolleranzaSensori = 10;

// Modifica Soglia minima
int sogliaMinima = 120;

int minVal = 0;
int maxVal = 0;
int percentageVal = 0;

// Valori relay
const byte relayOnState = LOW;
const byte relayOffState = HIGH;

// LDR (Fotoresistenze)
int sensoreDxPin = A0;
int sensoreSxPin = A1;

// Finecorsa
int finecorsaDxPin = A2;
int finecorsaSxPin = A3;

// Relè
int realiDxPin = 3;
int realiSxPin = 4; // Non lo vede

// Stati
int sensoreDxState = 0;
int sensoreSxState = 0;

int error = 0;
int poserror = 0;

int finecorsaDx = 0;
int finecorsaSx = 0;

bool go = true;

void setup() {
  pinMode(sensoreDxPin, INPUT);
  pinMode(sensoreSxPin, INPUT);
  pinMode(finecorsaDxPin, INPUT);
  pinMode(finecorsaSxPin, INPUT);
  pinMode(realiDxPin, OUTPUT);
  pinMode(realiSxPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  //Serial.println("start programm");
  digitalWrite(realiDxPin, relayOffState);
  digitalWrite(realiSxPin, relayOffState);
  
  go = true;

  while( go == true ){

    sensoreDxState = analogRead(sensoreDxPin);
    sensoreSxState = analogRead(sensoreSxPin);

    // Leggo i Valori dei fine corsa
    finecorsaDx = digitalRead(finecorsaDxPin);
    finecorsaSx = digitalRead(finecorsaSxPin);

    maxVal = max(sensoreSxState, sensoreDxState);
    minVal = min(sensoreSxState, sensoreDxState);
    error = sensoreDxState - sensoreSxState;

    float difference = maxVal - minVal;
    difference = difference / maxVal;
    difference = difference * 100;

    percentageVal = int(difference);

    //Serial.println(sensoreSxState + (String)" - " + sensoreDxState);
    //Serial.println((String)" Diff %: " + percentageVal);
    //Serial.println(percentageVal > tolleranzaSensori);
    //Serial.println(maxVal);

    if(maxVal > sogliaMinima){
      if (percentageVal > tolleranzaSensori){

        if (error > 0 && finecorsaSx == HIGH) {
          digitalWrite(realiSxPin, relayOnState);
          digitalWrite(realiDxPin, relayOffState);
          //Serial.println(" auto LEFT");
        }else if (error < 0  && finecorsaDx == HIGH){
          digitalWrite(realiDxPin, relayOnState);
          digitalWrite(realiSxPin, relayOffState);
          //Serial.println(" auto RIGHT");
        }else{
          digitalWrite(realiDxPin, relayOffState);
          digitalWrite(realiSxPin, relayOffState);
          //Serial.print("Stop");

          go = false;
          delay(secondiIntervallo * 1000);
        }
      
      }else{
        digitalWrite(realiDxPin, relayOffState);
        digitalWrite(realiSxPin, relayOffState);
        //Serial.print("Stop");

        go = false;
        delay(secondiIntervallo * 1000);
      }
    }else{
        go = false;
        delay(secondiIntervallo * 1000);
    }

    //delay(200);
  }
}

Please describe the problem; i.e. what does "stop working" mean exactly? If you put the Serial.print's back in, do they still happen or not?

Also please provide details on the hardware including a schematic diagram, details of components/modules used (product types & links documentation) and photographs of the setup that allow to verify if the schematic matches the equipment as built.

I moved your topic to an appropriate forum category @nico_m1.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

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