Project works, but loses data connection to pc after a while

I’m trying to figure out why my arduino loses connection to my pc after a while. To fix it I have to go into device manager and disable the arduino and then enable it. This is frustrating because it happens once a day. The program on the arduino still runs just fine though which is the most important part. I’m assuming there is a mistake with my code somewhere, so I’ve attached it. I pieced this code together from various sources. I’m no programmer so please forgive what I’m sure is a programmers worst nightmare :). Also a little background of what this is and does. I have two temp sensors I’m using, inside and outside. One is hooked up to a solar heater and the other one is in a water tank. The arduino monitors the collector temp and then turns a pump on or off based on the temp. It also spits out logging information to gobetweeno so I can keep logs.

// This Arduino sketch reads DS18B20 "1-Wire" digital
// temperature sensors.
// Tutorial:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 10

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress insideThermometer = { 0x28, 0x4C, 0xF0, 0x4A, 0x04, 0x00, 0x00, 0xD5 };
DeviceAddress outsideThermometer = { 0x28, 0x79, 0x35, 0x4A, 0x04, 0x00, 0x00, 0x23 };
DeviceAddress dogHouseThermometer = { 0x28, 0x59, 0xBE, 0xDF, 0x02, 0x00, 0x00, 0x9F };

int ledPin = 13;                 // LED connected to digital pin 13
char buffer[5];

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(outsideThermometer, 10);
  sensors.setResolution(insideThermometer, 10);
  sensors.setResolution(dogHouseThermometer, 10);
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

float getTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } 
  else 
  {

  }
 return tempC; 
}

void loop(void)
{ 
  
  //Serial.print("Getting temperatures...\n\r");
  sensors.requestTemperatures();
  float tank = getTemperature(insideThermometer);
  float collector = getTemperature(outsideThermometer);
  

   // Serial.print("Temp of collector is:, ");
   // Serial.print(DallasTemperature::toFahrenheit(collector));
   // Serial.print("F, ");
   // Serial.print(collector);
   // Serial.print("C,");
   // Serial.print("\n\r");

   // Serial.print("Temp of tank is:, ");   
   // Serial.print(DallasTemperature::toFahrenheit(tank));
   // Serial.print("F, ");
   // Serial.print(tank);
   // Serial.print("C,");
   // Serial.print("\n\r");
   
 
  Serial.print("#S|COLLECTOR|[");
  //Serial.print("Collector: ");
  //Serial.print(" ");
  Serial.print(itoa((DallasTemperature::toFahrenheit(collector)), buffer, 10));
  Serial.print(";"); 
  Serial.print(itoa((DallasTemperature::toFahrenheit(tank)), buffer, 10)); 
  Serial.println("]#");  
  
  
  if (collector > 49)
  {
    digitalWrite(ledPin, HIGH);   // sets the LED on
    delay(20000); // this is so the pump doesn't turn off and on 1000 times as the temp is close to the trigger temp
  }  
  else
  {
    digitalWrite(ledPin, LOW);    // sets the LED off 
    
    if (collector < 21)
    {
   delay(900000); // this will wait 15 minutes if the collector is cold.
    } //end collector < 21
    
    if (collector >= 21 && collector <= 49)
    {
    delay(10000); // this will wait 10 seconds between readings when the temp is close to getting hot enough
    } //end if collector > 21 an < 49
    
  }//end if collector > 26
  
} //end void loop

Your setup is far too complicated. The serial monitor of the Arduino IDE uses a Java RX TX module, that is not very stable.

Could you do a test. Don't start the Arduino IDE. Try a very simple serial monitor with logging. I use the Q Serial Terminal, http://qst.sourceforge.net/ Don't use the gobetweeno, only the Arduino board and the Q Serial Terminal.

Let it run for a few days. If that doesn't work, I have to know a few things: - Which Arduino board. - How is it powered. - How is the heater controlled.

P.S.: I did not look at the code yet. But it looks as if two conditional tests are not needed. Try writing the if...else... again.

Thanks for the input I'll give it a shot. Q serial terminal crashes when I change my baud and hit ok so this might take a while.

Edit: I had to click my com port first apparently. It's running now we'll see how it does for the next few days.

One other thing, the reason I started using gobetweeno was because it enabled me to log the time with my temp data. I don't see any way to do tht with q terminal unless you know of a way.

No, sorry, I don't know how to get the time with it. Others use other serial terminal programs. I don't know any that has timestamps. Perhaps this one, http://realterm.sourceforge.net/

That works and I have a timestamp nice. I'll let it run for a few days and see how it does. Thanks for your help.

How long ago i it that you downloaded GoBetwino ?

I uploaded a version that fixed a bug that would only show up if Arduino was sending data to GoBetwino for a long time. This would cause the PC to become really slow and semi unresponsive.