├── EEPROM n things.ods ├── README.md ├── RTC_Set └── RTC_Set.ino └── yieldbuddy_arduino ├── CheckSetPoints_functions.ino ├── Date_functions.ino ├── EEPROM_functions.ino ├── Relay_functions.ino ├── RestoreDefaults_functions.ino ├── Serial_functions.ino ├── Timer_functions.ino ├── UpdateSensors_functions.ino ├── readme └── yieldbuddy_arduino.ino /EEPROM n things.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yieldbuddy/arduino_mega/326b144ae1a47ccd4227db0553d19e531c37bd8d/EEPROM n things.ods -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | The default Username and Password are both: default 2 | 3 | See the Raspberry Pi folder's 'readme' for more details. 4 | 5 | yieldbuddy v1.17a - May 5, 2013 6 | 7 | -Switched everything from MySQL to SQLite3 8 | -Uses nginx instead of Apache 9 | -Python script much more reliable, and now with event logging 10 | -void main() in the arduino sketch has a section for restoring defaults (just uncomment, run, then comment out again) 11 | -Updated look of web interface, fixed up some code. 12 | -Updates database only when values change now, increasing performance of the script by a lot 13 | -Warning: Shuts down anything accessing database when it starts 14 | -Data points are taken at regular time intervals now. Default: 90 seconds (960 points / day) 15 | -Switched graphs from High Charts to Google Charts (uses Flash instead of Java) 16 | -Added log to 'System' page 17 | -More error handling 18 | -Some minor interface changes in the Python Script, also lists Interface IP Addresses 19 | -Changed all paths to reference Server Root, so everything can be run in a different location (not just /var/www). This was so you can run yieldbuddy on a USB flash drive and save your SD card from too many read/writes 20 | -Activated analog read of TDS1, TDS2, and CO2 sensors (see sensor functions in Arduino sketch to change the formulas to match that of your equipment [datasheets]) 21 | -Updated install script - let me know how it goes on the forum, as I manually installed so this should work 22 | 23 | yieldbuddy v1.16 - Mar 28, 2013 24 | 25 | -Fixed set arduino time under system 26 | -Fixed RTC setup sketch to use only the DS1307RTC library 27 | -Split sketch into seperate files 28 | -Fixed relay buttons on overview.php into a table 29 | -Removed lighting and watering pages and put them on a new timers page 30 | -Updated scripts to ensure yieldbuddy and wireless connection both stay up and running 31 | -Added Email Address & Camera Connectback Address Settings to the Settings Page 32 | -Added Alarms for the setpoint values which will automatically email you if out of range 33 | -Encrypts email password as a hash in sql database and generates a new random key everytime you click "Save Email Settings". 34 | (Doesn't store plaintext password, for better security) 35 | -Cleaned up code a bit, with better error handling. 36 | 37 | yieldbuddy v1.15c 38 | -Created a daemon script that constantly checks to make sure your connected to your network (wlan0) and to make sure yieldbuddy is running 39 | -Updated install script, again. 40 | -Added redirect so you don't have to go to /yieldbuddy/www anymore ---> /yieldbuddy 41 | 42 | yieldbuddy v1.15b 43 | -Updated install script - tested and works. 44 | -Raspberry Pi SD Image available on www.yieldbuddy.com 45 | 46 | 47 | ---Forum is up and running--- 48 | 49 | 50 | yieldbuddy v1.15 51 | -Data logging is done to an SQL Database now (runs a lot faster now) 52 | -Manual/Auto Relay Modes 53 | -HighChart graphs added that display information from SQL Database (zoomable) 54 | -Added Cambozola applet for viewing streaming webcam via motion 55 | -Added a couple scripts that act like daemons checking to see if the wireless connection is still alive, if not, restart connection and another to check to make sure yieldbuddy is still running, if not, restarts yieldbuddy. 56 | -Install script for Raspberry Pi added 57 | 58 | 59 | Project Name Changed To: yieldbuddy 60 | Website: www.yieldbuddy.com is alive! 61 | 62 | 63 | Environment Controller v1.14b 64 | -Fixed Water Timer issue going from PM to AM 65 | 66 | Environment Controller v1.14 67 | -Sessions are now used and you are required to login. See the readme in the Raspberry Pi folder for more details. (username: default password: default) 68 | -Added data-parsing capabilities for settings, information, etc to the arduino 69 | -Added "Lighting", "Watering", "Set Points", "System" pages 70 | -Added Time Settings to System Page 71 | -Added Restore Defaults to System Page <-- Recommended after fresh firmware upgrade! 72 | -Tested/Fixed timer issues 73 | -envirocontrol.py lists/asks for the path of the serial device you would like to use upon startup 74 | 75 | Environment Controller v1.13 76 | -Fixed up touchscreen interface (odd touchscreen coordinates) 77 | -New 'Defaults" button under 'Settings' (Arduino) writes settings to EEPROM (Run this after a fresh install to avoid bugs!) 78 | -Updated Python script for less data points (making big log files) 79 | 80 | Environment Controller v1.12 81 | -Bundled everything a little nicer 82 | -Included some 'readme' files :) 83 | -Some files were missing; everything is complete, organized and easier to understand. 84 | 85 | Environment Controller v1.11 86 | -Graph generates automatically 87 | -Edited gnuplot plotData.plt file 88 | -Fixed Read Fail's 89 | -Added firmware upload for arduino (new file: upload.php) 90 | -Renamed dataLogger.py (python script) to envirocontrol.py 91 | 92 | Environment Controller v1.10 93 | -Basic Frontend for Sensor Values and Relay Controls 94 | -Python script for rx/tx through serial port (USB RS-232) 95 | 96 | Environment Controller v1.0 97 | -Basic Ardunio Code working with Touchscreen 98 | -------------------------------------------------------------------------------- /RTC_Set/RTC_Set.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | boolean FirstTimeSet = false; 7 | time_t t = now(); 8 | String Months[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; 9 | 10 | void setup () { 11 | Serial.flush(); 12 | Serial.begin(115200); 13 | Serial.println(__DATE__); 14 | Serial.println(__TIME__); 15 | Serial.println(); 16 | char DateChar[] = __DATE__; 17 | char TimeChar[] = __TIME__; 18 | Serial.print("Now(): "); 19 | Serial.println(now() ); 20 | Serial.println(); 21 | 22 | int i = 0; 23 | String Date_buffer; 24 | String Date[4]; 25 | int j = 0; 26 | while(i < sizeof(DateChar)){ 27 | if (DateChar[i] != ' '){ 28 | Date_buffer = Date_buffer + DateChar[i]; 29 | } else { 30 | Date[j] = Date_buffer; 31 | Date_buffer = ""; 32 | Serial.print("Date["); 33 | Serial.print(j); 34 | Serial.print("] = "); 35 | Serial.println(Date[j]); 36 | j++; 37 | } 38 | i++; 39 | } 40 | Date[2] = Date_buffer; 41 | Serial.print("Date[2] = "); 42 | Serial.println(Date[2]); 43 | 44 | int k = 0; 45 | while(Months[k] != Date[0]){ 46 | k++; 47 | } 48 | 49 | Serial.print("Month: "); 50 | Serial.println(k+1); 51 | Serial.print("Day: "); 52 | Serial.println(Date[1]); 53 | Serial.print("Year: "); 54 | Serial.println(Date[2]); 55 | 56 | int New_month = k+1; 57 | int New_day = stringToInt(Date[1]); 58 | int New_year = stringToInt(Date[2]); 59 | 60 | Serial.println(); 61 | 62 | 63 | i = 0; 64 | String Time_buffer; 65 | String Time[4]; 66 | j = 0; 67 | while(i < sizeof(TimeChar)){ 68 | if (TimeChar[i] != ':'){ 69 | Time_buffer = Time_buffer + TimeChar[i]; 70 | } else { 71 | Time[j] = Time_buffer; 72 | Time_buffer = ""; 73 | Serial.print("Time["); 74 | Serial.print(j); 75 | Serial.print("] = "); 76 | Serial.println(Time[j]); 77 | j++; 78 | } 79 | i++; 80 | } 81 | Time[2] = Time_buffer; 82 | Serial.print("Time[2] = "); 83 | Serial.println(Time[2]); 84 | 85 | Serial.print("Hour: "); 86 | Serial.println(Time[0]); 87 | Serial.print("Minute: "); 88 | Serial.println(Time[1]); 89 | Serial.print("Second: "); 90 | Serial.println(Time[2]); 91 | 92 | int New_hour = stringToInt(Time[0]); 93 | int New_minute = stringToInt(Time[1]); 94 | int New_second = stringToInt(Time[2]); 95 | 96 | //setTime(hr,min,sec,day,month,yr) 97 | setTime(New_hour,New_minute,New_second,New_day,New_month,New_year); //<------------ The time will be the time at which this sketch was compiled, otherwise specify a time here. 98 | 99 | Serial.println(); 100 | Serial.print("Now(): "); 101 | Serial.println(now() ); 102 | Serial.println(); 103 | 104 | RTC.set(now()+10); //add ten seconds for upload time. 105 | 106 | } 107 | 108 | int stringToInt(String string){ 109 | 110 | char char_string[string.length()+1]; 111 | string.toCharArray(char_string, string.length()+1); 112 | 113 | return atoi(char_string); 114 | } 115 | 116 | void loop () { 117 | 118 | delay(3000); 119 | } 120 | -------------------------------------------------------------------------------- /yieldbuddy_arduino/CheckSetPoints_functions.ino: -------------------------------------------------------------------------------- 1 | /* 2 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3 | /!!CHECK SETPOINTS!!CHECK SETPOINTS!!CHECK SETPOINTS!!CHECK SETPOINTS!!CHECK SETPOINTS!!CHECK SETPOINTS!!CHECK SETPOINTS!!CHECK SETPOINTS!!CHECK SETPOINTS!!CHECK SETPOINTS!!CHECK SETPOINTS!!CHECK SETPOINTS!!CHECK SETPOINTS!!CHECK SETPOINTS!! 4 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 5 | 6 | Here you can create different statements to control your various devices/equipment with the relays. 7 | 8 | */ 9 | 10 | 11 | void CheckSetPoints(){ 12 | 13 | 14 | } 15 | -------------------------------------------------------------------------------- /yieldbuddy_arduino/Date_functions.ino: -------------------------------------------------------------------------------- 1 | /* 2 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3 | /!!UPDATE LONG DATE!!UPDATE LONG DATE!!UPDATE LONG DATE!!UPDATE LONG DATE!!UPDATE LONG DATE!!UPDATE LONG DATE!!UPDATE LONG DATE!!UPDATE LONG DATE!!UPDATE LONG DATE!!UPDATE LONG DATE!!UPDATE LONG DATE!!UPDATE LONG DATE!!UPDATE LONG DATE!!UPDATE LONG DATE!! 4 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 5 | */ 6 | void updatelongdate() { 7 | 8 | //MONTH 9 | char month_buffer[4]; 10 | PString my_month_string(month_buffer, sizeof(month_buffer)); 11 | int monthint = month(); 12 | 13 | switch (monthint) { 14 | case 1: 15 | my_month_string.println("Jan"); 16 | case 2: 17 | my_month_string.println("Feb"); 18 | case 3: 19 | my_month_string.println("Mar"); 20 | case 4: 21 | my_month_string.println("Apr"); 22 | case 5: 23 | my_month_string.println("May"); 24 | case 6: 25 | my_month_string.println("Jun"); 26 | case 7: 27 | my_month_string.println("Jul"); 28 | case 8: 29 | my_month_string.println("Aug"); 30 | case 9: 31 | my_month_string.println("Sep"); 32 | case 10: 33 | my_month_string.println("Oct"); 34 | case 11: 35 | my_month_string.println("Nov"); 36 | case 12: 37 | my_month_string.println("Dec"); 38 | } 39 | 40 | 41 | //DAY 42 | char day_int_buffer[3]; 43 | PString my_day_string(day_int_buffer, sizeof(day_int_buffer)); 44 | int dayint = day(); 45 | 46 | if (dayint < 10){ 47 | my_day_string.print("0"); 48 | my_day_string.println(dayint); 49 | } 50 | else { 51 | my_day_string.println(dayint); 52 | } 53 | 54 | //YEAR 55 | char year_int_buffer[5]; 56 | PString my_year_string(year_int_buffer, sizeof(year_int_buffer)); 57 | int yearint = year(); 58 | my_year_string.println(yearint); 59 | 60 | //HOUR 61 | char hour_int_buffer[3]; 62 | PString my_hour_string(hour_int_buffer, sizeof(hour_int_buffer)); 63 | int hourint = hour(); 64 | if (hourint > 12) { 65 | hourint = hourint - 12; 66 | } 67 | 68 | if (hourint < 10) { 69 | my_hour_string.print("0"); 70 | my_hour_string.println(hourint); 71 | } 72 | else { 73 | my_hour_string.println(hourint); 74 | } 75 | 76 | //MINUTE 77 | char minute_int_buffer[3]; 78 | PString my_minute_string(minute_int_buffer, sizeof(minute_int_buffer)); 79 | int minuteint = minute(); 80 | 81 | if (minuteint < 10){ 82 | my_minute_string.print("0"); 83 | my_minute_string.println(minuteint); 84 | } 85 | else { 86 | my_minute_string.println(minuteint); 87 | } 88 | 89 | if (last_minute != minute()) { //CODE THAT IS EXECUTED WHEN THE VALUE minute() CHANGES 90 | EEPROM.write(0,hour()); 91 | EEPROM.write(1,minute()); 92 | EEPROM.write(2,second()); 93 | EEPROM.write(3,day()); 94 | EEPROM.write(4,month()); 95 | EEPROM.write(5,year()); 96 | } 97 | 98 | last_minute = minute(); 99 | 100 | //SECOND 101 | char second_int_buffer[3]; 102 | PString my_second_string(second_int_buffer, sizeof(second_int_buffer)); 103 | int secondint = second(); 104 | 105 | 106 | if (secondint < 10){ 107 | my_second_string.print("0"); 108 | my_second_string.println(secondint); 109 | } 110 | else { 111 | my_second_string.println(secondint); 112 | } 113 | 114 | // AM/PM 115 | char am_pm_buffer[3]; 116 | PString my_am_pm_string(am_pm_buffer, sizeof(am_pm_buffer)); 117 | 118 | if (isAM() ==true){ 119 | my_am_pm_string.println("AM"); 120 | } 121 | else if (isAM()==false) { 122 | my_am_pm_string.println("PM"); 123 | } 124 | //COMBINED LONG FORMAT DATE 125 | // updates char longdate[22]; 126 | PString my_longdate_string(longdate, sizeof(longdate)); 127 | my_longdate_string.print(month_buffer); 128 | my_longdate_string.print(" "); 129 | my_longdate_string.print(day_int_buffer); 130 | my_longdate_string.print(", "); 131 | my_longdate_string.print(year_int_buffer); 132 | my_longdate_string.print(" "); 133 | my_longdate_string.print(hour_int_buffer); 134 | my_longdate_string.print(":"); 135 | my_longdate_string.print(minute_int_buffer); 136 | my_longdate_string.print(":"); 137 | my_longdate_string.print(second_int_buffer); 138 | my_longdate_string.print(" "); 139 | my_longdate_string.println(am_pm_buffer); 140 | } 141 | -------------------------------------------------------------------------------- /yieldbuddy_arduino/EEPROM_functions.ino: -------------------------------------------------------------------------------- 1 | /* 2 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3 | !!EEPROM READ/WRITE FUNCTIONS!!EEPROM READ/WRITE FUNCTIONS!!EEPROM READ/WRITE FUNCTIONS!!EEPROM READ/WRITE FUNCTIONS!!EEPROM READ/WRITE FUNCTIONS!!EEPROM READ/WRITE FUNCTIONS!!EEPROM READ/WRITE FUNCTIONS!!EEPROM READ/WRITE FUNCTIONS!!EEPROM READ/WRITE FUNCTIONS!! 4 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 5 | */ 6 | 7 | int eepromReadInt(int address){ 8 | int value = 0x0000; 9 | value = value | (EEPROM.read(address) << 8); 10 | value = value | EEPROM.read(address+1); 11 | return value; 12 | } 13 | 14 | void eepromWriteInt(int address, int value){ 15 | EEPROM.write(address, (value >> 8) & 0xFF ); 16 | EEPROM.write(address+1, value & 0xFF); 17 | } 18 | 19 | float eepromReadFloat(int address){ 20 | union u_tag { 21 | byte b[4]; 22 | float fval; 23 | } 24 | u; 25 | u.b[0] = EEPROM.read(address); 26 | u.b[1] = EEPROM.read(address+1); 27 | u.b[2] = EEPROM.read(address+2); 28 | u.b[3] = EEPROM.read(address+3); 29 | return u.fval; 30 | } 31 | 32 | void eepromWriteFloat(int address, float value){ 33 | union u_tag { 34 | byte b[4]; 35 | float fval; 36 | } 37 | u; 38 | u.fval=value; 39 | 40 | EEPROM.write(address , u.b[0]); 41 | EEPROM.write(address+1, u.b[1]); 42 | EEPROM.write(address+2, u.b[2]); 43 | EEPROM.write(address+3, u.b[3]); 44 | } 45 | 46 | -------------------------------------------------------------------------------- /yieldbuddy_arduino/Relay_functions.ino: -------------------------------------------------------------------------------- 1 | /* 2 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3 | /!!turnRelay!!turnRelay!!turnRelay!!turnRelay!!turnRelay!!turnRelay!!turnRelay!!turnRelay!!turnRelay!!turnRelay!!turnRelay!!turnRelay!!turnRelay!!turnRelay!!turnRelay!!turnRelay!!turnRelay!!turnRelay!!turnRelay!!turnRelay!! 4 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 5 | */ 6 | void turnRelay(int Relay_num, int TurnOnOff){ 7 | int Relay_Pin[6] = { 8 | Relay1_Pin, Relay2_Pin, Relay3_Pin, Relay4_Pin, Relay5_Pin, Relay6_Pin }; 9 | 10 | if (Relay_num < 6) { 11 | //Relay Board works opposite (Low/High) (Relays 1 - 5) 12 | if (TurnOnOff == 1) { 13 | digitalWrite(Relay_Pin[Relay_num - 1], LOW); 14 | } 15 | 16 | if(TurnOnOff == 0) { 17 | digitalWrite(Relay_Pin[Relay_num - 1], HIGH); 18 | } 19 | } 20 | else if (Relay_num == 6) { 21 | //SSR relay works as expected (High/Low) (Relay 6) 22 | if (TurnOnOff == 1) { 23 | digitalWrite(Relay_Pin[Relay_num - 1], HIGH); 24 | } 25 | 26 | if(TurnOnOff == 0) { 27 | digitalWrite(Relay_Pin[Relay_num - 1], LOW); 28 | } 29 | } 30 | sendRelayMessages(); // (through serial) 31 | } 32 | 33 | void FillPumpTimesArrays(int tmp_Pump_start_hour, int tmp_Pump_start_min, int tmp_Pump_every_hours, int tmp_Pump_every_mins, int tmp_Pump_for, int tmp_Pump_times) { 34 | tmp_Pump_hour_array[0] = tmp_Pump_start_hour; 35 | tmp_Pump_min_array[0] = tmp_Pump_start_min; 36 | tmp_Pump_isAM_array[0] = tmp_Pump_start_isAM; 37 | 38 | if (tmp_Pump_start_hour > 12) { 39 | tmp_Pump_isAM_array[0] = false; 40 | } 41 | 42 | 43 | int i = 0; 44 | for(i = 0; i < tmp_Pump_times; i++){ 45 | 46 | tmp_Pump_hour_array[i] = tmp_Pump_start_hour + ((i) * tmp_Pump_every_hours); 47 | tmp_Pump_min_array[i] = tmp_Pump_start_min + ((i) * tmp_Pump_every_mins); 48 | 49 | 50 | while (tmp_Pump_min_array[i] > 59) { 51 | tmp_Pump_min_array[i] = tmp_Pump_min_array[i] - 60; 52 | tmp_Pump_hour_array[i]++; 53 | } 54 | 55 | int AMPM_int = tmp_Pump_hour_array[i] / 12; 56 | 57 | while (tmp_Pump_hour_array[i] > 12) { 58 | tmp_Pump_hour_array[i] = tmp_Pump_hour_array[i] - 12; 59 | } 60 | 61 | Serial1.println(); 62 | Serial1.print("tmp_Pump_start_isAM:"); 63 | Serial1.print(tmp_Pump_start_isAM); 64 | Serial1.println(); 65 | Serial1.print(tmp_Pump_hour_array[i]); 66 | Serial1.print(") "); 67 | Serial1.print(AMPM_int); 68 | Serial1.println(); 69 | 70 | boolean case_zero = false; 71 | switch (AMPM_int) { 72 | case 0: 73 | case_zero = true; 74 | if (tmp_Pump_start_isAM == true) { 75 | tmp_Pump_isAM_array[i] = true; 76 | } 77 | else { 78 | tmp_Pump_isAM_array[i] = false; 79 | } 80 | break; 81 | case 1: 82 | if (case_zero == true){ 83 | if (tmp_Pump_start_isAM == true) { 84 | tmp_Pump_isAM_array[i] = false; 85 | } 86 | else { 87 | tmp_Pump_isAM_array[i] = true; 88 | } 89 | } 90 | else { 91 | if (tmp_Pump_start_isAM == true) { 92 | tmp_Pump_isAM_array[i] = false; 93 | } 94 | else { 95 | tmp_Pump_isAM_array[i] = true; 96 | } 97 | } 98 | break; 99 | case 2: 100 | if (case_zero == true){ 101 | if (tmp_Pump_start_isAM == true) { 102 | tmp_Pump_isAM_array[i] = false; 103 | } 104 | else { 105 | tmp_Pump_isAM_array[i] = true; 106 | } 107 | } 108 | else { 109 | if (tmp_Pump_start_isAM == true) { 110 | tmp_Pump_isAM_array[i] = true; 111 | } 112 | else { 113 | tmp_Pump_isAM_array[i] = false; 114 | } 115 | } 116 | break; 117 | case 3: 118 | if (case_zero == true){ 119 | if (tmp_Pump_start_isAM == true) { 120 | tmp_Pump_isAM_array[i] = true; 121 | } 122 | else { 123 | tmp_Pump_isAM_array[i] = false; 124 | } 125 | } 126 | else { 127 | if (tmp_Pump_start_isAM == true) { 128 | tmp_Pump_isAM_array[i] = false; 129 | } 130 | else { 131 | tmp_Pump_isAM_array[i] = true; 132 | } 133 | } 134 | break; 135 | case 4: 136 | if (case_zero == true){ 137 | if (tmp_Pump_start_isAM == true) { 138 | tmp_Pump_isAM_array[i] = false; 139 | } 140 | else { 141 | tmp_Pump_isAM_array[i] = true; 142 | } 143 | } 144 | else { 145 | if (tmp_Pump_start_isAM == true) { 146 | tmp_Pump_isAM_array[i] = true; 147 | } 148 | else { 149 | tmp_Pump_isAM_array[i] = false; 150 | } 151 | } 152 | break; 153 | } 154 | } 155 | } 156 | 157 | -------------------------------------------------------------------------------- /yieldbuddy_arduino/RestoreDefaults_functions.ino: -------------------------------------------------------------------------------- 1 | /* 2 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3 | /!!RESTORE DEFAULTS!!RESTORE DEFAULTS!!RESTORE DEFAULTS!!RESTORE DEFAULTS!!RESTORE DEFAULTS!!RESTORE DEFAULTS!!RESTORE DEFAULTS!!RESTORE DEFAULTS!!RESTORE DEFAULTS!!RESTORE DEFAULTS!!RESTORE DEFAULTS!!RESTORE DEFAULTS!!RESTORE DEFAULTS!!RESTORE DEFAULTS!! 4 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 5 | */ 6 | void RestoreDefaults() { 7 | 8 | //Temporary placeholders for Time Settings Screen 9 | tmp_month = 1; 10 | tmp_day = 1; 11 | tmp_year = 2012; 12 | tmp_hour = 0; 13 | tmp_minute = 0; 14 | tmp_second = 0; 15 | 16 | //Note: Committed Time Settings are stored as their associated month(), day(), year(), etc... as per 17 | 18 | tmp_Light_ON_hour = 0; 19 | tmp_Light_ON_min = 0; 20 | tmp_Light_OFF_hour = 18; 21 | tmp_Light_OFF_min = 18; 22 | 23 | //Committed Light Settings 24 | Light_ON_hour = 0; 25 | Light_ON_min = 0; 26 | Light_OFF_hour = 18; 27 | Light_OFF_min = 0; 28 | 29 | //Temporary placeholders for Pump Schedule Screen 30 | tmp_Pump_start_hour = 7; 31 | tmp_Pump_start_min = 15; 32 | tmp_Pump_start_isAM = true; 33 | tmp_Pump_every_hours = 2; 34 | tmp_Pump_every_mins = 30; 35 | tmp_Pump_for = 15; //In Minutes 36 | tmp_Pump_times = 1; //Number of times per day 37 | 38 | //Committed Pump Schedule Settings 39 | Pump_start_hour = 7; 40 | Pump_start_min = 15; 41 | Pump_start_isAM = true; 42 | Pump_every_hours = 2; 43 | Pump_every_mins = 30; 44 | Pump_for = 15; //In Minutes 45 | Pump_times = 1; //Number of times per day 46 | 47 | //SENSOR VARIABLES 48 | 49 | //Values the arduino sees 50 | pH1RawValue = 0; 51 | pH2RawValue = 0; 52 | TempRawValue = 0; 53 | RHRawValue = 0; 54 | TDS1RawValue = 0; 55 | TDS2RawValue = 0; 56 | CO2RawValue = 0; 57 | LightRawValue = 0; 58 | 59 | //Values the humans see 60 | pH1Value = 0; 61 | pH2Value = 0; 62 | TempValue = 0; 63 | RHValue = 0; 64 | TDS1Value = 0; 65 | TDS2Value = 0; 66 | CO2Value = 0; 67 | LightValue = 0; 68 | 69 | //Status Indicator Values 70 | pH1_Status = "OK"; 71 | pH1Value_Low = 5.60; 72 | pH1Value_High = 6.10; 73 | 74 | pH2_Status = "OK"; 75 | pH2Value_Low = 5.60; 76 | pH2Value_High = 6.10; 77 | 78 | Temp_Status = "OK"; 79 | TempValue_Low = 21.00; 80 | TempValue_High = 29.00; 81 | 82 | RH_Status = "OK"; 83 | RHValue_Low = 30.00; 84 | RHValue_High = 80.00; 85 | 86 | TDS1_Status = "OK"; 87 | TDS1Value_Low = 500.0; 88 | TDS1Value_High = 800.0; 89 | 90 | //TDS2 91 | TDS2_Status = "OK"; 92 | TDS2Value_Low = 500.0; 93 | TDS2Value_High = 800.0; 94 | //Accessory ON/OFF Values 95 | NutePump2_ON = 500.0; 96 | NutePump2_OFF = 800.0; 97 | MixPump2_Enabled = false; 98 | 99 | CO2_Status = "OK"; 100 | CO2Value_Low = 60.00; 101 | CO2Value_High= 75.00; 102 | 103 | Light_Status = "OK"; 104 | LightValue_Low = 20.00; 105 | LightValue_High = 95.00; 106 | 107 | //Accessory ON/OFF Values 108 | Heater_ON = 21.00; 109 | Heater_OFF = 25.00; 110 | AC_ON = 29.00; 111 | AC_OFF = 25.00; 112 | Humidifier_ON = 40.00; 113 | Humidifier_OFF = 60.00; 114 | Dehumidifier_ON = 80.00; 115 | Dehumidifier_OFF = 60.00; 116 | NutePump1_ON = 500.0; 117 | NutePump1_OFF = 800.0; 118 | MixPump1_Enabled = false; 119 | CO2_ON = 40.00; 120 | CO2_OFF = 60.00 ; 121 | CO2_Enabled = false; 122 | 123 | 124 | //Turn all relays off and set to manual mode by default 125 | //Relay_States 126 | 127 | turnRelay(1, 0); 128 | turnRelay(2, 0); 129 | turnRelay(3, 0); 130 | turnRelay(4, 0); 131 | turnRelay(5, 0); 132 | turnRelay(6, 0); 133 | Relay1_State = 0; 134 | Relay2_State = 0; 135 | Relay3_State = 0; 136 | Relay4_State = 0; 137 | Relay5_State = 0; 138 | Relay6_State = 0; 139 | EEPROM.write(6, 0); 140 | EEPROM.write(7, 0); 141 | EEPROM.write(8, 0); 142 | EEPROM.write(9, 0); 143 | EEPROM.write(10, 0); 144 | EEPROM.write(11, 0); 145 | 146 | 147 | Relay1_isAuto = 0; //EEPROM.read(211); //Water Pump 1 148 | Relay2_isAuto = 0; //EEPROM.read(212); //Water Pump 2 149 | Relay3_isAuto = 0; //EEPROM.read(213); //Free 150 | Relay4_isAuto = 0; //EEPROM.read(214); //Free 151 | Relay5_isAuto = 0; //EEPROM.read(215); //Free 152 | Relay6_isAuto = 0; //EEPROM.read(216); //Light/Ballast 153 | 154 | //Relay isAuto 155 | EEPROM.write(211, Relay1_isAuto); 156 | EEPROM.write(212, Relay2_isAuto); 157 | EEPROM.write(213, Relay3_isAuto); 158 | EEPROM.write(214, Relay4_isAuto); 159 | EEPROM.write(215, Relay5_isAuto); 160 | EEPROM.write(216, Relay6_isAuto); 161 | 162 | 163 | //pH 164 | eepromWriteFloat(78,pH1Value_Low); 165 | eepromWriteFloat(82,pH1Value_High); 166 | eepromWriteFloat(180,pH2Value_Low); 167 | eepromWriteFloat(184,pH2Value_High); 168 | 169 | //Temp 170 | eepromWriteFloat(86,TempValue_Low); 171 | eepromWriteFloat(90,TempValue_High); 172 | eepromWriteFloat(94,Heater_ON); 173 | eepromWriteFloat(98,Heater_OFF); 174 | eepromWriteFloat(102,AC_ON); 175 | eepromWriteFloat(106,AC_OFF); 176 | 177 | //RH 178 | eepromWriteFloat(110,RHValue_Low); 179 | eepromWriteFloat(114,RHValue_High); 180 | eepromWriteFloat(118,Humidifier_ON); 181 | eepromWriteFloat(122,Humidifier_OFF); 182 | eepromWriteFloat(126,Dehumidifier_ON); 183 | eepromWriteFloat(130,Dehumidifier_OFF); 184 | 185 | //TDS1 186 | eepromWriteFloat(134,TDS1Value_Low); 187 | eepromWriteFloat(139,TDS1Value_High); 188 | eepromWriteFloat(144,NutePump1_ON); 189 | eepromWriteFloat(149,NutePump1_OFF); 190 | if (MixPump1_Enabled == true) { 191 | EEPROM.write(154,1); 192 | } 193 | else { 194 | EEPROM.write(154,0); 195 | } 196 | 197 | //TDS2 198 | eepromWriteFloat(188,TDS2Value_Low); 199 | eepromWriteFloat(193,TDS2Value_High); 200 | eepromWriteFloat(198,NutePump2_ON); 201 | eepromWriteFloat(203,NutePump2_OFF); 202 | if (MixPump2_Enabled == true) { 203 | EEPROM.write(208,1); 204 | } 205 | else { 206 | EEPROM.write(208,0); 207 | } 208 | 209 | //CO2 210 | eepromWriteFloat(155,CO2Value_Low); 211 | eepromWriteFloat(159,CO2Value_High); 212 | eepromWriteFloat(163,CO2_ON); 213 | eepromWriteFloat(167,CO2_OFF); 214 | if (CO2_Enabled == true) { 215 | EEPROM.write(171,1); 216 | } 217 | else { 218 | EEPROM.write(171,0); 219 | } 220 | //Light 221 | eepromWriteFloat(172,LightValue_Low); 222 | eepromWriteFloat(176,LightValue_High); 223 | 224 | EEPROM.write(76, Light_ON_hour); 225 | EEPROM.write(209, Light_ON_min); 226 | EEPROM.write(77, Light_OFF_hour); 227 | EEPROM.write(210, Light_OFF_min); 228 | 229 | //Pump 230 | EEPROM.write(21,Pump_start_hour); 231 | EEPROM.write(22,Pump_start_min); 232 | EEPROM.write(23,Pump_every_hours); 233 | EEPROM.write(24,Pump_every_mins); 234 | EEPROM.write(25,Pump_for); 235 | EEPROM.write(26,Pump_times); 236 | 237 | int i = 0; 238 | for(i = 0; i < tmp_Pump_times; i++){ 239 | Pump_hour_array[i]= tmp_Pump_hour_array[i]; 240 | Pump_min_array[i] = tmp_Pump_min_array[i]; 241 | Pump_isAM_array[i] = tmp_Pump_isAM_array[i]; 242 | EEPROM.write((i+27),Pump_hour_array[i]); 243 | EEPROM.write((i+43),Pump_min_array[i]); 244 | EEPROM.write((i+59),Pump_isAM_array[i]); 245 | } 246 | 247 | //Save Time Settings 248 | EEPROM.write(0,tmp_hour); 249 | EEPROM.write(1,tmp_minute); 250 | EEPROM.write(2,tmp_second); 251 | EEPROM.write(3,tmp_day); 252 | EEPROM.write(4,tmp_month); 253 | EEPROM.write(5,tmp_year); 254 | setTime(tmp_hour,tmp_minute,tmp_second,tmp_day,tmp_month,tmp_year); 255 | setSyncProvider(RTC.get); 256 | 257 | } 258 | 259 | -------------------------------------------------------------------------------- /yieldbuddy_arduino/Serial_functions.ino: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3 | /!!SEND SERIAL MESSAGE!!!!SEND SERIAL MESSAGE!!SEND SERIAL MESSAGE!!SEND SERIAL MESSAGE!!SEND SERIAL MESSAGE!!SEND SERIAL MESSAGE!!SEND SERIAL MESSAGE!! 4 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 5 | */ 6 | void sendserialmessages(){ 7 | 8 | //The purpose of 'serialcounter' is so that serial messages are not sent as one big chunk of data every 'loop()', instead they are split up 9 | //into 3 chunks, and those chunks are then sent every second loop (over a period of a total of 5 'loop()s') 10 | //However, Sensors and Relay values are sent every 1st and 4th messages. 11 | 12 | if (serialcounter == 1 || serialcounter == 4 || serialcounter == 7){ 13 | //SEND TIMESTAMP 14 | updatelongdate(); 15 | Serial1.print("Time,"); 16 | Serial1.print(longdate); 17 | Serial1.print(","); 18 | Serial1.print(month()); 19 | Serial1.print(","); 20 | Serial1.print(day()); 21 | Serial1.print(","); 22 | Serial1.print(year()); 23 | Serial1.print(","); 24 | Serial1.print(hour()); 25 | Serial1.print(","); 26 | Serial1.print(minute()); 27 | Serial1.print(","); 28 | Serial1.println(second()); 29 | //SENSOR VALUES 30 | Serial1.print("Sensors,"); 31 | Serial1.print(pH1Value); 32 | Serial1.print(","); 33 | Serial1.print(pH2Value); 34 | Serial1.print(","); 35 | Serial1.print(TempValue); 36 | Serial1.print(","); 37 | Serial1.print(RHValue); 38 | Serial1.print(","); 39 | Serial1.print(TDS1Value); 40 | Serial1.print(","); 41 | Serial1.print(TDS2Value); 42 | Serial1.print(","); 43 | Serial1.print(CO2Value); 44 | Serial1.print(","); 45 | Serial1.println(LightValue); 46 | 47 | sendRelayMessages(); //<<---- Relays and Relay_isAutoMessages 48 | 49 | } 50 | if (serialcounter == 3) { 51 | 52 | 53 | //LIGHTS 54 | Serial1.print("Light_Schedule,"); 55 | Serial1.print(Light_ON_hour); 56 | Serial1.print(","); 57 | Serial1.print(Light_ON_min); 58 | Serial1.print(","); 59 | Serial1.print(Light_OFF_hour); 60 | Serial1.print(","); 61 | Serial1.println(Light_OFF_min); 62 | //WATERING 63 | Serial1.print("Watering_Schedule,"); 64 | Serial1.print(Pump_start_hour); 65 | Serial1.print(","); 66 | Serial1.print(Pump_start_min); 67 | Serial1.print(","); 68 | if (Pump_start_isAM == true) { 69 | Serial1.print("1,"); 70 | } 71 | else { 72 | Serial1.print("0,"); 73 | } 74 | Serial1.print(Pump_every_hours); 75 | Serial1.print(","); 76 | Serial1.print(Pump_every_mins); 77 | Serial1.print(","); 78 | Serial1.print(Pump_for); 79 | Serial1.print(","); 80 | Serial1.println(Pump_times); 81 | } 82 | 83 | if (serialcounter == 4) { 84 | //SETPOINTS 85 | //pH1 86 | Serial1.print("SetPoint_pH1,"); 87 | Serial1.print(pH1Value_Low); 88 | Serial1.print(","); 89 | Serial1.print(pH1Value_High); 90 | Serial1.print(","); 91 | Serial1.println(pH1_Status); 92 | } 93 | if (serialcounter == 5) { 94 | 95 | //pH2 96 | Serial1.print("SetPoint_pH2,"); 97 | Serial1.print(pH2Value_Low); 98 | Serial1.print(","); 99 | Serial1.print(pH2Value_High); 100 | Serial1.print(","); 101 | Serial1.println(pH1_Status); 102 | } 103 | if (serialcounter == 6) { 104 | //Temp 105 | Serial1.print("SetPoint_Temp,"); 106 | Serial1.print(TempValue_Low); 107 | Serial1.print(","); 108 | Serial1.print(TempValue_High); 109 | Serial1.print(","); 110 | Serial1.print(Heater_ON); 111 | Serial1.print(","); 112 | Serial1.print(Heater_OFF); 113 | Serial1.print(","); 114 | Serial1.print(AC_ON); 115 | Serial1.print(","); 116 | Serial1.print(AC_OFF); 117 | Serial1.print(","); 118 | Serial1.println(Temp_Status); 119 | } 120 | if (serialcounter == 7) { 121 | //RH 122 | Serial1.print("SetPoint_RH,"); 123 | Serial1.print(RHValue_Low); 124 | Serial1.print(","); 125 | Serial1.print(RHValue_High); 126 | Serial1.print(","); 127 | Serial1.print(Humidifier_ON); 128 | Serial1.print(","); 129 | Serial1.print(Humidifier_OFF); 130 | Serial1.print(","); 131 | Serial1.print(Dehumidifier_ON); 132 | Serial1.print(","); 133 | Serial1.print(Dehumidifier_OFF); 134 | Serial1.print(","); 135 | Serial1.println(RH_Status); 136 | } 137 | if (serialcounter == 8) { 138 | //TDS1 139 | Serial1.print("SetPoint_TDS1,"); 140 | Serial1.print(TDS1Value_Low); 141 | Serial1.print(","); 142 | Serial1.print(TDS1Value_High); 143 | Serial1.print(","); 144 | Serial1.print(NutePump1_ON); 145 | Serial1.print(","); 146 | Serial1.print(NutePump1_OFF); 147 | Serial1.print(","); 148 | Serial1.print(MixPump1_Enabled); 149 | Serial1.print(","); 150 | Serial1.println(TDS1_Status); 151 | } 152 | if (serialcounter == 9) { 153 | //TDS2 154 | Serial1.print("SetPoint_TDS2,"); 155 | Serial1.print(TDS2Value_Low); 156 | Serial1.print(","); 157 | Serial1.print(TDS2Value_High); 158 | Serial1.print(","); 159 | Serial1.print(NutePump2_ON); 160 | Serial1.print(","); 161 | Serial1.print(NutePump2_OFF); 162 | Serial1.print(","); 163 | Serial1.print(MixPump2_Enabled); 164 | Serial1.print(","); 165 | Serial1.println(TDS2_Status); 166 | } 167 | if (serialcounter == 10) { 168 | //CO2 169 | Serial1.print("SetPoint_CO2,"); 170 | Serial1.print(CO2Value_Low); 171 | Serial1.print(","); 172 | Serial1.print(CO2Value_High); 173 | Serial1.print(","); 174 | Serial1.print(CO2_ON); 175 | Serial1.print(","); 176 | Serial1.print(CO2_OFF); 177 | Serial1.print(","); 178 | Serial1.print(CO2_Enabled); 179 | Serial1.print(","); 180 | Serial1.println(CO2_Status); 181 | } 182 | if (serialcounter == 11) { 183 | //Light 184 | Serial1.print("SetPoint_Light,"); 185 | Serial1.print(LightValue_Low); 186 | Serial1.print(","); 187 | Serial1.print(LightValue_High); 188 | Serial1.print(","); 189 | Serial1.println(Light_Status); 190 | 191 | serialcounter = 0; 192 | } 193 | serialcounter++; 194 | 195 | } 196 | 197 | /* 198 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 199 | /!!serialEvent!!serialEvent!!serialEvent!!serialEvent!!serialEvent!!serialEvent!!serialEvent!!serialEvent!!serialEvent!!serialEvent!!serialEvent!!serialEvent!!serialEvent!!serialEvent!!serialEvent!!serialEvent!!serialEvent!! 200 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 201 | */ 202 | void serialEvent() { 203 | while (Serial1.available() > 0) { 204 | // get the new byte: 205 | char inChar = (char)Serial1.read(); 206 | 207 | // if the incoming character is a newline, set a flag 208 | // so the main loop can do something about it: 209 | if (inChar == '\n') { 210 | stringComplete = true; 211 | Serial1.println("Recieved String! '" + Serial_inString + "'"); 212 | 213 | if (Serial_inString == "Relay1 on" && Relay1_isAuto == 0) { 214 | Relay1_State = 1; 215 | EEPROM.write(6,1); 216 | turnRelay(1, 1); 217 | sendRelayMessages(); 218 | } 219 | else if (Serial_inString == "Relay1 off" && Relay1_isAuto == 0) { 220 | Relay1_State = 0; 221 | EEPROM.write(6,0); 222 | turnRelay(1, 0); 223 | sendRelayMessages(); 224 | } 225 | 226 | if (Serial_inString == "Relay2 on" && Relay2_isAuto == 0) { 227 | Relay2_State = 1; 228 | EEPROM.write(7,1); 229 | turnRelay(2, 1); 230 | sendRelayMessages(); 231 | } 232 | else if (Serial_inString == "Relay2 off" && Relay2_isAuto == 0) { 233 | Relay2_State = 0; 234 | EEPROM.write(7,0); 235 | turnRelay(2, 0); 236 | sendRelayMessages(); 237 | } 238 | 239 | if (Serial_inString == "Relay3 on" && Relay3_isAuto == 0) { 240 | Relay3_State = 1; 241 | EEPROM.write(8,1); 242 | turnRelay(3, 1); 243 | sendRelayMessages(); 244 | } 245 | else if (Serial_inString == "Relay3 off" && Relay3_isAuto == 0) { 246 | Relay3_State = 0; 247 | EEPROM.write(8,0); 248 | turnRelay(3, 0); 249 | sendRelayMessages(); 250 | } 251 | 252 | if (Serial_inString == "Relay4 on" && Relay4_isAuto == 0) { 253 | Relay4_State = 1; 254 | EEPROM.write(9,1); 255 | turnRelay(4, 1); 256 | sendRelayMessages(); 257 | } 258 | else if (Serial_inString == "Relay4 off" && Relay4_isAuto == 0) { 259 | Relay4_State = 0; 260 | EEPROM.write(9,0); 261 | turnRelay(4, 0); 262 | sendRelayMessages(); 263 | } 264 | 265 | if (Serial_inString == "Relay5 on" && Relay5_isAuto == 0) { 266 | Relay5_State = 1; 267 | EEPROM.write(10,1); 268 | turnRelay(5, 1); 269 | sendRelayMessages(); 270 | } 271 | else if (Serial_inString == "Relay5 off" && Relay5_isAuto == 0) { 272 | Relay5_State = 0; 273 | EEPROM.write(10,0); 274 | turnRelay(5, 0); 275 | sendRelayMessages(); 276 | } 277 | 278 | if (Serial_inString == "Relay6 on" && Relay6_isAuto == 0) { 279 | Relay6_State = 1; 280 | EEPROM.write(11,1); 281 | turnRelay(6, 1); 282 | sendRelayMessages(); 283 | 284 | } 285 | else if (Serial_inString == "Relay6 off" && Relay6_isAuto == 0) { 286 | Relay6_State = 0; 287 | EEPROM.write(11,0); 288 | turnRelay(6, 0); 289 | sendRelayMessages(); 290 | } 291 | 292 | if (Serial_inString == "Relay1 isAuto 1") { 293 | Relay1_isAuto = 1; 294 | EEPROM.write(211,1); 295 | sendRelayMessages(); 296 | } 297 | else if (Serial_inString == "Relay1 isAuto 0") { 298 | Relay1_isAuto = 0; 299 | EEPROM.write(211,0); 300 | sendRelayMessages(); 301 | } 302 | 303 | if (Serial_inString == "Relay2 isAuto 1") { 304 | Relay2_isAuto = 1; 305 | EEPROM.write(212,1); 306 | sendRelayMessages(); 307 | } 308 | else if (Serial_inString == "Relay2 isAuto 0") { 309 | Relay2_isAuto = 0; 310 | EEPROM.write(212,0); 311 | sendRelayMessages(); 312 | } 313 | 314 | if (Serial_inString == "Relay3 isAuto 1") { 315 | Relay3_isAuto = 1; 316 | EEPROM.write(213,1); 317 | sendRelayMessages(); 318 | } 319 | else if (Serial_inString == "Relay3 isAuto 0") { 320 | Relay3_isAuto = 0; 321 | EEPROM.write(213,0); 322 | sendRelayMessages(); 323 | } 324 | 325 | if (Serial_inString == "Relay4 isAuto 1") { 326 | Relay4_isAuto = 1; 327 | EEPROM.write(214,1); 328 | sendRelayMessages(); 329 | } 330 | else if (Serial_inString == "Relay4 isAuto 0") { 331 | Relay4_isAuto = 0; 332 | EEPROM.write(214,0); 333 | sendRelayMessages(); 334 | } 335 | 336 | if (Serial_inString == "Relay5 isAuto 1") { 337 | Relay5_isAuto = 1; 338 | EEPROM.write(215,1); 339 | sendRelayMessages(); 340 | } 341 | else if (Serial_inString == "Relay5 isAuto 0") { 342 | Relay5_isAuto = 0; 343 | EEPROM.write(215,0); 344 | sendRelayMessages(); 345 | } 346 | 347 | if (Serial_inString == "Relay6 isAuto 1") { 348 | Relay6_isAuto = 1; 349 | EEPROM.write(216,1); 350 | sendRelayMessages(); 351 | } 352 | else if (Serial_inString == "Relay6 isAuto 0") { 353 | Relay6_isAuto = 0; 354 | EEPROM.write(216,0); 355 | sendRelayMessages(); 356 | } 357 | 358 | 359 | 360 | if (Serial_inString == "restoredefaults") { 361 | RestoreDefaults(); 362 | } 363 | 364 | if(Serial_inString.indexOf("setdate") >=0) { 365 | // Serial1.println("YESSS"); 366 | char datechar[Serial_inString.length()+1]; 367 | Serial_inString.toCharArray(datechar, Serial_inString.length()+1); 368 | // Serial1.print("Char: "); 369 | // Serial1.println(datechar); 370 | int date[10]; 371 | // Serial1.println(Serial_inString); 372 | // Serial1.print("Size: "); 373 | // Serial1.println(Serial_inString.length()+1); 374 | int i; 375 | String datestring[7]; 376 | String tmpBuffer; 377 | int parsecount = 0; 378 | for (i=0;i<(Serial_inString.length()+1);i++){ 379 | if (datechar[i] == ',') { 380 | tmpBuffer.replace(",", ""); 381 | datestring[parsecount] = tmpBuffer; 382 | tmpBuffer = ""; 383 | parsecount++; 384 | } 385 | if (i == Serial_inString.length()){ 386 | tmpBuffer.replace(",", ""); 387 | datestring[parsecount] = tmpBuffer; 388 | } 389 | tmpBuffer += datechar[i]; 390 | } 391 | 392 | 393 | // Serial1.print("Split:"); 394 | // Serial1.println(Serial_inString); 395 | // 396 | // 397 | // Serial1.println("Month"); 398 | // Serial1.println(datestring[1]); 399 | // Serial1.println("Day"); 400 | // Serial1.println(datestring[2]); 401 | // Serial1.println("Year"); 402 | // Serial1.println(datestring[3]); 403 | // Serial1.println("Hour"); 404 | // Serial1.println(datestring[4]); 405 | // Serial1.println("Min"); 406 | // Serial1.println(datestring[5]); 407 | // Serial1.println("Sec"); 408 | // Serial1.println(datestring[6]); 409 | // 410 | int parsed_month = datestring[1].toInt(); 411 | int parsed_day = datestring[2].toInt(); 412 | int parsed_year = datestring[3].toInt(); 413 | int parsed_hour = datestring[4].toInt(); 414 | int parsed_minute = datestring[5].toInt(); 415 | int parsed_second = datestring[6].toInt(); 416 | 417 | EEPROM.write(0,parsed_hour); 418 | EEPROM.write(1,parsed_minute); 419 | EEPROM.write(2,parsed_second); 420 | EEPROM.write(3,parsed_day); 421 | EEPROM.write(4,parsed_month); 422 | EEPROM.write(5,parsed_year); 423 | setTime(parsed_hour,parsed_minute,parsed_second,parsed_day,parsed_month,parsed_year); 424 | RTC.set(now()); 425 | } 426 | 427 | if(Serial_inString.indexOf("setlightschedule") >=0) { 428 | // Serial1.println("setlightschedule"); 429 | char lightschedulechar[Serial_inString.length()+1]; 430 | Serial_inString.toCharArray(lightschedulechar, Serial_inString.length()+1); 431 | // Serial1.print("Char: "); 432 | // Serial1.println(lightschedulechar); 433 | int date[10]; 434 | // Serial1.println(Serial_inString); 435 | // Serial1.print("Size: "); 436 | // Serial1.println(Serial_inString.length()+1); 437 | int i; 438 | String lightschedulestring[6]; 439 | String tmpBuffer; 440 | int parsecount = 0; 441 | for (i=0;i<(Serial_inString.length()+1);i++){ 442 | if (lightschedulechar[i] == ',') { 443 | tmpBuffer.replace(",", ""); 444 | lightschedulestring[parsecount] = tmpBuffer; 445 | tmpBuffer = ""; 446 | parsecount++; 447 | } 448 | if (i == Serial_inString.length()){ 449 | tmpBuffer.replace(",", ""); 450 | lightschedulestring[parsecount] = tmpBuffer; 451 | } 452 | tmpBuffer += lightschedulechar[i]; 453 | } 454 | 455 | 456 | // Serial1.print("Split:"); 457 | // Serial1.println(Serial_inString); 458 | 459 | // Serial1.println("Light_ON_hour"); 460 | // Serial1.println(lightschedulestring[1]); 461 | // Serial1.println("Light_ON_min"); 462 | // Serial1.println(lightschedulestring[2]); 463 | // Serial1.println("Light_OFF_hour"); 464 | // Serial1.println(lightschedulestring[3]); 465 | // Serial1.println("Light_OFF_min"); 466 | // Serial1.println(lightschedulestring[4]); 467 | 468 | int parsed_Light_ON_hour = lightschedulestring[1].toInt(); 469 | int parsed_Light_ON_min = lightschedulestring[2].toInt(); 470 | int parsed_Light_OFF_hour = lightschedulestring[3].toInt(); 471 | int parsed_Light_OFF_min = lightschedulestring[4].toInt(); 472 | 473 | Light_ON_hour = parsed_Light_ON_hour; 474 | Light_ON_min = parsed_Light_ON_min; 475 | Light_OFF_hour = parsed_Light_OFF_hour; 476 | Light_OFF_min = parsed_Light_OFF_min; 477 | 478 | EEPROM.write(76, Light_ON_hour); 479 | EEPROM.write(77, Light_OFF_hour); 480 | EEPROM.write(209, Light_ON_min); 481 | EEPROM.write(210, Light_OFF_min); 482 | } 483 | 484 | 485 | if(Serial_inString.indexOf("setwateringschedule") >=0) { 486 | Serial1.println("setwaterschedule"); 487 | char waterschedulechar[Serial_inString.length()+1]; 488 | Serial_inString.toCharArray(waterschedulechar, Serial_inString.length()+1); 489 | Serial1.print("Char: "); 490 | Serial1.println(waterschedulechar); 491 | int date[10]; 492 | // Serial1.println(Serial_inString); 493 | // Serial1.print("Size: "); 494 | // Serial1.println(Serial_inString.length()+1); 495 | int i; 496 | String waterschedulestring[7]; 497 | String tmpBuffer; 498 | int parsecount = 0; 499 | for (i=0;i<(Serial_inString.length()+1);i++){ 500 | if (waterschedulechar[i] == ',') { 501 | tmpBuffer.replace(",", ""); 502 | waterschedulestring[parsecount] = tmpBuffer; 503 | tmpBuffer = ""; 504 | parsecount++; 505 | } 506 | if (i == Serial_inString.length()){ 507 | tmpBuffer.replace(",", ""); 508 | waterschedulestring[parsecount] = tmpBuffer; 509 | } 510 | tmpBuffer += waterschedulechar[i]; 511 | } 512 | 513 | 514 | // Serial1.print("Split:"); 515 | // Serial1.println(Serial_inString); 516 | 517 | // Serial1.println("Pump_start_hour"); 518 | // Serial1.println(waterschedulestring[1]); 519 | // Serial1.println("Pump_start_min"); 520 | // Serial1.println(waterschedulestring[2]); 521 | // Serial1.println("Pump_every_hours"); 522 | // Serial1.println(waterschedulestring[3]); 523 | // Serial1.println("Pump_every_mins"); 524 | // Serial1.println(waterschedulestring[4]); 525 | // Serial1.println("Pump_for"); 526 | // Serial1.println(waterschedulestring[5]); 527 | // Serial1.println("Pump_times"); 528 | // Serial1.println(waterschedulestring[6]); 529 | 530 | int parsed_Pump_start_hour = waterschedulestring[1].toInt(); 531 | int parsed_Pump_start_min = waterschedulestring[2].toInt(); 532 | int parsed_Pump_every_hours = waterschedulestring[3].toInt(); 533 | int parsed_Pump_every_mins = waterschedulestring[4].toInt(); 534 | int parsed_Pump_for = waterschedulestring[5].toInt(); 535 | int parsed_Pump_times = waterschedulestring[6].toInt(); 536 | 537 | Pump_start_hour = parsed_Pump_start_hour; 538 | Pump_start_min = parsed_Pump_start_min; 539 | Pump_every_hours = parsed_Pump_every_hours; 540 | Pump_every_mins = parsed_Pump_every_mins; 541 | Pump_for = parsed_Pump_for; 542 | Pump_times = parsed_Pump_times; 543 | 544 | EEPROM.write(21,Pump_start_hour); 545 | EEPROM.write(22,Pump_start_min); 546 | EEPROM.write(23,Pump_every_hours); 547 | EEPROM.write(24,Pump_every_mins); 548 | EEPROM.write(25,Pump_for); 549 | EEPROM.write(26,Pump_times); 550 | 551 | FillPumpTimesArrays(Pump_start_hour, Pump_start_min, Pump_every_hours, Pump_every_mins, Pump_for, Pump_times); 552 | 553 | i = 0; 554 | for(i = 0; i < Pump_times; i++){ 555 | Pump_hour_array[i]= tmp_Pump_hour_array[i]; 556 | Pump_min_array[i] = tmp_Pump_min_array[i]; 557 | Pump_isAM_array[i] = tmp_Pump_isAM_array[i]; 558 | EEPROM.write((i+27),Pump_hour_array[i]); 559 | EEPROM.write((i+43),Pump_min_array[i]); 560 | EEPROM.write((i+59),Pump_isAM_array[i]); 561 | } 562 | 563 | 564 | 565 | } 566 | 567 | if(Serial_inString.indexOf("setpH1") >=0) { 568 | char serialchar[Serial_inString.length()+1]; 569 | Serial_inString.toCharArray(serialchar, Serial_inString.length()+1); 570 | 571 | int i; 572 | String splitstring[3]; 573 | String tmpBuffer; 574 | int parsecount = 0; 575 | for (i=0;i<(Serial_inString.length()+1);i++){ 576 | if (serialchar[i] == ',') { 577 | tmpBuffer.replace(",", ""); 578 | splitstring[parsecount] = tmpBuffer; 579 | tmpBuffer = ""; 580 | parsecount++; 581 | } 582 | if (i == Serial_inString.length()){ 583 | tmpBuffer.replace(",", ""); 584 | splitstring[parsecount] = tmpBuffer; 585 | } 586 | tmpBuffer += serialchar[i]; 587 | } 588 | char char_pH1Value_Low[splitstring[1].length() + 1]; 589 | splitstring[1].toCharArray(char_pH1Value_Low, sizeof(char_pH1Value_Low)); 590 | float parsed_pH1Value_Low = atof(char_pH1Value_Low); 591 | 592 | char char_pH1Value_High[splitstring[2].length() + 1]; 593 | splitstring[2].toCharArray(char_pH1Value_High, sizeof(char_pH1Value_High)); 594 | float parsed_pH1Value_High = atof(char_pH1Value_High); 595 | 596 | pH1Value_Low = parsed_pH1Value_Low; 597 | pH1Value_High = parsed_pH1Value_High; 598 | 599 | eepromWriteFloat(78, parsed_pH1Value_Low); 600 | eepromWriteFloat(82, parsed_pH1Value_High); 601 | 602 | } 603 | 604 | if(Serial_inString.indexOf("setpH2") >=0) { 605 | char serialchar[Serial_inString.length()+1]; 606 | Serial_inString.toCharArray(serialchar, Serial_inString.length()+1); 607 | 608 | int i; 609 | String splitstring[3]; 610 | String tmpBuffer; 611 | int parsecount = 0; 612 | for (i=0;i<(Serial_inString.length()+1);i++){ 613 | if (serialchar[i] == ',') { 614 | tmpBuffer.replace(",", ""); 615 | splitstring[parsecount] = tmpBuffer; 616 | tmpBuffer = ""; 617 | parsecount++; 618 | } 619 | if (i == Serial_inString.length()){ 620 | tmpBuffer.replace(",", ""); 621 | splitstring[parsecount] = tmpBuffer; 622 | } 623 | tmpBuffer += serialchar[i]; 624 | } 625 | char char_pH2Value_Low[splitstring[1].length() + 1]; 626 | splitstring[1].toCharArray(char_pH2Value_Low, sizeof(char_pH2Value_Low)); 627 | float parsed_pH2Value_Low = atof(char_pH2Value_Low); 628 | 629 | char char_pH2Value_High[splitstring[2].length() + 1]; 630 | splitstring[2].toCharArray(char_pH2Value_High, sizeof(char_pH2Value_High)); 631 | float parsed_pH2Value_High = atof(char_pH2Value_High); 632 | 633 | pH2Value_Low = parsed_pH2Value_Low; 634 | pH2Value_High = parsed_pH2Value_High; 635 | 636 | eepromWriteFloat(180, parsed_pH2Value_Low); 637 | eepromWriteFloat(184, parsed_pH2Value_High); 638 | 639 | } 640 | 641 | if(Serial_inString.indexOf("setTemp") >=0) { 642 | char serialchar[Serial_inString.length()+1]; 643 | Serial_inString.toCharArray(serialchar, Serial_inString.length()+1); 644 | 645 | int i; 646 | String splitstring[7]; 647 | String tmpBuffer; 648 | int parsecount = 0; 649 | for (i=0;i<(Serial_inString.length()+1);i++){ 650 | if (serialchar[i] == ',') { 651 | tmpBuffer.replace(",", ""); 652 | splitstring[parsecount] = tmpBuffer; 653 | tmpBuffer = ""; 654 | parsecount++; 655 | } 656 | if (i == Serial_inString.length()){ 657 | tmpBuffer.replace(",", ""); 658 | splitstring[parsecount] = tmpBuffer; 659 | } 660 | tmpBuffer += serialchar[i]; 661 | } 662 | 663 | char char_TempValue_Low[splitstring[1].length() + 1]; 664 | splitstring[1].toCharArray(char_TempValue_Low, sizeof(char_TempValue_Low)); 665 | float parsed_TempValue_Low = atof(char_TempValue_Low); 666 | 667 | char char_TempValue_High[splitstring[2].length() + 1]; 668 | splitstring[2].toCharArray(char_TempValue_High, sizeof(char_TempValue_High)); 669 | float parsed_TempValue_High = atof(char_TempValue_High); 670 | 671 | char char_Heater_ON[splitstring[3].length() + 1]; 672 | splitstring[3].toCharArray(char_Heater_ON, sizeof(char_Heater_ON)); 673 | float parsed_Heater_ON = atof(char_Heater_ON); 674 | 675 | char char_Heater_OFF[splitstring[4].length() + 1]; 676 | splitstring[4].toCharArray(char_Heater_OFF, sizeof(char_Heater_OFF)); 677 | float parsed_Heater_OFF = atof(char_Heater_OFF); 678 | 679 | char char_AC_ON[splitstring[5].length() + 1]; 680 | splitstring[5].toCharArray(char_AC_ON, sizeof(char_AC_ON)); 681 | float parsed_AC_ON = atof(char_AC_ON); 682 | 683 | char char_AC_OFF[splitstring[6].length() + 1]; 684 | splitstring[6].toCharArray(char_AC_OFF, sizeof(char_AC_OFF)); 685 | float parsed_AC_OFF = atof(char_AC_OFF); 686 | 687 | TempValue_Low = parsed_TempValue_Low; 688 | TempValue_High = parsed_TempValue_High; 689 | Heater_ON = parsed_Heater_ON; 690 | Heater_OFF = parsed_Heater_OFF; 691 | AC_ON = parsed_AC_ON; 692 | AC_OFF = parsed_AC_OFF; 693 | 694 | eepromWriteFloat(86, parsed_TempValue_Low); 695 | eepromWriteFloat(90, parsed_TempValue_High); 696 | eepromWriteFloat(84, parsed_Heater_ON); 697 | eepromWriteFloat(98, parsed_Heater_OFF); 698 | eepromWriteFloat(102, parsed_AC_ON); 699 | eepromWriteFloat(106, parsed_AC_OFF); 700 | 701 | } 702 | 703 | if(Serial_inString.indexOf("setRH") >=0) { 704 | char serialchar[Serial_inString.length()+1]; 705 | Serial_inString.toCharArray(serialchar, Serial_inString.length()+1); 706 | 707 | int i; 708 | String splitstring[7]; 709 | String tmpBuffer; 710 | int parsecount = 0; 711 | for (i=0;i<(Serial_inString.length()+1);i++){ 712 | if (serialchar[i] == ',') { 713 | tmpBuffer.replace(",", ""); 714 | splitstring[parsecount] = tmpBuffer; 715 | tmpBuffer = ""; 716 | parsecount++; 717 | } 718 | if (i == Serial_inString.length()){ 719 | tmpBuffer.replace(",", ""); 720 | splitstring[parsecount] = tmpBuffer; 721 | } 722 | tmpBuffer += serialchar[i]; 723 | } 724 | 725 | char char_RHValue_Low[splitstring[1].length() + 1]; 726 | splitstring[1].toCharArray(char_RHValue_Low, sizeof(char_RHValue_Low)); 727 | float parsed_RHValue_Low = atof(char_RHValue_Low); 728 | 729 | char char_RHValue_High[splitstring[2].length() + 1]; 730 | splitstring[2].toCharArray(char_RHValue_High, sizeof(char_RHValue_High)); 731 | float parsed_RHValue_High = atof(char_RHValue_High); 732 | 733 | char char_Humidifier_ON[splitstring[3].length() + 1]; 734 | splitstring[3].toCharArray(char_Humidifier_ON, sizeof(char_Humidifier_ON)); 735 | float parsed_Humidifier_ON = atof(char_Humidifier_ON); 736 | 737 | char char_Humidifier_OFF[splitstring[4].length() + 1]; 738 | splitstring[4].toCharArray(char_Humidifier_OFF, sizeof(char_Humidifier_OFF)); 739 | float parsed_Humidifier_OFF = atof(char_Humidifier_OFF); 740 | 741 | char char_Dehumidifier_ON[splitstring[5].length() + 1]; 742 | splitstring[5].toCharArray(char_Dehumidifier_ON, sizeof(char_Dehumidifier_ON)); 743 | float parsed_Dehumidifier_ON = atof(char_Dehumidifier_ON); 744 | 745 | char char_Dehumidifier_OFF[splitstring[6].length() + 1]; 746 | splitstring[6].toCharArray(char_Dehumidifier_OFF, sizeof(char_Dehumidifier_OFF)); 747 | float parsed_Dehumidifier_OFF = atof(char_Dehumidifier_OFF); 748 | 749 | RHValue_Low = parsed_RHValue_Low; 750 | RHValue_High = parsed_RHValue_High; 751 | Humidifier_ON = parsed_Humidifier_ON; 752 | Humidifier_OFF = parsed_Humidifier_OFF; 753 | Dehumidifier_ON = parsed_Dehumidifier_ON; 754 | Dehumidifier_OFF = parsed_Dehumidifier_OFF; 755 | 756 | eepromWriteFloat(110, parsed_RHValue_Low); 757 | eepromWriteFloat(114, parsed_RHValue_High); 758 | eepromWriteFloat(118, parsed_Humidifier_ON); 759 | eepromWriteFloat(122, parsed_Humidifier_OFF); 760 | eepromWriteFloat(126, parsed_Dehumidifier_ON); 761 | eepromWriteFloat(130, parsed_Dehumidifier_OFF); 762 | 763 | } 764 | 765 | if(Serial_inString.indexOf("setTDS1") >=0) { 766 | char serialchar[Serial_inString.length()+1]; 767 | Serial_inString.toCharArray(serialchar, Serial_inString.length()+1); 768 | 769 | int i; 770 | String splitstring[6]; 771 | String tmpBuffer; 772 | int parsecount = 0; 773 | for (i=0;i<(Serial_inString.length()+1);i++){ 774 | if (serialchar[i] == ',') { 775 | tmpBuffer.replace(",", ""); 776 | splitstring[parsecount] = tmpBuffer; 777 | tmpBuffer = ""; 778 | parsecount++; 779 | } 780 | if (i == Serial_inString.length()){ 781 | tmpBuffer.replace(",", ""); 782 | splitstring[parsecount] = tmpBuffer; 783 | } 784 | tmpBuffer += serialchar[i]; 785 | } 786 | 787 | char char_TDS1Value_Low[splitstring[1].length() + 1]; 788 | splitstring[1].toCharArray(char_TDS1Value_Low, sizeof(char_TDS1Value_Low)); 789 | float parsed_TDS1Value_Low = atof(char_TDS1Value_Low); 790 | 791 | char char_TDS1Value_High[splitstring[2].length() + 1]; 792 | splitstring[2].toCharArray(char_TDS1Value_High, sizeof(char_TDS1Value_High)); 793 | float parsed_TDS1Value_High = atof(char_TDS1Value_High); 794 | 795 | char char_NutePump1_ON[splitstring[3].length() + 1]; 796 | splitstring[3].toCharArray(char_NutePump1_ON, sizeof(char_NutePump1_ON)); 797 | float parsed_NutePump1_ON = atof(char_NutePump1_ON); 798 | 799 | char char_NutePump1_OFF[splitstring[4].length() + 1]; 800 | splitstring[4].toCharArray(char_NutePump1_OFF, sizeof(char_NutePump1_OFF)); 801 | float parsed_NutePump1_OFF = atof(char_NutePump1_OFF); 802 | 803 | int parsed_MixPump1_Enabled = splitstring[5].toInt(); 804 | 805 | TDS1Value_Low = parsed_TDS1Value_Low; 806 | TDS1Value_High = parsed_TDS1Value_High; 807 | NutePump1_ON = parsed_NutePump1_ON; 808 | NutePump1_OFF = parsed_NutePump1_OFF; 809 | 810 | if (parsed_MixPump1_Enabled == 1) { 811 | MixPump1_Enabled = true; 812 | EEPROM.write(154, 1); 813 | } 814 | else if(parsed_MixPump1_Enabled == 0) { 815 | MixPump1_Enabled = false; 816 | EEPROM.write(154, 0); 817 | } 818 | 819 | eepromWriteFloat(134, parsed_TDS1Value_Low); 820 | eepromWriteFloat(139, parsed_TDS1Value_High); 821 | eepromWriteFloat(144, parsed_NutePump1_ON); 822 | eepromWriteFloat(149, parsed_NutePump1_OFF); 823 | 824 | } 825 | 826 | if(Serial_inString.indexOf("setTDS2") >=0) { 827 | char serialchar[Serial_inString.length()+1]; 828 | Serial_inString.toCharArray(serialchar, Serial_inString.length()+1); 829 | 830 | int i; 831 | String splitstring[6]; 832 | String tmpBuffer; 833 | int parsecount = 0; 834 | for (i=0;i<(Serial_inString.length()+1);i++){ 835 | if (serialchar[i] == ',') { 836 | tmpBuffer.replace(",", ""); 837 | splitstring[parsecount] = tmpBuffer; 838 | tmpBuffer = ""; 839 | parsecount++; 840 | } 841 | if (i == Serial_inString.length()){ 842 | tmpBuffer.replace(",", ""); 843 | splitstring[parsecount] = tmpBuffer; 844 | } 845 | tmpBuffer += serialchar[i]; 846 | } 847 | 848 | char char_TDS2Value_Low[splitstring[1].length() + 1]; 849 | splitstring[1].toCharArray(char_TDS2Value_Low, sizeof(char_TDS2Value_Low)); 850 | float parsed_TDS2Value_Low = atof(char_TDS2Value_Low); 851 | 852 | char char_TDS2Value_High[splitstring[2].length() + 1]; 853 | splitstring[2].toCharArray(char_TDS2Value_High, sizeof(char_TDS2Value_High)); 854 | float parsed_TDS2Value_High = atof(char_TDS2Value_High); 855 | 856 | char char_NutePump2_ON[splitstring[3].length() + 1]; 857 | splitstring[3].toCharArray(char_NutePump2_ON, sizeof(char_NutePump2_ON)); 858 | float parsed_NutePump2_ON = atof(char_NutePump2_ON); 859 | 860 | char char_NutePump2_OFF[splitstring[4].length() + 1]; 861 | splitstring[4].toCharArray(char_NutePump2_OFF, sizeof(char_NutePump2_OFF)); 862 | float parsed_NutePump2_OFF = atof(char_NutePump2_OFF); 863 | 864 | int parsed_MixPump2_Enabled = splitstring[5].toInt(); 865 | 866 | TDS2Value_Low = parsed_TDS2Value_Low; 867 | TDS2Value_High = parsed_TDS2Value_High; 868 | NutePump2_ON = parsed_NutePump2_ON; 869 | NutePump2_OFF = parsed_NutePump2_OFF; 870 | 871 | if (parsed_MixPump2_Enabled == 1) { 872 | MixPump2_Enabled = true; 873 | EEPROM.write(154, 1); 874 | } 875 | else if(parsed_MixPump2_Enabled == 0) { 876 | MixPump2_Enabled = false; 877 | EEPROM.write(154, 0); 878 | } 879 | 880 | eepromWriteFloat(188, parsed_TDS2Value_Low); 881 | eepromWriteFloat(193, parsed_TDS2Value_High); 882 | eepromWriteFloat(198, parsed_NutePump2_ON); 883 | eepromWriteFloat(203, parsed_NutePump2_OFF); 884 | 885 | } 886 | 887 | if(Serial_inString.indexOf("setCO2") >=0) { 888 | char serialchar[Serial_inString.length()+1]; 889 | Serial_inString.toCharArray(serialchar, Serial_inString.length()+1); 890 | 891 | int i; 892 | String splitstring[5]; 893 | String tmpBuffer; 894 | int parsecount = 0; 895 | for (i=0;i<(Serial_inString.length()+1);i++){ 896 | if (serialchar[i] == ',') { 897 | tmpBuffer.replace(",", ""); 898 | splitstring[parsecount] = tmpBuffer; 899 | tmpBuffer = ""; 900 | parsecount++; 901 | } 902 | if (i == Serial_inString.length()){ 903 | tmpBuffer.replace(",", ""); 904 | splitstring[parsecount] = tmpBuffer; 905 | } 906 | tmpBuffer += serialchar[i]; 907 | } 908 | 909 | char char_CO2Value_Low[splitstring[1].length() + 1]; 910 | splitstring[1].toCharArray(char_CO2Value_Low, sizeof(char_CO2Value_Low)); 911 | float parsed_CO2Value_Low = atof(char_CO2Value_Low); 912 | 913 | char char_CO2Value_High[splitstring[2].length() + 1]; 914 | splitstring[2].toCharArray(char_CO2Value_High, sizeof(char_CO2Value_High)); 915 | float parsed_CO2Value_High = atof(char_CO2Value_High); 916 | 917 | char char_CO2_ON[splitstring[3].length() + 1]; 918 | splitstring[3].toCharArray(char_CO2_ON, sizeof(char_CO2_ON)); 919 | float parsed_CO2_ON = atof(char_CO2_ON); 920 | 921 | char char_CO2_OFF[splitstring[4].length() + 1]; 922 | splitstring[4].toCharArray(char_CO2_OFF, sizeof(char_CO2_OFF)); 923 | float parsed_CO2_OFF = atof(char_CO2_OFF); 924 | 925 | int parsed_CO2_Enabled = splitstring[5].toInt(); 926 | 927 | if (parsed_CO2_Enabled == 1) { 928 | CO2_Enabled = true; 929 | EEPROM.write(171, 1); 930 | } 931 | else if(parsed_CO2_Enabled == 0) { 932 | CO2_Enabled = false; 933 | EEPROM.write(171, 0); 934 | } 935 | 936 | CO2Value_Low = parsed_CO2Value_Low; 937 | CO2Value_High = parsed_CO2Value_High; 938 | CO2_ON = parsed_CO2_ON; 939 | CO2_OFF = parsed_CO2_OFF; 940 | 941 | 942 | eepromWriteFloat(155, parsed_CO2Value_Low); 943 | eepromWriteFloat(159, parsed_CO2Value_High); 944 | eepromWriteFloat(163, parsed_CO2_ON); 945 | eepromWriteFloat(167, parsed_CO2_OFF); 946 | 947 | } 948 | 949 | if(Serial_inString.indexOf("setLight") >=0) { 950 | char serialchar[Serial_inString.length()+1]; 951 | Serial_inString.toCharArray(serialchar, Serial_inString.length()+1); 952 | 953 | int i; 954 | String splitstring[3]; 955 | String tmpBuffer; 956 | int parsecount = 0; 957 | for (i=0;i<(Serial_inString.length()+1);i++){ 958 | if (serialchar[i] == ',') { 959 | tmpBuffer.replace(",", ""); 960 | splitstring[parsecount] = tmpBuffer; 961 | tmpBuffer = ""; 962 | parsecount++; 963 | } 964 | if (i == Serial_inString.length()){ 965 | tmpBuffer.replace(",", ""); 966 | splitstring[parsecount] = tmpBuffer; 967 | } 968 | tmpBuffer += serialchar[i]; 969 | } 970 | 971 | char char_LightValue_Low[splitstring[1].length() + 1]; 972 | splitstring[1].toCharArray(char_LightValue_Low, sizeof(char_LightValue_Low)); 973 | float parsed_LightValue_Low = atof(char_LightValue_Low); 974 | 975 | char char_LightValue_High[splitstring[2].length() + 1]; 976 | splitstring[2].toCharArray(char_LightValue_High, sizeof(char_LightValue_High)); 977 | float parsed_LightValue_High = atof(char_LightValue_High); 978 | 979 | 980 | LightValue_Low = parsed_LightValue_Low; 981 | LightValue_High = parsed_LightValue_High; 982 | 983 | eepromWriteFloat(172, parsed_LightValue_Low); 984 | eepromWriteFloat(176, parsed_LightValue_High); 985 | 986 | } 987 | Serial_inString = ""; 988 | serialcounter = 1; 989 | sendserialmessages(); 990 | } 991 | else { 992 | // add it to the inputString: 993 | Serial_inString += inChar; 994 | } 995 | } 996 | } 997 | 998 | void sendRelayMessages() { 999 | //RELAYS 1000 | Serial1.print("Relays,"); 1001 | if (digitalRead(Relay1_Pin) == LOW){ 1002 | Serial1.print(1); 1003 | } 1004 | else if (digitalRead(Relay1_Pin) == HIGH) { 1005 | Serial1.print(0); 1006 | } 1007 | Serial1.print(","); 1008 | if (digitalRead(Relay2_Pin) == LOW){ 1009 | Serial1.print(1); 1010 | } 1011 | else if (digitalRead(Relay2_Pin) == HIGH) { 1012 | Serial1.print(0); 1013 | } 1014 | Serial1.print(","); 1015 | if (digitalRead(Relay3_Pin) == LOW){ 1016 | Serial1.print(1); 1017 | } 1018 | else if (digitalRead(Relay3_Pin) == HIGH) { 1019 | Serial1.print(0); 1020 | } 1021 | Serial1.print(","); 1022 | if (digitalRead(Relay4_Pin) == LOW){ 1023 | Serial1.print(1); 1024 | } 1025 | else if (digitalRead(Relay4_Pin) == HIGH) { 1026 | Serial1.print(0); 1027 | } 1028 | Serial1.print(","); 1029 | if (digitalRead(Relay5_Pin) == LOW){ 1030 | Serial1.print(1); 1031 | } 1032 | else if (digitalRead(Relay5_Pin) == HIGH) { 1033 | Serial1.print(0); 1034 | } 1035 | Serial1.print(","); //This Relay is opposite 1036 | if (digitalRead(Relay6_Pin) == HIGH){ 1037 | Serial1.println(1); 1038 | } 1039 | else if (digitalRead(Relay6_Pin) == LOW) { 1040 | Serial1.println(0); 1041 | } 1042 | 1043 | //Relay_isAuto Values (Modes) 1044 | Serial1.print("Relay_isAuto,"); 1045 | Serial1.print(Relay1_isAuto); 1046 | Serial1.print(","); 1047 | Serial1.print(Relay2_isAuto); 1048 | Serial1.print(","); 1049 | Serial1.print(Relay3_isAuto); 1050 | Serial1.print(","); 1051 | Serial1.print(Relay4_isAuto); 1052 | Serial1.print(","); 1053 | Serial1.print(Relay5_isAuto); 1054 | Serial1.print(","); 1055 | Serial1.println(Relay6_isAuto); 1056 | } 1057 | -------------------------------------------------------------------------------- /yieldbuddy_arduino/Timer_functions.ino: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | /* 3 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 4 | /!!CHECK TIMERS!!CHECK TIMERS!!CHECK TIMERS!!CHECK TIMERS!!CHECK TIMERS!!CHECK TIMERS!!CHECK TIMERS!!CHECK TIMERS!!CHECK TIMERS!!CHECK TIMERS!!CHECK TIMERS!!CHECK TIMERS!!CHECK TIMERS!!CHECK TIMERS!!!!CHECK TIMERS!!CHECK TIMERS!!CHECK TIMERS!! 5 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 6 | */ 7 | void CheckTimers(){ 8 | //Check Light Timer 9 | // Serial1.println(); 10 | // Serial1.print("Light Schedule Timer: "); 11 | // Serial1.println(); 12 | // Serial1.print("hour: "); 13 | // Serial1.print(hour()); 14 | // Serial1.println(); 15 | // Serial1.print("minute: "); 16 | // Serial1.print(minute()); 17 | // Serial1.println(); 18 | // Serial1.print("Light_ON_hour: "); 19 | // Serial1.print(Light_ON_hour); 20 | // Serial1.println(); 21 | // Serial1.print("Light_ON_min: "); 22 | // Serial1.print(Light_ON_min); 23 | // Serial1.println(); 24 | // Serial1.print("Light_OFF_hour: "); 25 | // Serial1.print(Light_OFF_hour); 26 | // Serial1.println(); 27 | // Serial1.print("Light_OFF_min: "); 28 | // Serial1.print(Light_OFF_min); 29 | // Serial1.println(); 30 | 31 | if (Relay6_isAuto == 1){ 32 | 33 | 34 | 35 | int TurnLightOn = 2; //0: Turn Off 1: Turn On 36 | 37 | if (Light_ON_hour < Light_OFF_hour) { 38 | if (hour() >= Light_ON_hour && hour() <= Light_OFF_hour) { 39 | if (hour() == Light_OFF_hour && minute() < Light_OFF_min) { 40 | TurnLightOn = 1; 41 | goto exit_loop_light; 42 | } 43 | if (hour() == Light_ON_hour && minute() >= Light_ON_min) { 44 | TurnLightOn = 1; 45 | goto exit_loop_light; 46 | } 47 | if (hour() != Light_OFF_hour && hour() != Light_ON_hour && hour() > Light_ON_hour && hour() < Light_OFF_hour){ 48 | TurnLightOn = 1; 49 | goto exit_loop_light; 50 | } 51 | } 52 | } 53 | 54 | if (Light_ON_hour > Light_OFF_hour) { 55 | if (hour() <= Light_OFF_hour || hour() >= Light_ON_hour) { 56 | if (hour() == Light_OFF_hour && minute() < Light_OFF_min) { 57 | TurnLightOn = 1; 58 | goto exit_loop_light; 59 | } 60 | if (hour() == Light_ON_hour && minute() >= Light_ON_min) { 61 | TurnLightOn = 1; 62 | goto exit_loop_light; 63 | } 64 | if (hour() != Light_OFF_hour && hour() != Light_ON_hour){ 65 | if (hour() > Light_ON_hour && hour() < 24){ 66 | TurnLightOn = 1; 67 | goto exit_loop_light; 68 | } 69 | if (hour() < Light_OFF_hour) { 70 | TurnLightOn = 1; 71 | goto exit_loop_light; 72 | } 73 | } 74 | } 75 | } 76 | 77 | exit_loop_light:; 78 | if (TurnLightOn == 1) { 79 | if (Relay6_isAuto == 1){ 80 | Relay6_State = 1; 81 | EEPROM.write(11,1); 82 | turnRelay(6, 1); 83 | } 84 | // Serial1.println(); 85 | // Serial1.println("Turned Light ON"); 86 | // Serial1.println(); 87 | } 88 | else { 89 | if (Relay6_isAuto == 1){ 90 | Relay6_State = 0; 91 | EEPROM.write(11,0); 92 | turnRelay(6, 0); 93 | } 94 | // Serial1.println(); 95 | // Serial1.println("Turned Light OFF"); 96 | // Serial1.println(); 97 | } 98 | 99 | 100 | } 101 | 102 | //Check Pump Timers 103 | 104 | int Pump_hour_on; 105 | int Pump_min_on; 106 | int Pump_hour_off; 107 | int Pump_min_off; 108 | 109 | int TurnPumpOn = 2; //0: Turn Off 1: Turn On 2: Unsure 110 | 111 | 112 | int i = 0; 113 | // Serial1.println(); 114 | // Serial1.print("Water Pump Timers: "); 115 | // Serial1.println(); 116 | 117 | for(i=0;i 59) { 136 | Pump_min_on = 60 - Pump_min_on; 137 | Pump_hour_on++; 138 | } 139 | if (Pump_hour_on > 23) { 140 | Pump_hour_on = Pump_hour_on - 24; 141 | } 142 | 143 | if (Pump_min_off > 59) { 144 | Pump_min_off = Pump_min_off - 60; 145 | Pump_hour_off++; 146 | } 147 | if (Pump_hour_off > 23) { 148 | Pump_hour_off = Pump_hour_off - 24; 149 | } 150 | 151 | // Serial1.print(i); 152 | // Serial1.print(") "); 153 | // Serial1.print("Hour: "); 154 | // Serial1.print(hour()); 155 | // Serial1.print(" Minute: "); 156 | // Serial1.print(minute()); 157 | // Serial1.print(" On Time: "); 158 | // Serial1.print(Pump_hour_on); 159 | // Serial1.print(":"); 160 | // Serial1.print(Pump_min_on); 161 | // Serial1.print(" Off Time: "); 162 | // Serial1.print(Pump_hour_off); 163 | // Serial1.print(":"); 164 | // Serial1.print(Pump_min_off); 165 | // Serial1.print(" Is AM:"); 166 | // Serial1.println(Pump_isAM_array[i]); 167 | // Serial1.println(); 168 | 169 | if (Pump_hour_on == 23 && Pump_hour_off < Pump_hour_on) { 170 | if (Pump_hour_on == hour() && minute() >= Pump_min_on ) { 171 | SwitchPump(1); 172 | goto exit_loop_pump; 173 | } 174 | if (hour() < Pump_hour_off) { 175 | SwitchPump(1); 176 | goto exit_loop_pump; 177 | } 178 | if (hour() == Pump_hour_off) { 179 | if (minute() < Pump_min_off) { 180 | SwitchPump(1); 181 | goto exit_loop_pump; 182 | } 183 | } 184 | } 185 | 186 | if (hour() == Pump_hour_on && hour() <= Pump_hour_off) { 187 | if (minute() >= Pump_min_on) { 188 | if (Pump_hour_off != Pump_hour_on && hour() == Pump_hour_off && minute() < Pump_min_off){ 189 | SwitchPump(1); 190 | goto exit_loop_pump; 191 | } 192 | if (Pump_hour_off != Pump_hour_on && hour() == Pump_hour_on && minute() >= Pump_min_on){ 193 | SwitchPump(1); 194 | goto exit_loop_pump; 195 | } 196 | if (Pump_hour_off == Pump_hour_on && minute() >= Pump_min_on && minute() < Pump_min_off){ 197 | SwitchPump(1); 198 | goto exit_loop_pump; 199 | } 200 | } 201 | 202 | } 203 | if (hour() > Pump_hour_on && hour() < Pump_hour_off) { 204 | SwitchPump(1); 205 | goto exit_loop_pump; 206 | } 207 | if (hour() >= Pump_hour_on && hour() == Pump_hour_off) { 208 | if (Pump_hour_off != Pump_hour_on && hour() == Pump_hour_off && minute() < Pump_min_off){ 209 | SwitchPump(1); 210 | goto exit_loop_pump; 211 | } 212 | if (Pump_hour_off != Pump_hour_on && hour() == Pump_hour_on && minute() >= Pump_min_on){ 213 | SwitchPump(1); 214 | goto exit_loop_pump; 215 | } 216 | if (Pump_hour_off == Pump_hour_on && minute() >= Pump_min_on && minute() < Pump_min_off){ 217 | SwitchPump(1); 218 | goto exit_loop_pump; 219 | } 220 | } 221 | 222 | 223 | } 224 | 225 | SwitchPump(TurnPumpOn); 226 | exit_loop_pump:; 227 | } 228 | 229 | void SwitchPump(int TurnPumpOn){ 230 | // Serial1.print("TurnPumpOn: "); 231 | // Serial1.println(TurnPumpOn); 232 | if (TurnPumpOn == 1) { 233 | if (Relay1_isAuto == 1) { 234 | Relay1_State = 1; 235 | EEPROM.write(6,1); 236 | turnRelay(1, 1); 237 | } 238 | if (Relay2_isAuto == 1) { 239 | Relay2_State = 1; 240 | EEPROM.write(7,1); 241 | turnRelay(2, 1); 242 | } 243 | // Serial1.println(); 244 | // Serial1.println("Turned Water Pump On"); 245 | // Serial1.println(); 246 | } 247 | else if (TurnPumpOn == 0 || TurnPumpOn == 2) { 248 | if (Relay1_isAuto == 1){ 249 | Relay1_State = 0; 250 | EEPROM.write(6,0); 251 | turnRelay(1, 0); 252 | } 253 | if (Relay2_isAuto == 1){ 254 | Relay2_State = 0; 255 | EEPROM.write(7,0); 256 | turnRelay(2, 0); 257 | } 258 | // Serial1.println(); 259 | // Serial1.println("Turned Water Pump Off"); 260 | // Serial1.println(); 261 | } 262 | } 263 | 264 | -------------------------------------------------------------------------------- /yieldbuddy_arduino/UpdateSensors_functions.ino: -------------------------------------------------------------------------------- 1 | /* 2 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3 | /!!UPDATE SENSOR VALUES!!UPDATE SENSOR VALUES!!UPDATE SENSOR VALUES!!UPDATE SENSOR VALUES!!UPDATE SENSOR VALUES!!UPDATE SENSOR VALUES!!UPDATE SENSOR VALUES!!UPDATE SENSOR VALUES!!UPDATE SENSOR VALUES!!UPDATE SENSOR VALUES!! 4 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 5 | */ 6 | 7 | //READ ALL SENSOR VALUES AND CONVERT FOR LCD DISPLAY 8 | void updateSensorValues() { 9 | 10 | analogReference(DEFAULT); //Seems more accurate. 11 | 12 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 13 | !!PH SENSORS!!PH SENSORS!!PH SENSORS!!PH SENSORS!!PH SENSORS!!PH SENSORS!!PH SENSORS!!PH SENSORS!!PH SENSORS!! 14 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 15 | /*PH1------------------------------------------------*/ 16 | float pH1Sum = 0; 17 | int j = 0; 18 | analogRead(pH1Pin); //Get ADC to switch to correct pin 19 | delay(20); //Wait for Pin to Change 20 | 21 | while(j<30) { 22 | pH1Sum = pH1Sum + analogRead(pH1Pin); 23 | j++; 24 | } 25 | pH1RawValue = pH1Sum/30; 26 | 27 | pH1Value = (0.0178 * pH1RawValue - 1.889); 28 | if(isnan(pH1Value)){ 29 | pH1Value = 0; 30 | } 31 | PString my_pH1_string(pH1_char, sizeof(pH1_char)); 32 | if (pH1Value < 10){ 33 | my_pH1_string.print(" "); 34 | my_pH1_string.println(pH1Value); 35 | } 36 | else { 37 | my_pH1_string.println(pH1Value); 38 | } 39 | 40 | 41 | 42 | /*PH2------------------------------------------------*/ 43 | float pH2Sum = 0; 44 | j = 0; 45 | analogRead(pH2Pin); //Get ADC to switch to correct pin 46 | delay(15); //Wait for Pin to Change 47 | 48 | while(j<30) { 49 | pH2Sum = pH2Sum + analogRead(pH2Pin); 50 | j++; 51 | } 52 | pH2RawValue = pH2Sum/30; 53 | 54 | pH2Value = (0.0178 * pH2RawValue - 1.889); 55 | if(isnan(pH2Value)){ 56 | pH2Value = 0; 57 | } 58 | PString my_pH2_string(pH2_char, sizeof(pH2_char)); 59 | if (pH2Value < 20){ 60 | my_pH2_string.print(" "); 61 | my_pH2_string.println(pH2Value); 62 | } 63 | else { 64 | my_pH2_string.println(pH2Value); 65 | } 66 | 67 | 68 | 69 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 70 | !!TEMPERATURE SENSOR!!TEMPERATURE SENSOR!!TEMPERATURE SENSOR!!TEMPERATURE SENSOR!!TEMPERATURE SENSOR!! 71 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 72 | float TempSum = 0; 73 | j = 0; 74 | analogRead(TempPin); //Get ADC to switch to correct pin 75 | delay(15); //Wait for Pin to Change 76 | 77 | while(j<10) { 78 | TempSum = TempSum + analogRead(TempPin); 79 | j++; 80 | } 81 | 82 | TempRawValue = TempSum/((j-1) * 2); 83 | 84 | TempValue = ((5.00 * TempRawValue * 100.0)/1024.0) + 8.50; 85 | 86 | ; //dht.readTemperature(); to use the DHT11 87 | if(isnan(TempValue)){ 88 | TempValue = 0; 89 | } 90 | PString my_Temp_string(Temp_char, sizeof(Temp_char)); 91 | my_Temp_string.print(TempValue); 92 | my_Temp_string.println(" C"); 93 | 94 | 95 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 96 | !!HUMIDITY DHT11 SENSOR!!HUMIDITY DHT11 SENSOR!!HUMIDITY DHT11 SENSOR!!HUMIDITY DHT11 SENSOR!!HUMIDITY DHT11!! 97 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 98 | // float RHSum = 0; 99 | // j = 0; 100 | // 101 | // while(j<30) { 102 | // RHSum = RHSum + ; 103 | // j++; 104 | // delay(10); 105 | // } 106 | // RHRawValue = RHSum/30; 107 | dht.readHumidity(); //The DHT11 Sensor works differently, but for 'good measure'. 108 | delay(15); //Wait for Pin to Change 109 | RHValue = dht.readHumidity(); 110 | if (isnan(RHValue)) { 111 | RHValue = 0; 112 | } 113 | PString my_RH_string(RH_char, sizeof(RH_char)); 114 | my_RH_string.print(RHValue); 115 | 116 | if (RHValue < 10){ 117 | my_RH_string.println("% "); 118 | } 119 | else { 120 | my_RH_string.println("%"); 121 | } 122 | 123 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 124 | !!TDS1 SENSOR!!TDS1 SENSOR!!TDS1 SENSOR!!TDS1 SENSOR!!TDS1 SENSOR!!TDS1 SENSOR!!TDS1 SENSOR!!TDS1 SENSOR!!TDS1 SENSOR!! 125 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 126 | float TDS1Sum = 0; 127 | j = 0; 128 | analogRead(TDS1Pin); //Get ADC to switch to correct pin 129 | delay(15); //Wait for Pin to Change 130 | 131 | while(j<10) { 132 | TDS1Sum = TDS1Sum + analogRead(TDS1Pin); 133 | j++; 134 | } 135 | 136 | TDS1RawValue = TDS1Sum/((j-1) * 2); 137 | 138 | TDS1Value = ((TDS1RawValue * 100.0)/1024.0); 139 | 140 | if(isnan(TDS1Value)){ 141 | TDS1Value = 0; 142 | } 143 | PString my_TDS1_string(TDS1_char, sizeof(TDS1_char)); 144 | my_TDS1_string.println(TDS1Value); 145 | my_TDS1_string.println(" ppm"); 146 | 147 | 148 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 149 | !!TDS2 SENSOR!!TDS2 SENSOR!!TDS2 SENSOR!!TDS2 SENSOR!!TDS2 SENSOR!!TDS2 SENSOR!!TDS2 SENSOR!!TDS2 SENSOR!!TDS2 SENSOR!! 150 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 151 | float TDS2Sum = 0; 152 | j = 0; 153 | analogRead(TDS2Pin); //Get ADC to switch to correct pin 154 | delay(15); //Wait for Pin to Change 155 | 156 | while(j<10) { 157 | TDS2Sum = TDS2Sum + analogRead(TDS2Pin); 158 | j++; 159 | } 160 | 161 | TDS2RawValue = TDS2Sum/((j-1) * 2); 162 | 163 | TDS2Value = ((TDS2RawValue * 100.0)/1024.0); 164 | 165 | if(isnan(TDS2Value)){ 166 | TDS2Value = 0; 167 | } 168 | PString my_TDS2_string(TDS2_char, sizeof(TDS2_char)); 169 | my_TDS2_string.print(TDS2Value); 170 | my_TDS2_string.println(" ppm"); 171 | 172 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 173 | !!CO2 SENSOR!!CO2 SENSOR!!CO2 SENSOR!!CO2 SENSOR!!CO2 SENSOR!!CO2 SENSOR!!CO2 SENSOR!!CO2 SENSOR!!CO2 SENSOR!! 174 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 175 | float CO2Sum = 0; 176 | j = 0; 177 | analogRead(CO2Pin); //Get ADC to switch to correct pin 178 | delay(15); //Wait for Pin to Change 179 | 180 | while(j<10) { 181 | CO2Sum = CO2Sum + analogRead(CO2Pin); 182 | j++; 183 | } 184 | 185 | CO2RawValue = CO2Sum/((j-1) * 2); 186 | 187 | CO2Value = ((CO2RawValue * 100.0)/1024.0); 188 | 189 | if(isnan(CO2Value)){ 190 | CO2Value = 0; 191 | } 192 | PString my_CO2_string(CO2_char, sizeof(CO2_char)); 193 | my_CO2_string.print(CO2Value); 194 | my_CO2_string.println(" ppm"); 195 | 196 | 197 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 198 | !!LIGHT SENSOR!!LIGHT SENSOR!!LIGHT SENSOR!!LIGHT SENSOR!!LIGHT SENSOR!!LIGHT SENSOR!!LIGHT SENSOR!! 199 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 200 | float LightSum = 0; 201 | j = 0; 202 | analogRead(LightPin); //Get ADC to switch to correct pin 203 | delay(10); //Wait for Pin to Change 204 | 205 | while(j<10) { 206 | LightSum = LightSum + analogRead(LightPin); 207 | j++; 208 | } 209 | 210 | LightRawValue = LightSum/10; 211 | 212 | LightValue = ((LightRawValue * 100.0) / 1024.0); 213 | 214 | if (isnan(LightValue)) { 215 | LightValue = 0; 216 | } 217 | PString my_Light_string(Light_char, sizeof(Light_char)); 218 | my_Light_string.print(LightValue); 219 | if (LightValue < 10){ 220 | my_Light_string.println("% "); 221 | } 222 | else { 223 | my_Light_string.println("%"); 224 | } 225 | 226 | 227 | 228 | 229 | 230 | //pH 231 | if (pH1Value < pH1Value_Low) { 232 | pH1_Status = "LOW"; 233 | } 234 | else if (pH1Value > pH1Value_Low && pH1Value < pH1Value_High) { 235 | pH1_Status = "OK"; 236 | } 237 | else if (pH1Value > pH1Value_High) { 238 | pH1_Status = "HIGH"; 239 | } 240 | 241 | 242 | if (pH2Value < pH2Value_Low) { 243 | pH2_Status = "LOW"; 244 | } 245 | else if (pH2Value > pH2Value_Low && pH2Value < pH2Value_High) { 246 | pH2_Status = "OK"; 247 | } 248 | else if (pH2Value > pH2Value_High) { 249 | pH2_Status = "HIGH"; 250 | } 251 | 252 | //Temp 253 | if (TempValue < TempValue_Low) { 254 | Temp_Status = "LOW"; 255 | } 256 | else if (TempValue > TempValue_Low && TempValue < TempValue_High) { 257 | Temp_Status = "OK"; 258 | } 259 | else if (TempValue > TempValue_High) { 260 | Temp_Status = "HIGH"; 261 | } 262 | //RH 263 | if (RHValue < RHValue_Low) { 264 | RH_Status = "LOW"; 265 | } 266 | else if (RHValue > RHValue_Low && RHValue < RHValue_High) { 267 | RH_Status = "OK"; 268 | } 269 | else if (RHValue < RHValue_High) { 270 | RH_Status = "HIGH"; 271 | } 272 | //TDS1 273 | if (TDS1Value < TDS1Value_Low) { 274 | TDS1_Status = "LOW"; 275 | } 276 | else if (TDS1Value > TDS1Value_Low && TDS1Value < TDS1Value_High) { 277 | TDS1_Status = "OK"; 278 | } 279 | else if (TDS1Value < TDS1Value_High) { 280 | TDS1_Status = "HIGH"; 281 | } 282 | //TDS2 283 | if (TDS2Value < TDS2Value_Low) { 284 | TDS2_Status = "LOW"; 285 | } 286 | else if (TDS2Value > TDS2Value_Low && TDS2Value < TDS2Value_High) { 287 | TDS2_Status = "OK"; 288 | } 289 | else if (TDS2Value < TDS2Value_High) { 290 | TDS2_Status = "HIGH"; 291 | } 292 | //CO2 293 | if (CO2Value < CO2Value_Low) { 294 | CO2_Status = "LOW"; 295 | } 296 | else if (CO2Value > CO2Value_Low && CO2Value < CO2Value_High) { 297 | CO2_Status = "OK"; 298 | } 299 | else if (CO2Value > CO2Value_High){ 300 | CO2_Status = "HIGH"; 301 | } 302 | //Light 303 | if (LightValue < LightValue_Low) { 304 | Light_Status = "LOW"; 305 | } 306 | else if (LightValue > LightValue_Low && LightValue < LightValue_High) { 307 | Light_Status = "OK"; 308 | } 309 | else if (LightValue < LightValue_High) { 310 | Light_Status = "HIGH"; 311 | } 312 | 313 | } 314 | -------------------------------------------------------------------------------- /yieldbuddy_arduino/readme: -------------------------------------------------------------------------------- 1 | yieldbuddy_arduino.ino is the main sketch file. 2 | -------------------------------------------------------------------------------- /yieldbuddy_arduino/yieldbuddy_arduino.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "Arduino.h" 9 | 10 | /* 11 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 12 | /!!VARIABLES!!VARIABLES!!VARIABLES!!VARIABLES!!VARIABLES!!VARIABLES!!VARIABLES!!VARIABLES!!VARIABLES!! 13 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 14 | */ 15 | 16 | String Serial_inString = ""; 17 | boolean stringComplete = false; 18 | int serialcounter = 0; 19 | 20 | char longdate[25] = "Jan 01, 2012 12:00:00 PM"; 21 | char pH1_char[6] = "00.00"; 22 | char pH2_char[6] = "00.00"; 23 | char Temp_char[8]= ""; 24 | char RH_char[7] = "00.00%"; 25 | char TDS1_char[11] = "0000.0ppm"; 26 | char TDS2_char[11] = "0000.0ppm"; 27 | char CO2_char[8] = "00.00%"; 28 | char Light_char[7] = "00.00%"; 29 | 30 | //Temporary placeholders for Time Settings Screen 31 | int tmp_month; 32 | int tmp_day; 33 | int tmp_year; 34 | int tmp_hour; 35 | int tmp_minute; 36 | int tmp_second; 37 | 38 | int last_minute; 39 | 40 | //Note: Committed Time Settings are stored as their associated month(), day(), year(), etc... as per 41 | 42 | //Hours of the day array 43 | String DayHours[24] = { 44 | "12:00 AM"," 1:00 AM"," 2:00 AM"," 3:00 AM"," 4:00 AM"," 5:00 AM"," 6:00 AM"," 7:00 AM"," 8:00 AM"," 9:00 AM","10:00 AM","11:00 AM", 45 | "12:00 PM"," 1:00 PM"," 2:00 PM"," 3:00 PM"," 4:00 PM"," 5:00 PM"," 6:00 PM"," 7:00 PM"," 8:00 PM"," 9:00 PM","10:00 PM","11:00 PM"}; 46 | 47 | //Temporary placeholders for Light Schedule Screen 48 | int tmp_send; 49 | int tmp_Light_ON_hour; 50 | int tmp_Light_ON_min; 51 | int tmp_Light_OFF_hour; 52 | int tmp_Light_OFF_min; 53 | 54 | //Committed Light Settings 55 | int Light_ON_hour = 0; 56 | int Light_ON_min = 0; 57 | int Light_OFF_hour = 18; 58 | int Light_OFF_min = 0; 59 | 60 | //Temporary placeholders for Pump Schedule Screen 61 | int tmp_Pump_start_hour; 62 | int tmp_Pump_start_min; 63 | boolean tmp_Pump_start_isAM = true; 64 | int tmp_Pump_every_hours; 65 | int tmp_Pump_every_mins; 66 | int tmp_Pump_for; //In Minutes 67 | int tmp_Pump_times; //Number of times per day 68 | 69 | int tmp_Pump_hour_array[16]; 70 | int tmp_Pump_min_array[16]; 71 | boolean tmp_Pump_isAM_array[16]; 72 | 73 | //Committed Pump Schedule Settings 74 | int Pump_start_hour = 7; 75 | int Pump_start_min = 15; 76 | boolean Pump_start_isAM = true; 77 | int Pump_every_hours = 2; 78 | int Pump_every_mins = 30; 79 | int Pump_for = 15; //In Minutes 80 | int Pump_times = 1; //Number of times per day 81 | 82 | int Pump_hour_array[16]; 83 | int Pump_min_array[16]; 84 | boolean Pump_isAM_array[16]; 85 | 86 | 87 | /* 88 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 89 | /!!SENSOR VARIABLES!!SENSOR VARIABLES!!SENSOR VARIABLES!!SENSOR VARIABLES!!SENSOR VARIABLES!!SENSOR VARIABLES!! 90 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 91 | */ 92 | 93 | //Values the arduino sees 94 | int pH1RawValue = 0; 95 | int pH2RawValue = 0; 96 | int TempRawValue = 0; 97 | int RHRawValue = 0; 98 | int TDS1RawValue = 0; 99 | int TDS2RawValue = 0; 100 | int CO2RawValue = 0; 101 | int LightRawValue = 0; 102 | 103 | //Values the humans see (after it has been calculated using raw values above ^^^ and their respected formulas) 104 | float pH1Value = 0; 105 | float pH2Value = 0; 106 | float TempValue = 0; 107 | float RHValue = 0; 108 | float TDS1Value = 0; 109 | float TDS2Value = 0; 110 | float CO2Value = 0; 111 | float LightValue = 0; 112 | 113 | //PH 114 | //Status Indicator Values 115 | String pH1_Status = "OK"; 116 | float pH1Value_Low = 5.60; 117 | float pH1Value_High = 6.10; 118 | 119 | String pH2_Status = "OK"; 120 | float pH2Value_Low = 5.60; 121 | float pH2Value_High = 6.10; 122 | 123 | //Temp 124 | String Temp_Status = "OK"; 125 | float TempValue_Low = 21.00; 126 | float TempValue_High = 29.00; 127 | //Accessory ON/OFF Values 128 | float Heater_ON = 21.00; 129 | float Heater_OFF = 25.00; 130 | float AC_ON = 29.00; 131 | float AC_OFF = 25.00; 132 | 133 | 134 | //Humidty(RH) 135 | String RH_Status = "OK"; 136 | float RHValue_Low = 30.00; 137 | float RHValue_High = 80.00; 138 | //Accessory ON/OFF Values 139 | float Humidifier_ON = 40.00; 140 | float Humidifier_OFF = 60.00; 141 | float Dehumidifier_ON = 80.00; 142 | float Dehumidifier_OFF = 60.00; 143 | 144 | //TDS1 145 | String TDS1_Status = "OK"; 146 | float TDS1Value_Low = 500.0; 147 | float TDS1Value_High = 800.0; 148 | //Accessory ON/OFF Values 149 | float NutePump1_ON = 500.0; 150 | float NutePump1_OFF = 800.0; 151 | boolean MixPump1_Enabled = true; 152 | 153 | //TDS2 154 | String TDS2_Status = "OK"; 155 | float TDS2Value_Low = 500.0; 156 | float TDS2Value_High = 800.0; 157 | //Accessory ON/OFF Values 158 | float NutePump2_ON = 500.0; 159 | float NutePump2_OFF = 800.0; 160 | boolean MixPump2_Enabled = true; 161 | 162 | //CO2 163 | String CO2_Status = "OK"; 164 | float CO2Value_Low = 60.00; 165 | float CO2Value_High= 75.00; 166 | //Accessory ON/OFF Values 167 | float CO2_ON = 40.00; 168 | float CO2_OFF = 60.00 ; 169 | boolean CO2_Enabled = true; 170 | 171 | //Light 172 | String Light_Status = "OK"; 173 | float LightValue_Low = 20.00; 174 | float LightValue_High = 95.00; 175 | 176 | 177 | /* 178 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 179 | /!!PIN DEFINITIONS!!PIN DEFINITIONS!!PIN DEFINITIONS!!PIN DEFINITIONS!!PIN DEFINITIONS!!PIN DEFINITIONS!! 180 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 181 | */ 182 | int pH1Pin = A3; 183 | int pH2Pin = A4; 184 | int TempPin = A0; 185 | 186 | //RH 187 | #define DHTPIN 28 188 | #define DHTTYPE DHT11 // DHT 11 189 | DHT dht(DHTPIN, DHTTYPE); 190 | 191 | int TDS1Pin = A5; 192 | int TDS2Pin = A6; 193 | int CO2Pin = A1; 194 | int LightPin = A2; 195 | 196 | int Relay1_Pin = 27; //Water Pump 1 197 | int Relay2_Pin = 26; //Water Pump 2 198 | int Relay3_Pin = 25; //Free 199 | int Relay4_Pin = 24; //Free 200 | int Relay5_Pin = 23; //Free 201 | int Relay6_Pin = 22; //Light/Ballast 202 | 203 | int Relay1_State = 0; 204 | int Relay2_State = 0; 205 | int Relay3_State = 0; 206 | int Relay4_State = 0; 207 | int Relay5_State = 0; 208 | int Relay6_State = 0; 209 | 210 | int Relay1_isAuto = 1; //Water Pump 1 211 | int Relay2_isAuto = 1; //Water Pump 2 212 | int Relay3_isAuto = 0; //Free 213 | int Relay4_isAuto = 0; //Free 214 | int Relay5_isAuto = 0; //Free 215 | int Relay6_isAuto = 1; //Light/Ballast 216 | 217 | /* 218 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 219 | /!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!!SETUP!! 220 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 221 | */ 222 | void setup() 223 | { 224 | //Set Pin Modes 225 | pinMode(Relay1_Pin, OUTPUT); 226 | pinMode(Relay2_Pin, OUTPUT); 227 | pinMode(Relay3_Pin, OUTPUT); 228 | pinMode(Relay4_Pin, OUTPUT); 229 | pinMode(Relay5_Pin, OUTPUT); 230 | pinMode(Relay6_Pin, OUTPUT); 231 | 232 | //COMMENT OUT THIS SECTION ON FIRST START UP!!----------------------------------- 233 | //EEPROM TIME 234 | int eeprom_hr = EEPROM.read(0); 235 | int eeprom_min = EEPROM.read(1); 236 | int eeprom_sec = EEPROM.read(2); 237 | int eeprom_day = EEPROM.read(3); 238 | int eeprom_month = EEPROM.read(4); 239 | int eeprom_yr = EEPROM.read(5); 240 | 241 | //EEPROM RELAYS 242 | Relay1_State = 0; //EEPROM.read(6); //Water-Pump 1 243 | Relay2_State = 0; //EEPROM.read(7); //Water-Pump 2 244 | Relay3_State = 0; //EEPROM.read(8); //Free 245 | Relay4_State = 0; //EEPROM.read(9); //Free 246 | Relay5_State = 0; //EEPROM.read(10); //Free 247 | Relay6_State = 0; //EEPROM.read(11); //Light/Ballast 248 | 249 | Relay1_isAuto = EEPROM.read(211); //Water Pump 1 250 | Relay2_isAuto = EEPROM.read(212); //Water Pump 2 251 | Relay3_isAuto = EEPROM.read(213); //Free 252 | Relay4_isAuto = EEPROM.read(214); //Free 253 | Relay5_isAuto = EEPROM.read(215); //Free 254 | Relay6_isAuto = EEPROM.read(216); //Light/Ballast 255 | 256 | 257 | //Safe-Route ---> Disregard last known states and turn all relays off (auto will take over): 258 | turnRelay(1, 0); 259 | turnRelay(2, 0); 260 | turnRelay(3, 0); 261 | turnRelay(4, 0); 262 | turnRelay(5, 0); 263 | turnRelay(6, 0); 264 | 265 | 266 | //If Relay is not set for automatic mode, then resume last known state 267 | //(ie. Set relay as it was before a power failure?) 268 | // if (Relay1_State == 0 && Relay1_isAuto == 0) { 269 | // turnRelay(1, 0); 270 | // } else if (Relay2_State == 1 && Relay2_isAuto == 0){ 271 | // turnRelay(1, 1); 272 | // } 273 | // if (Relay2_State == 0 && Relay2_isAuto == 0) { 274 | // turnRelay(2, 0); 275 | // } else if (Relay1_State == 1 && Relay2_isAuto == 0){ 276 | // turnRelay(2, 1); 277 | // } 278 | // if (Relay3_State == 0 && Relay3_isAuto == 0) { 279 | // turnRelay(3, 0); 280 | // } else if (Relay3_State == 1 && Relay3_isAuto == 0){ 281 | // turnRelay(3, 1); 282 | // } 283 | // if (Relay4_State == 0 && Relay4_isAuto == 0) { 284 | // turnRelay(4, 0); 285 | // } else if (Relay4_State == 1 && Relay4_isAuto == 0){ 286 | // turnRelay(4, 1); 287 | // } 288 | // if (Relay5_State == 0 && Relay5_isAuto == 0) { 289 | // turnRelay(5, 0); 290 | // } else if (Relay5_State == 1 && Relay5_isAuto == 0){ 291 | // turnRelay(5, 1); 292 | // } 293 | // if (Relay6_State == 0 && Relay6_isAuto == 0) { 294 | // turnRelay(6, 0); 295 | // } else if (Relay6_State == 1 && Relay6_isAuto == 0){ 296 | // turnRelay(6, 1); 297 | // } 298 | 299 | 300 | //EEPROM Water Pump Schedule 301 | Pump_start_hour = EEPROM.read(21); 302 | Pump_start_min = EEPROM.read(22); 303 | Pump_every_hours = EEPROM.read(23); 304 | Pump_every_mins = EEPROM.read(24); 305 | Pump_for = EEPROM.read(25); 306 | Pump_times = EEPROM.read(26); 307 | 308 | int i = 0; 309 | for(i = 0; i < 16; i++){ 310 | Pump_hour_array[i] = EEPROM.read(i+27); 311 | Pump_min_array[i] = EEPROM.read(i+43); 312 | Pump_isAM_array[i] = EEPROM.read(i+59); 313 | } 314 | 315 | //EEPROM Light Schedule 316 | Light_ON_hour = EEPROM.read(76); 317 | Light_ON_min = EEPROM.read(209); 318 | Light_OFF_hour = EEPROM.read(77); 319 | Light_OFF_min = EEPROM.read(210); 320 | 321 | //EEPROM pH1 Settings 322 | pH1Value_Low = eepromReadFloat(78); 323 | pH1Value_High = eepromReadFloat(82); 324 | 325 | //EEPROM pH2 Settings 326 | pH2Value_Low = eepromReadFloat(180); 327 | pH2Value_High = eepromReadFloat(184); 328 | 329 | //EEPROM Temp Settings 330 | TempValue_Low = eepromReadFloat(86); 331 | TempValue_High = eepromReadFloat(90); 332 | Heater_ON = eepromReadFloat(94); 333 | Heater_OFF =eepromReadFloat(98); 334 | AC_ON = eepromReadFloat(102); 335 | AC_OFF = eepromReadFloat(106); 336 | 337 | //EEPROM RH Settings 338 | RHValue_Low = eepromReadFloat(110); 339 | RHValue_High = eepromReadFloat(114); 340 | Humidifier_ON = eepromReadFloat(118); 341 | Humidifier_OFF = eepromReadFloat(122); 342 | Dehumidifier_ON = eepromReadFloat(126); 343 | Dehumidifier_OFF = eepromReadFloat(130); 344 | 345 | //EEPROM TDS1 Settings 346 | TDS1Value_Low = eepromReadFloat(134); 347 | TDS1Value_High = eepromReadFloat(139); 348 | NutePump1_ON = eepromReadFloat(144); 349 | NutePump1_OFF = eepromReadFloat(149); 350 | if (EEPROM.read(154) == 1){ 351 | MixPump1_Enabled = true; 352 | } 353 | else { 354 | MixPump1_Enabled = false; 355 | } 356 | 357 | //EEPROM TDS2 Settings 358 | TDS2Value_Low = eepromReadFloat(188); 359 | TDS2Value_High = eepromReadFloat(193); 360 | NutePump2_ON = eepromReadFloat(198); 361 | NutePump2_OFF = eepromReadFloat(203); 362 | if (EEPROM.read(208) == 1){ 363 | MixPump2_Enabled = true; 364 | } 365 | else { 366 | MixPump2_Enabled = false; 367 | } 368 | 369 | 370 | //EEPROM CO2 Settings 371 | CO2Value_Low = eepromReadFloat(155); 372 | CO2Value_High = eepromReadFloat(159); 373 | CO2_ON = eepromReadFloat(163); 374 | CO2_OFF = eepromReadFloat(167); 375 | if (EEPROM.read(171) == 1){ 376 | CO2_Enabled = true; 377 | } 378 | else { 379 | CO2_Enabled = false; 380 | } 381 | // 382 | //EEPROM Light Settings 383 | LightValue_Low = eepromReadFloat(172); 384 | LightValue_High = eepromReadFloat(176); 385 | 386 | 387 | //------------------------------------------------------------------------------ 388 | 389 | //Load default time first, then try the RTC. 390 | //Set-Time setTime(hr,min,sec,day,month,yr); 391 | setTime(0,0,0,1,1,2013); 392 | setSyncProvider(RTC.get); 393 | 394 | Serial1.begin(115200); 395 | } 396 | 397 | 398 | /* 399 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 400 | /!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!!LOOP!! 401 | /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 402 | */ 403 | void loop() 404 | { 405 | 406 | 407 | //Clear the EEPROM and then write defaults. 408 | for (int i = 0; i < 4096; i++) { 409 | EEPROM.write(i, 0); 410 | } 411 | delay(1000); 412 | 413 | RestoreDefaults(); 414 | turnRelay(1,1); 415 | delay(1000); 416 | turnRelay(1,0); 417 | //delay(30000); 418 | //delay(30000); 419 | 420 | 421 | 422 | while (1){ 423 | updatelongdate(); 424 | updateSensorValues(); 425 | serialEvent(); 426 | sendserialmessages(); 427 | CheckTimers(); 428 | serialEvent(); 429 | CheckSetPoints(); 430 | } 431 | } 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | --------------------------------------------------------------------------------