Made a graft onto a a stump of a male - genetic drift?? we'll see.
So got the code squared away for timing, heat and humidity. Here it is -
#include <RTClib.h>
#include <Wire.h>
//DHT 22 Sensor Libraries
#include "DHT.h"
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; //mostly for diagnostic code during serial printouts
// Main Light variable On/Off times 24hr
// read all notes before setting the variables below
int LightOnHour = 16; //0-23 Actually LightOnHour + or - PeakLightoffset must be between 0 and 23
int LightOnMinute = 0; //0-59
int LightOffHour = 9; //0-23 Actually LightOffHour + or - PeakLightoffset must be between 0 and 23
int LightOffMinute = 0; //0-59
// Peak On/Off times calculated in main loop based on main light on time
int PeakLightoffset = 2; //number of hours to wait before peak on and number of hours prior to main lights off to turn off peak light
int OnTimeCalc = (LightOnHour*60 + LightOnMinute);
int OffTimeCalc = (LightOffHour*60 + LightOffMinute);
int PeakOnHour = (LightOnHour + PeakLightoffset); //current program limitation PeakOn and PeakOff hours must be between 0-23
int PeakOffHour = (LightOffHour - PeakLightoffset); //this means LightOffHour + offset must be 3-23 and LightOnHour - Offset must be 0-20
int PeakOnMinute = (LightOnMinute);
int PeakOffMinute = (LightOffMinute);
int PeakOnTimeCalc = PeakOnHour*60 + PeakOnMinute;
int PeakOffTimeCalc = PeakOffHour*60 + PeakOffMinute;
//UV Variables and Constants
const int UVduration = 25; // duration in minutes uv runs on the hour during peak hours
int VegDays = 60;
int TransitionDays = 14; //Number of days to transition over
int TransitionEndpoint = 11; //Hours of light in a 24hr period
//Set Desired Temperature and humidity parameters
int HighTemp = 55;
int LowTemp = 45;
int HighHumidity = 60;
int LowHumidity = 30;
// Other variables used in calculations. These may get set to zero here, if the main loop is ordered correctly.
int lighttime;
int daycounter;
int reducelighttime;
int daysintransition;
int x;
// Hardware
//Define Relay Pinouts and assign relay off status
int MainLight = 5; // 3 outlets on power strip
int PeakLight = 8; // 3 outlets on power strip
int UVLight = 6; // 1 outlet on power strip
int Heater = 7; // 1 outlet on power strip
int VentFan = 10; // 1 outlet on power strip
int Extra = 8; // 1 outlet on power strip
int MainLightFan = 11; // Fans on MainLight (12V)
int Mist = 12; // Future 12V Solenoid
#define DHT1PIN 3 // Orange wire data pin connected to DHT sensor #1.
#define DHT2PIN 4 // Blue wire data pin conected to DHT sensor #2
// Uncomment the type of sensor in use:
//#define DHTTYPE DHT11 // DHT 11
#define DHT1TYPE DHT22 // DHT 22 (AM2302)
#define DHT2TYPE DHT22
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht1(DHT1PIN, DHT1TYPE);
DHT dht2(DHT2PIN, DHT2TYPE);
void setup ()
{
Serial.begin(9600);
rtc.begin();//start clock
dht1.begin();//start sensors
dht2.begin();
// following line sets the RTC to the date & time this sketch was compiled
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// 8-Channel Relay
pinMode(MainLight, OUTPUT);
pinMode(PeakLight, OUTPUT);
pinMode(UVLight, OUTPUT);
pinMode(Heater, OUTPUT);
pinMode(VentFan, OUTPUT);
pinMode(MainLightFan, OUTPUT);
pinMode(Mist, OUTPUT);
pinMode(Extra, OUTPUT);
//Ensure realys are off at startup
digitalWrite(MainLight, HIGH);
digitalWrite(PeakLight, HIGH);
digitalWrite(UVLight, HIGH);
digitalWrite(Heater, HIGH);
digitalWrite(VentFan, HIGH);
digitalWrite(MainLightFan, HIGH);
digitalWrite(Mist, HIGH);
digitalWrite(Extra, HIGH);
if (OnTimeCalc < OffTimeCalc){
x = 0;
lighttime = (OffTimeCalc - OnTimeCalc); //time in minutes light is on
}else{
x = 1;
lighttime = (1440 - OnTimeCalc + OffTimeCalc); //time in minutes light is on
}
}
void loop () {
DateTime now = rtc.now();
DateTime StartDate (2017,1,10,0,0,0); // Sprouted January 10, 2017 This is the date transition and flower are calculated from
int TimeCalc = now.hour()*60 + now.minute();
int MainLightStatus = digitalRead(MainLight);
int PeakLightStatus = digitalRead(PeakLight);
int currentday = ((now.unixtime()) - (StartDate.unixtime()))/86400;
int differential = lighttime - 60*TransitionEndpoint;
//The if statements below determines if light cycle should be in veg, transition or flower
if ((currentday >= VegDays) & (currentday <= (VegDays + TransitionDays))){
daysintransition = currentday - VegDays;
}
reducelighttime = ((differential*daysintransition)/(TransitionDays));
if (currentday > (VegDays + TransitionDays)){
reducelighttime = differential;
}
//Main Light Timer Peak and UV integrated
switch(x){
case 0:
if ((TimeCalc >= (OnTimeCalc + (reducelighttime/2))) & (TimeCalc < (OffTimeCalc - (reducelighttime/2)))){
switch(MainLightStatus){
case 1: digitalWrite(MainLight, LOW);
delay(3000);
digitalWrite(MainLightFan, LOW);
delay(1000);
break;
case 0:
digitalWrite(MainLight, LOW);
digitalWrite(MainLightFan, LOW);
break;
default:
digitalWrite(MainLight, HIGH);
digitalWrite(MainLightFan, HIGH);
break;}
if (TimeCalc >= (PeakOnTimeCalc + (reducelighttime/2)) & (TimeCalc < (PeakOffTimeCalc - (reducelighttime/2)))){ //Peak Light function
switch(PeakLightStatus){
case 1: digitalWrite(PeakLight, LOW);
delay(3000);
break;
case 0:
digitalWrite(PeakLight, LOW);
break;
default:
digitalWrite(PeakLight, HIGH);
break;}
if (now.minute() >= (60 - UVduration)){ //UV Light function No safety delay included due to low wattage
digitalWrite(UVLight, LOW);
}else{
digitalWrite(UVLight, HIGH);
}}else{
digitalWrite(PeakLight, HIGH);
digitalWrite(UVLight, HIGH);
}}else{
digitalWrite(MainLight, HIGH);
digitalWrite(MainLightFan, HIGH);
digitalWrite(PeakLight, HIGH);
digitalWrite(UVLight, HIGH);
break;
case 1:
if ((TimeCalc >= (OnTimeCalc + (reducelighttime/2))) || (TimeCalc < (OffTimeCalc - (reducelighttime/2)))){
switch(MainLightStatus){
case 1: digitalWrite(MainLight, LOW);
delay(3000);
digitalWrite(MainLightFan, LOW);
delay(1000);
break;
case 0:
digitalWrite(MainLight, LOW);
digitalWrite(MainLightFan, LOW);
break;
default:
digitalWrite(MainLight, HIGH);
digitalWrite(MainLightFan, HIGH);
break;}
if ((TimeCalc >= (PeakOnTimeCalc + (reducelighttime/2))) || (TimeCalc < (PeakOffTimeCalc - (reducelighttime/2)))){ //Peak Light function
switch(PeakLightStatus){
case 1: digitalWrite(PeakLight, LOW);
delay(3000);
break;
case 0:
digitalWrite(PeakLight, LOW);
break;
default:
digitalWrite(PeakLight, HIGH);
break;}
digitalWrite(PeakLight, LOW);
if (now.minute() >= (60 - UVduration)){ //UV Light function No safety delay included due to low wattage
digitalWrite(UVLight, LOW);
}else{
digitalWrite(UVLight, HIGH);
}}else{
digitalWrite(PeakLight, HIGH);
digitalWrite(UVLight, HIGH);
}}else{
digitalWrite(MainLight, HIGH);
digitalWrite(MainLightFan, HIGH);
digitalWrite(PeakLight, HIGH);
digitalWrite(UVLight, HIGH);
}
break;
default:
digitalWrite(MainLight, HIGH);
digitalWrite(MainLightFan, HIGH);
digitalWrite(PeakLight, HIGH);
digitalWrite(UVLight, HIGH);
break;}}
// Temperature and Humidity Controls
//dht1
int h1 = dht1.readHumidity(); // Read humidity RH%
int f1 = dht1.readTemperature(true); // Read temperature as Fahrenheit (isFahrenheit = true) to get celcius false or leave blank
//dht2
int h2 = dht2.readHumidity();
int f2 = dht2.readTemperature(true);
//Check to see if Mist is needed to adjust humidity Do this only when the lights are on
switch(MainLightStatus){
case 0:
if ((now.minute() == 15) || (now.minute() == 30) || (now.minute() == 45) || (now.minute() == 0)){ //check temp and humidity on the quarter hr
if (((h1+h2)/2) < LowHumidity){
digitalWrite(Mist, LOW);
delay(10000);
digitalWrite(Mist, HIGH);
}else{
digitalWrite(Mist, HIGH);
}
}else{
digitalWrite(Mist, HIGH); //Don't know if its actually needed but just to ensure mist is not left on
}
break;
case 1:
digitalWrite(Mist, HIGH);
break;
default:
digitalWrite(Mist, HIGH);
break;
}
//Check to see if heater or fan needs to run (high temp or humidity) every 15 minutes do this regardless if light is on or not
if ((now.minute() == 15) || (now.minute() == 32) || (now.minute() == 45) || (now.minute() == 0)){ //check temp to see if heat is needed
if (((f1+f2)/2) <= LowTemp){
digitalWrite(Heater, LOW);
}else{
digitalWrite(Heater, HIGH);
}
if (((f1+f2)/2) > HighTemp){
delay(2000);
digitalWrite(VentFan, LOW);
delay(3000);
}else{
digitalWrite(VentFan, HIGH);
}
if (((h1+h2)/2) > HighHumidity){
delay(2000);
digitalWrite(VentFan, LOW);
delay(3000);
}}
This pig should fly.