 #include <Time.h>
 
-const int relaisPin =  11;
+const int relayPin =  11;
 const int sensorPin = A0;    // select the input pin for the potentiometer
 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 sensorValue = 0;  // variable to store the value coming from the sensor
 int thresholdLow = 0;
 int thresholdHigh = 0;
 int avg = 0;

    // 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;


  Serial.println(avg + deviation);

  // switch the relays!
  if (humidity < thresholdLow) {
    // HIGH means setting the relay to NC
    digitalWrite(relayPin, HIGH);
  } else if (humidity > thresholdHigh) {
    // LOW means setting the relay to NO
    digitalWrite(relayPin, LOW); 
  }
  delay(milliseconds_sleep);
}
