   
   if (startup_seconds > 0) {
     // during startup, sensor needs to settle, so average is allowed to change fast
-    avg = (avg + humidity) / 2;
+    avg = (avg + humidity) / 2.0f;
     startup_seconds -= milliseconds_sleep / 1000;
   } else {
     // decay the old value, combine with the new (reverse decay)
-    avg = avg * (1.0 - avg_decay) + humidity * avg_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.0 - deviation_decay) + max_deviation * deviation_decay;
-  thresholdLow = avg + deviation / 3;
-  thresholdHigh = avg + 2 * deviation / 3;
+  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 = ");

  Serial.print(", thi = ");
  Serial.print(thresholdHigh);
  Serial.print(", dmin = ");
  Serial.print(avg);
  Serial.print(", dmax = ");
  Serial.println(avg + deviation);

  // switch the relays!
  if (humidity < thresholdLow) {

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

