Here is the Arduino code to run my tent:
/* This program runs a cannabis grow tent.
* The tent is equipped with DIY COB LED lights,
* active heatsink cooling on the COBs
* 730nm SemiLeds for phytochrome manipulation
* CO2 from compressed cylinder injected based calculated flow rate per cubic foot
* exhaust fan to control heat and humidity
* It will determine the time point of the active 24 hour cycle and resume
* running at the real time point after a power failure.
* INPUT the hour for the lights to come on(LightsOnH),
* INPUT the minutes for the lights to come on(LightsOnM)
* INPUT Lights On run time (LORTime)
* It requires a DS3231 time clock
* The CO2 cycle is based on the observed heat load in the tent wihch allows a 40 minute cycle
*/
#include <DS3231.h> // real time clock library
int LightsOnH = 17; //Hour of day to turn the lights on (0 - 23)
int LightsOnM = 15; //Minute of hour to turn lights on (0 - 59)
//Seconds not set default = 0
int LORTime = 18; //Length of Lights On in hours (12 or 10.5)
int FarRedOn = 900; //Turn 730nm lights on for 15 minutes
int WakeUpDelay = 2400; //40 minute plant wakeup time in seconds before CO2
long UST; //Calc lightsOnTime as a unix in this 24 hour cycle
int myyear; //current year
int myday; //current day
int mymonth; //current month
long UTNow; //unix time now
long DarkTime; //Lights off time in seconds
long LOT; //hold calculated LORTime
long CGasOn;
long GasOn;
long GasOff = 2700;
// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL);
// Init a Time-data structure
Time t;
void setup() {
// Setup Serial connection
//Serial.begin(9600);
// Initialize the rtc object
rtc.begin();
digitalWrite(5, HIGH); // this relay is OFF on HIGH
digitalWrite(9, HIGH); // this relay is OFF on HIGH
pinMode(5, OUTPUT); //Cob Fans
pinMode(6, OUTPUT); // COB LIGHTS
pinMode(9, OUTPUT); //730nm lights
pinMode(10, OUTPUT); //CO2
pinMode(11, OUTPUT); //Exhaust Fan
// The following lines can be uncommented to set the date and time in the DS3231
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(1, 1, 2014); // Set the date to January 1st, 2014
t = rtc.getTime(); //Get time and date
myyear = t.year; //set to current year
myday = t.date; //set to current day
mymonth = t.mon; //set to current month
t.hour = LightsOnH; // determine the unix time for LightsOn time in this 24 hour cycle
t.min = LightsOnM;
t.sec = 0;
t.year = myyear;
t.mon = mymonth;
t.date = myday;
UST = (rtc.getUnixTime(t)); //LightsOn "UnixStartTime"
LOT = LORTime * 3600u; //Lights On length in seconds 64800
DarkTime = 86400u - LOT; //Calculate DarkTime 21600
DarkTime=DarkTime-FarRedOn; //Take FarRed out of DarkTime 20700
LOT = LOT + FarRedOn; //Add FarRedOn time 900+ 65700
LOT = LOT -WakeUpDelay; //Subtract WakeUpDelay 2400- 63300
LOT = LOT - GasOff; //Subtract GasOff EOD 3600- 59700
}
void loop() {
UTNow = (rtc.getUnixTime(rtc.getTime())); //get current unix time
// wait until lights on time
while(UTNow < UST){
UTNow = (rtc.getUnixTime(rtc.getTime()));
}
//Wake plants up
digitalWrite(10, LOW); //set CO2 off
digitalWrite(9, HIGH); //set 730nm lights off
digitalWrite(5, LOW); //turn cob fans on
digitalWrite(11, HIGH); //turn exhaust fan on
digitalWrite(6, HIGH); //turn cobs on
while(UTNow >= UST && UTNow <= UST + WakeUpDelay){
UTNow = (rtc.getUnixTime(rtc.getTime())); //get current unix time
}
/*Start CO2 cycle and set stop CO2 at 45 minutes before DarkTime minus run over
* each CO2 cycle is 40 minutes long
*/
while(UTNow >= UST + WakeUpDelay && UTNow <= UST + WakeUpDelay + LOT){
digitalWrite(6, HIGH); //Turn Cobs on needed in case of power outage
digitalWrite(5, LOW); //turn cob fans on needed in case of power outage
digitalWrite(11, LOW); //turn exhaust fan off
digitalWrite(10, HIGH); // turn gas on
delay (180000); // gas on for 3 minutes
digitalWrite(10, LOW); // turn gas Off
delay (420000); //wait 7 minutes
digitalWrite(10, HIGH); // turn gas on
delay (60000); // gas on for 1 minute
digitalWrite(10, LOW); // turn gas off
delay (540000); // wait 9 minutes
digitalWrite(10, HIGH); // turn gas on
delay (60000); // gas on for 1 minute
digitalWrite(10, LOW); // turn gas off
delay (540000); // wait 9 minutes
digitalWrite(11, HIGH); //turn fan on
delay (600000); // run exhast fan 10 minutes
UTNow = (rtc.getUnixTime(rtc.getTime())); // get the time
}
//Stop CO2 prior to lights out
digitalWrite(10, LOW); //turn CO2 off needed in case of power outage
digitalWrite(11, HIGH); //turn exhaust fan on needed in case of power outage
digitalWrite(5, LOW); //turn cob fans on needed in case of power outage
digitalWrite(6, HIGH); //Turn Cobs on needed in case of power outage
digitalWrite(9, HIGH); //turn 730nm off needed in case of power outage
//wait for lights out time
while(UTNow >= UST + WakeUpDelay + LOT && UTNow <= UST + WakeUpDelay + LOT + GasOff){
UTNow = (rtc.getUnixTime(rtc.getTime()));
}
// run 730nm lights for 15 minutes
digitalWrite(6, LOW); //turn cobs off
digitalWrite(9, LOW); //turn 730nm on
digitalWrite(10, LOW); //turn CO2 off needed in case of power outage
digitalWrite(11, HIGH); //turn exhaust fan on needed in case of power outage
digitalWrite(5, LOW); //turn cob fans on needed in case of power outage
while(UTNow >= UST + WakeUpDelay + LOT + GasOff && UTNow <= UST + WakeUpDelay + FarRedOn + LOT + GasOff){
UTNow = (rtc.getUnixTime(rtc.getTime()));
}
//start night
digitalWrite(6, LOW); //turn cobs off
digitalWrite(9, HIGH); //turn 730nm off
digitalWrite(10, LOW); //turn CO2 off needed in case of power outage
digitalWrite(11, HIGH); //turn exhaust fan on needed in case of power outage
digitalWrite(5, HIGH); //turn cob fans off needed in case of power outage
while(UTNow >= UST + WakeUpDelay + FarRedOn + LOT && UTNow <= UST + WakeUpDelay + FarRedOn + DarkTime + LOT + GasOff){
UTNow = (rtc.getUnixTime(rtc.getTime()));
}
//Night over
t = rtc.getTime(); //Get time and date
myyear = t.year; //set to current year
myday = t.date; //set to current day
mymonth = t.mon; //set to current month
t.hour = LightsOnH; // get unix time for LightsOn in this 24
t.min = LightsOnM; //hour cycle.
t.sec = 0;
t.year = myyear;
t.mon = mymonth;
t.date = myday;
UST = (rtc.getUnixTime(t)); //unix lightsOn time
}