#include <DHT.h>;

//Constants
#define DHT_OUT_PIN 2     // what pin we're connected to
#define DHT_OUT_TYPE DHT22   // DHT 22  (AM2302)
#define DHT_DUCK_PIN 3     // what pin we're connected to
#define DHT_DUCK_TYPE DHT22   // DHT 22  (AM2302)

#define DUCK_VENT_PIN 13     // what pin we're connected to

DHT dhtOut(DHT_OUT_PIN, DHT_OUT_TYPE); //// Initialize DHT sensor for normal 16mhz Arduino
DHT dhtDuck(DHT_DUCK_PIN, DHT_DUCK_TYPE); //// Initialize DHT sensor for normal 16mhz Arduino

//Variables
int chk;
int DUCK_VENT_STATUS = 0;
float humOut;  //Stores humidity value
float tempOut; //Stores temperature value
float humDuck;  //Stores humidity value
float tempDuck; //Stores temperature value

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
	dhtOut.begin();
	dhtDuck.begin();
  pinMode(DUCK_VENT_PIN, OUTPUT);
}

void loop() {
    //Read data and store it to variables hum and temp
    humOut = dhtOut.readHumidity();
    tempOut = dhtOut.readTemperature();
    humDuck = dhtDuck.readHumidity();
    tempDuck = dhtDuck.readTemperature();
    
    //too wet in duck house
    if (humDuck > 70) {
      if (DUCK_VENT_STATUS == 0 && humOut < humDuck) {
          DUCK_VENT_STATUS = 1;
          digitalWrite(DUCK_VENT_PIN, HIGH);  
      }
    }
    //normal humidity in duck house
    if (humDuck <= 70) {
      if (DUCK_VENT_STATUS == 1) {
        DUCK_VENT_STATUS = 0;
        digitalWrite(DUCK_VENT_PIN, LOW);
      }
    }
       
    Serial.print("Humidity: ");
    Serial.print(humOut);
    Serial.print(" %, ");
    Serial.print(humDuck);
    Serial.print(" %; Temp: ");
    Serial.print(tempOut);
    Serial.print(" C, ");
    Serial.print(tempDuck);
    Serial.println(" C");
    delay(2000); //Delay 2 sec.
}