//********************************************************// includes libraries needed for code functionality and defines system parameters #include // includes DHT.h library for DHT11 Sensor #include // includes Wire.h library circuit functionality #include // include library for LCD display #define DHTPIN 2 // what digital pin we're connected to #define DHTTYPE DHT11 // defines DHT11 as the type of DHT sensor it is DHT dht(DHTPIN, DHTTYPE); // initializes the DHT11 sensor byte degree[8] = // create (') character before ("C") temperature unit { 0b00011, 0b00011, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000 }; LiquidCrystal lcd( 37, 36, 35, 34, 33, 32); // indicats which pins the LCD is connect to int int_Pin0=3; // defines the interrupt pin_0 to pin3 of arduino int PumpOFFflag = 0; // defines the value to the interrupt that toggles pump function on and off unsigned long Timer_Off_Lights =15000; ////changed Pump to Lights unsigned long time_pre=0, time_new=0, time_diff=0; // sets up mathmatical value parameters for the lights unsigned long time_LightsOn=0, time_diff_LightsOn=0; //states mathmatical values for when the lights turn on and off #define RELAY1 11 // RELAY1 connected to pin 11 #define RELAY2 10 // RELAY2 connected to pin 10 #define RELAY3 9 // RELAY3 connected to pin 9 #define RELAY4 8 // RELAY4 connected to pin 8 //*********************************************** //*********// Initialize the setup for your arduino void setup() { Serial.begin(9600); // Serial.println("Greenhouse Weather Station"); // lcd.begin(20,4); // lcd.createChar(1, degree); // lcd.clear(); // lcd.setCursor(0, 0); // lcd.print("Temp Humidity"); // lcd.setCursor(0, 1); // lcd.print("C:"); // lcd.setCursor(9, 1); // lcd.print("H:"); // lcd.setCursor(0,3); // lcd.print("Fan:"); // dht.begin(); // //********************************************** //*********************************************// Initialize Pins so relays are OFF at reset digitalWrite(RELAY1, HIGH); digitalWrite(RELAY2, HIGH); digitalWrite(RELAY3, HIGH); digitalWrite(RELAY4, HIGH); delay(900); //*********************************************** //**********************************************// Initialize the Arduino pins for OUTPUT and INPUT pinMode(RELAY1, OUTPUT); pinMode(RELAY2, OUTPUT); pinMode(RELAY3, OUTPUT); pinMode(RELAY4, OUTPUT); pinMode(DHTPIN, INPUT); pinMode(13, OUTPUT); // declared pin13 as output to use LED light to test parts of circuit individually pinMode(int_Pin0, INPUT); attachInterrupt(digitalPinToInterrupt(int_Pin0), StopPumps, RISING); // delay(900); // } //*********************************************** //***********************************************// void set up which allows for parallel functioning void StopPumps() { digitalWrite(RELAY1, HIGH); // tells interrupt that the water pump should be off (when parameters are met) digitalWrite(RELAY2, HIGH); // tells interrupt that the air pump whould be off (when parameters are met) digitalWrite(13,HIGH); // This was used to test the interrupts functionallity with led lights on protoboard digitalWrite(13,LOW); // This was used to test the interrupts functionallity with led lights on protoboard } //*********************************************** //*********************************************// continuously ran programming for arduino void loop() { time_new = millis(); //declares time in milliseconds time_diff = time_new-time_pre; // mathmatical parameter for measuring time for lights function Serial.print("time_diff ="); // states what is to be printed to serial monitor Serial.println(time_diff); // prints to serial monitor for visualizing what the circuit is doing if (time_diff < Timer_Off_Lights) // if, time_diff in time measured is less than Timer_Off_Lights (15 seconds), the below functions is active { digitalWrite(RELAY4, LOW); // tells the relay to turn lights on } else if (time_diff < 30000) // when the time_diff is >15000 ms but <30000 ms the below function is active { //the above line also sets 30000 ms as the limit to measured time and resets back to 0 ms as measured time passes 30000 ms digitalWrite(RELAY4, HIGH); // tells relay to turn the lights off } else { time_pre=time_new; // } PumpOFFflag = digitalRead(int_Pin0); // if (PumpOFFflag==0) // { digitalWrite(RELAY1, LOW); // digitalWrite(RELAY2, LOW); // } int h = dht.readHumidity(); // defines h to read humidity as % int t = dht.readTemperature(); // defines t read temperature as Celsius (the default) int f = dht.readTemperature(true); // defines f read temperature as Fahrenheit (isFahrenheit = true) if(t<26 ) // { lcd.setCursor(5, 4); // digitalWrite(RELAY3,HIGH); // lcd.print("OFF"); // delay(900); // } else if(t>=26) // { lcd.setCursor(5, 4); // digitalWrite(RELAY3,LOW); // lcd.print("ON "); // delay(900); // } Serial.print("H: "); // Serial.print(h); // Serial.print(" %\t"); // Serial.print("T: "); // Serial.print(t); // Serial.print(" *C "); // Serial.println(); // if (isnan(h) ||isnan(t) || isnan(f)) // { Serial.println("Failed to read from DHT sensor!"); // return; // } lcd.setCursor(3, 1); // lcd.print(dht.readTemperature()); // Serial.print("Temperature (oC): "); // Serial.println(dht.readTemperature()); // lcd.setCursor(12, 1); // lcd.print(dht.readHumidity()); // lcd.print("%"); // Serial.print("Humidity (%): "); // Serial.println(dht.readHumidity()); // delay(900); // } //****************************************************************//end of sketch!