Arduino Nano 33 IoT freezes around 48 hours

Hi I am using Arduino Nano hooked up with two sensors and a relay for watering plants. Everything works perfectly on Blynk but around 48 hours on-line the Arduino freezes!
I can´t find any similar treads about this when I do a google search, any ideas?

Best regards Villi

#define BLYNK_PRINT Serial
#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>


char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
char ssid[] = "XXXXXXXX";  
char pass[] = "XXXXXXXX";        

const int Relay_pin = 8; 
const int Snuningstakki = A0;
int lesa_takki_fasti;    
int skrifa_takki_fasti;  


const int RakaSensor =  A1; 
int RakaFasti;
const int dry = 718; // value for dry sensor
const int wet = 316; // value for wet sensor

const int Float_sensor = 7;  
int Float_fasti = 0; 

const int LED_RED = 2; 
const int LED_BLUE = 3; 
const int LED_GREEN = 4; 

BlynkTimer timer;
WidgetLCD lcd(V2);


void sendFlagToServer() {

lesa_takki_fasti = analogRead (Snuningstakki);
skrifa_takki_fasti = (255./1023.) * lesa_takki_fasti; 

RakaFasti = analogRead(RakaSensor);
int Rakastig = map(RakaFasti, wet, dry, 100, 0); 

Float_fasti = digitalRead (Float_sensor);

Blynk.virtualWrite(V4,Rakastig); 
Blynk.virtualWrite(V5,Float_fasti); 

 
if (Float_fasti ==0) //HVÍTUR 0 , GRÆNN 1 
  {
  analogWrite (LED_GREEN,0);
  digitalWrite (LED_RED,HIGH);
            }

else {
 
    analogWrite (LED_GREEN,skrifa_takki_fasti);
    digitalWrite (LED_RED,LOW);
}
}



void sendFlag2ToServer() {


if (Float_fasti ==0)
  {
 
  lcd.clear ();
  lcd.print(1, 0, "FORÐABÚR:");
  lcd.print(1, 1, "Vatn vantar");
            }

else {
 

    lcd.clear ();
    lcd.print(1, 0, "HVÍTA KERFIÐ:");
    lcd.print(1, 1, "Vatn til staðar ");

//Serial.println ("Rakaskynjari");
//Serial.print (friendlyValue);
}
}

 
BLYNK_WRITE(V1) {

  int Relay_Value = param.asInt();

      if (Relay_Value !=0)
            {
            digitalWrite (Relay_pin,HIGH);
            Blynk.virtualWrite(V7,255); 
            }
            
      else { 
            digitalWrite (Relay_pin,LOW);
            Blynk.virtualWrite(V7,0);
           }
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  timer.setInterval(1000L, sendFlagToServer);
  timer.setInterval(9950L, sendFlag2ToServer);
  
  pinMode(Relay_pin, OUTPUT);
  pinMode(RakaSensor, INPUT);
  pinMode (Snuningstakki, INPUT);
  pinMode(Float_sensor,INPUT_PULLUP);

  pinMode (LED_BLUE,OUTPUT);
  pinMode (LED_RED,OUTPUT);
  pinMode (LED_GREEN,OUTPUT);
}


void loop()
{
  Blynk.run();
  timer.run();

}

Does it do the same with a simple Blynk sketch?

Is the SPI library necessary for your sketch?

Pete.

Hi Pete thank you for helping me! I don´t need SPI, I have turn´it off. I will upload a simple Blynk sketch and see if I get a different outcome. Maybe I will do a hardware reset every 24 hours if nothing works :wink:

Villi