   Serial.print(", thi = ");
   Serial.print(thresholdHigh);
   Serial.print(", dmin = ");
-  Serial.print(avg);
+  Serial.print((int)(avg));
   Serial.print(", dmax = ");
-  Serial.println(avg + deviation);
+  Serial.println((int)(avg + deviation));
 
   // switch the relays!
   if (humidity < thresholdLow) {

const int MINHUMIDITY = 0;
const int MAXHUMIDITY = 1023;
const int milliseconds_sleep = 5000;
const int avg_decay = 0.00001;
const int deviation_decay = 0.01;
int thresholdLow = 0;
int thresholdHigh = 0;
int avg = 0;
int deviation = 20;
int humidity = 0;
int startup_seconds = 900; // sensor needs to settle for 15 minutes


  
  if (startup_seconds > 0) {
    // during startup, sensor needs to settle, so average is allowed to change fast
    avg = (avg + humidity) / 2.0f;
    startup_seconds -= milliseconds_sleep / 1000;
  } else {
    // decay the old value, combine with the new (reverse decay)
    avg = avg * (1.0f - avg_decay) + humidity * avg_decay;
  }
  // don't use math inside max(), it causes undefined behaviour (see docs)
  int cur_deviation = humidity - avg;
  int max_deviation = max(deviation, cur_deviation);
  deviation = deviation * (1.0f - deviation_decay) + max_deviation * deviation_decay;
  thresholdLow = avg + deviation / 3.0f;
  thresholdHigh = avg + 2.0f * deviation / 3.0f;

  // print out the values for debugging/plotting
  Serial.print("humidity = ");
