   Serial.println(avg + deviation);
 
   // switch the relays!
-  if (sensorValue < thresholdLow) {
+  if (humidity < thresholdLow) {
     // HIGH means setting the relay to NC
-    digitalWrite(relaisPin, HIGH);
-  } else if (sensorValue > thresholdHigh) {
+    digitalWrite(relayPin, HIGH);
+  } else if (humidity > thresholdHigh) {
     // LOW means setting the relay to NO
-    digitalWrite(relaisPin, LOW); 
+    digitalWrite(relayPin, LOW); 
   }
   delay(milliseconds_sleep);
 }

    // decay the old value, combine with the new (reverse decay)
    avg = avg * (1.0 - avg_decay) + humidity * avg_decay;
  }
  int cur_deviation = max(deviation, humidity - avg);
  deviation = deviation * (1.0 - deviation_decay) + cur_deviation * deviation_decay;
  thresholdLow = avg + deviation / 3;
  thresholdHigh = avg + 2 * deviation / 3;


void setup() {
  // initialize the 11 pin as an output:
  Serial.begin(9600);
  pinMode(relayPin, OUTPUT);
  pinMode(sensorPin, INPUT);
  digitalWrite(relayPin, HIGH);
  avg = get_humidity();
}

