Program sents information only for few seconds.

Hi
When i don't have my Serial port monitor turned on arduino only sends information for few seconds and after a while it restarts but when I turn on the Serial port monitor it runs until i close the port monitor.
Do you know how to solve this?
Thanks in advance.

You have given us nothing to go on to start troubleshooting unfortunately..

  • Start by providing your current, compiling code (wrapped in CODE tags please!)

  • How do you know your Arduino is sending/doing ANYTHING if the serial monitor window is NOT open? (ie: how do you know 'something' is no longer sending after a few seconds?)

  • FYI:
    When opening and closing the serial monitor, it resets the Arduino. (You need to add a hack/fix to stop the resetting if desired)

This is my code:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display = Adafruit_SSD1306();



#define LED      13

#define gora 3 //10
#define luz 5 //11
#define dol 6 //12


int bieg ;
int bieg1 = 1;

int ThermistorPin = 0;
int Vo;
float R1 = 10000;
float logR2, R2, T;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
int n = 0;
int q = 0;

int tempSilnika;
int czujnik;

void setup() {  
  delay(2000);
  Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC);  
  display.clearDisplay();

    display.drawBitmap(0,0,vara,128,20,WHITE);
      
 
    display.display();

    delay(2000);
  
    pinMode(dol,INPUT_PULLUP);
    pinMode(luz,INPUT_PULLUP);
    pinMode(gora,INPUT_PULLUP);

    display.clearDisplay();
}
void loop() {
  
  
  
  display.setTextColor(WHITE);
  display.setTextSize(2);
  display.setCursor(0,0);
  
  
  firstPage();

  temperature();

  gears();

  engineTemp();

  display.display();

 

 Serial.println(n); 

 delay(100);
}

void firstPage ()
{
  display.clearDisplay();
  display.drawBitmap(0,0,temp,35,35,WHITE);


  
}

void temperature(){

  Vo = analogRead(ThermistorPin);
  R2 = R1 * (1023 / (float)Vo - 1);
  logR2 = log(R2);
  T = (1 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  T = T - 273;
  n = T;


  if (n < -20){
    display.setTextSize(3);
    display.setCursor(0,40);
    display.print("--");
  }

  if (n >= -20){
  display.setTextColor(WHITE);          //** WyĹ›wietla temperature na ekranie
  display.setTextSize(3);
  display.setCursor(0,40);
  display.print(n);                     //** 
  }
}

void gears(){
  if (digitalRead(luz) == LOW){                        //LUZ 
  display.drawBitmap(22,0,neutral,80,64,WHITE);
  bieg = 0;
  bieg1 = 1;

  
  }
  if (digitalRead(dol) == LOW  && bieg1 == 1){       //1
    bieg = 1;
    while (digitalRead(dol) == LOW && bieg1 == 1);       
   }
  if (bieg == 1 && bieg1 < 2){
    display.setTextSize(9);
    display.setCursor(38,0);
    display.print("1");
  }
  if (digitalRead(gora) == LOW && bieg1 < 5){         //zmiana biegĂłw
    bieg1++;
   while (digitalRead(gora) == LOW);

  }

  
    
  if (bieg > 5){
    bieg = 5;
  }

  if (digitalRead(dol) == LOW && bieg1 >=1 ){
    bieg1--;
   while (digitalRead(dol) == LOW);
  }



  display.setTextSize(9);
  display.setCursor(38,0);
  
  switch(bieg1){
    case 2:
    display.print("2");
    break;
    case 3:
    display.print("3");
    break;
    case 4:
    display.print("4");
    break;
    case 5:
    display.print("5");
    break;
   }                              //koniec zmiany biegĂłw
  
  

  
}
void engineTemp(){
  display.drawBitmap(89,0,tempsilnik,35,35,WHITE); 

  czujnik = analogRead(A3);
  tempSilnika = map(czujnik,1,1021,0,130);



  display.setTextColor(WHITE);
  display.setTextSize(3);
  display.setCursor(89,40);
  display.print(tempSilnika);
}

I can see the arduino’s TX led flashing and from what i know it lits up when it sends something. And after few seconds it stops flashing. When i open Serial monitor it works annd flashes all the time.