I'm having a lot of trouble controlling the relays based on time and temperature. from 8AM to 8PM I want the temp around 90F, turn light off at 92F and back on at 88F. From 8PM to 8AM I want the temp around 80F, turn the light off at 82F and back on at 78F.
I'm using a Arduino Mega 2560, Ethernet shield, 4X20 LCD screen DC3231 RTC, (4X) 10K Thermistors and (2X) relays. LCD connections RS-D12,E-11, D4-D5,D5-D4,D6-D3,D7-D2. thermistors connections A4,A5,A6,A7. RCT connections SDA-SDA D20, SCL-SCL D21. relay connections D8,D9.
code first half..
#include <math.h>
#include <Wire.h>
#include <DS3232RTC.h>
#include <Time.h>
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Arduino.h>
#define HR1224 6
#define DS3232RTC.h
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte mac[] =
{
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
EthernetServer server(80);
int RelayL = 8;//Relay Large Tank
int RelayS = 9;//Relay Small Tank
const int HTempSensorPin0 = 4;// A4 Hot Side Large Tank
const int CTempSensorPin2 = 6;// A6 Cold Side Large Tank
const int HTempSensorPin1 = 5;// A5 Hot Side Small Tank
const int CTempSensorPin3 = 7;// A7 Cold Side Small Tank
int hourFormat12();
int day();
int month();
int year();
double mytempC4;
double mytempF4;
double mytempC6;
double mytempF6;
double mytempC5;
double mytempF5;
double mytempC7;
double mytempF7;
void setup()
{
Serial.begin(9600);
while (!Serial)
{
;
}
SPI.begin();
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
pinMode(RelayL,OUTPUT);
pinMode(RelayS,OUTPUT);
digitalWrite(RelayL,LOW);
digitalWrite(RelayS,LOW);
lcd.begin(20, 4);
lcd.setCursor(4, 1);
lcd.print("Loading...");
lcd.setCursor(4, 2);
lcd.print("Please Wait");
{
delay(1000);
}
{
setSyncProvider(RTC.get);
if (timeStatus() != timeSet)
Serial.println("Unable to Sync with RTC");
else
Serial.println("RTC has set the system time");
}
{
lcd.clear();
}
lcd.begin(20, 4);
lcd.setCursor(4,0);
lcd.print("Temps loaded");
lcd.setCursor(0,1);
if (timeStatus() != timeSet)
lcd.print("Unable to Sync with RTC");
else
lcd.print("RTC set system time");
lcd.setCursor(7, 2);
lcd.print("Done");
{
delay(700);
}
{
lcd.clear();
}
}
double Thermister(int RawADC)
{
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 273.15;
return Temp;
}
byte countr = 1;
void loop()
{
{
EthernetClient client = server.available();
if (client)
{
Serial.println("new client");
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
Serial.write(c);
if (c == '\n' && currentLineIsBlank)
{
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 5");
client.println();
client.println("<!DOCTYPE HTML>\n");
client.println("<html>\n");
mytempC4 = Thermister(analogRead(4));
mytempF4 = (mytempC4 * 1.8) + 32.0;
mytempC6 = Thermister(analogRead(6));
mytempF6 = (mytempC6 * 1.8) + 32.0;
mytempC5 = Thermister(analogRead(5));
mytempF5 = (mytempC5 * 1.8) + 32.0;
mytempC7 = Thermister(analogRead(7));
mytempF7 = (mytempC7 * 1.8) + 32.0;
client.println("<head>");
client.println("Snake Temps");
client.println("</head>");
client.println("<title>");
client.println("Snake Temps");
client.println("</title>");
client.println("<body bgcolor=black>");
client.println("<font color=white>");
client.println("<meta http-equiv=\"refresh\" content=\"5\">");
client.println("<center>");
client.println("<b>");
client.println("<td align=center>");
client.println("<font color = blue size = 15>");
client.println("Snake Temps");
client.println("
");
client.println("<table>");
client.println("<td align=center>");
client.println("<font color = blue size = 5>");
client.println(hourFormat12());
client.print(':');
client.print(minute());
client.print(' ');
if (isAM())
{
client.print("AM");
}
if (isPM())
{
client.print("PM");
}
client.print(' ');
client.print(month());
client.print('/');
client.print(day());
client.print('/');
client.print(year());
client.print(' ');
client.println("<table>");
client.println("<td align=left>");
client.println("<font color = white size = 4>");
client.println("
");
client.println(" Large Tank,");
client.println("
");
client.println("Hot Side:");
client.print(mytempC4);
client.print("C ");
client.print(' ');
client.print("- ");
client.print(' ');
client.print(mytempF4);
client.print("F ");
client.println("
");
client.print("Cold Side:");
client.print(mytempC6);
client.print("C ");
client.print(' ');
client.print("- ");
client.print(' ');
client.print(mytempF6);
client.print("F ");
client.println("<table>");
client.println("<td align=left>");
client.println("<font color = white size = 4>");
client.println("
");
client.println(" Small Tank,");
client.println("
");
client.println("Hot Side:");
client.print(mytempC5);
client.print("C ");
client.print(' ');
client.print("- ");
client.print(' ');
client.print(mytempF5);
client.print("F ");
client.println("
");
client.print("Cold Side:");
client.print(mytempC7);
client.print("C ");
client.print(' ');
client.print("- ");
client.print(' ');
client.print(mytempF7);
client.print("F ");
client.println("");
client.println("</td>");
client.println("</tr>");
client.println("</table>");
client.println("<p>");
client.println("<FORM>");
client.println("<INPUT type=button value=Refresh onClick=window.location='/?reconnect\'>");
client.println("</FORM>");
client.println("<FORM>");
client.println("</html>");
break;
}
if (c == '\n')
{
currentLineIsBlank = true;
}
else if (c != '\r')
{
currentLineIsBlank = false;
}
}