 }
 
 void setup() {
-  // initialize the 11 pin as an output:
   Serial.begin(9600);
-  pinMode(relayPin, OUTPUT);
+  
+  // set relays to normally connected
+  pinMode(K1, OUTPUT);
+  pinMode(K2, OUTPUT);
+  digitalWrite(K1, NormallyConnected);
+  digitalWrite(K2, NormallyConnected);
+
+  // initialize sensor
   pinMode(sensorPin, INPUT);
-  digitalWrite(relayPin, HIGH);
   avg = get_humidity();
 }
 

  thresholdLow = avg + deviation / 3.0f;
  thresholdHigh = avg + 2.0f * deviation / 3.0f;

  // print out the values for debugging/plotting
  Serial.print("humidity = ");
  Serial.print(humidity);
  Serial.print(", tlow = ");
  Serial.print(thresholdLow);
  Serial.print(", thi = ");
  Serial.print(thresholdHigh);
  Serial.print(", dmin = ");
  Serial.print((int)(avg));
  Serial.print(", dmax = ");
  Serial.println((int)(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);
}

#include <Time.h>

// consts for controlling relays
const int K1 = 11;
const int K2 = 12;
const int milliseconds_switch_delay = 100;
const int NormallyConnected = HIGH;
const int NormallyOpen = LOW;


// consts/variables for humidity sensor and averages etc.
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 float avg_decay = 0.00001;
const float deviation_decay = 0.01;

int thresholdLow = 0;
int thresholdHigh = 0;
float avg = 0;
float deviation = 40;
int humidity = 0;
int startup_seconds = 900; // sensor needs to settle for 15 minutes
int on_off = 0;

int get_humidity() {
  int sensorValue = analogRead(sensorPin);
