My temps are fluctuating from ~40F to ~110F.
Please help!
here is my sketch...
#include <LiquidCrystal.h>
#include <Wire.h>
#include <RealTimeClockDS1307.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//RS, E, D4, D5, D6, D7
#define DS3231_I2C_ADDRESS 0x68
byte decToBcd(byte val)// Convert normal decimal numbers to binary coded decimal
{
return( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val)// Convert binary coded decimal to normal decimal numbers
{
return( (val/16*10) + (val%16) );
}
#define Display_Clock_Every_N_Seconds 10
#define Display_ShortHelp_Every_N_Seconds 60
String tz;
int hours = 0;
int minutes = 0;
int seconds = 0;
int dates = 0;
int months = 0;
int years = 0;
int ap = 0;
int RelayL = 8;//Relay Large Tank
int RelayS = 9;//Relay Small Tank
float temp;
float tempC;
//int tempMax = 37.78;// 100F
float tempF;
const int HTempSensorPin0 = 0;// A0 Hot Side Large Tank
const int HTempSensorPin1 = 1;// A1 Hot Side Small Tank
const int CTempSensorPin2 = 2;// A2 Cold Side Large Tank
const int CTempSensorPin3 = 3;// A3 Cold Side Small Tank
void setup()
{
Wire.begin();
// set the initial time here:
//DS3231 seconds, minutes, hours, day, date, month, year;
//setDS3231time(30,33,20,5,05,11,15);
Serial.begin(9600);
pinMode(RelayL,OUTPUT);
pinMode(RelayS,OUTPUT);
lcd.begin(20, 4);
lcd.setCursor(3, 1);
lcd.print("Loading Temps");
lcd.setCursor(4, 2);
lcd.print("Please Wait");
{
delay(700);
}
{
lcd.clear();
}
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
// sets time and date data to DS3231
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set next input to start at the seconds register
Wire.write(decToBcd(second)); // set seconds
Wire.write(decToBcd(minute)); // set minutes
Wire.write(decToBcd(hour)); // set hours
Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
Wire.write(decToBcd(month)); // set month
Wire.write(decToBcd(year)); // set year (0 to 99)
Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set DS3231 register pointer to 00h
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
// request seven bytes of data from DS3231 starting from register 00h
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
void loop()
{
{
RTC.readClock();
if(ap == 1)
{
tz = "PM";
}
else
{
tz ="AM";
}
lcd.home();
hours = RTC.getHours();
minutes = RTC.getMinutes();
seconds = RTC.getSeconds();
ap = RTC.isPM();
dates = RTC.getDate();
months = RTC.getMonth();
years = RTC.getYear();
lcd.setCursor(0, 3);
if (hours >12)
{
hours -= 12;
tz = "PM";
}
else
tz = "AM";
lcd.print(hours);
lcd.print(":");
lcd.print(minutes);
//lcd.print(":");
//lcd.print(seconds);
lcd.print(" ");
lcd.setCursor(5, 3);
lcd.print(tz);
lcd.setCursor(13, 3);
lcd.print(months);
lcd.print("/");
lcd.print(dates);
lcd.print("/");
lcd.print(years);
delay(1);
}
int value = analogRead(HTempSensorPin0);// Read Sensor
float millivolts = (value / 1024.0) * 5000;// Convert Reading to Millivolts
float celsius = millivolts / 10;//Convert Millivolts to Celsius //9.31 - 10 - 12?
lcd.setCursor(2, 1);
lcd.print((celsius * 9) / 5 + 32);//Convert Celsius To Fahrenheit
lcd.print("F");//Fahrenheit
lcd.setCursor(0, 0);
lcd.print("LG Tank");
lcd.setCursor(0, 1);
lcd.print("H");//Hot
if (celsius >37.78)//100F
{
digitalWrite(8,LOW);
}
if (celsius <31.11)//88F
{
digitalWrite(8,HIGH);
}
{
int value = analogRead(HTempSensorPin1);// Read Sensor
float millivolts = (value / 1024.0) * 5000;// Convert Reading to Millivolts
float celsius = millivolts / 10;//Convert Millivolts to Celsius //9.31 - 10 - 12?
lcd.setCursor(14, 1);
lcd.print((celsius * 9) / 5 + 32);//Convert Celsius To Fahrenheit
lcd.print("F");//Fahrenheit
lcd.setCursor(13, 0);
lcd.print("SM Tank");
lcd.setCursor(12, 1);
lcd.print("H");//Hot
if (celsius >37.78)//100F
{
digitalWrite(9,LOW);
}
if (celsius <31.11)//88F
{
digitalWrite(9,HIGH);
}
{
int value = analogRead(CTempSensorPin2);// Read Sensor
float millivolts = (value / 1024.0) * 5000;// Convert Reading to Millivolts
float celsius = millivolts / 10;//Convert Millivolts to Celsius //9.31 - 10 - 12?
lcd.setCursor(2, 2);
lcd.print((celsius * 9) / 5 + 32);//Convert Celsius To Fahrenheit
lcd.print("F");//Fahrenheit
lcd.setCursor(0, 0);
lcd.print("LG Tank");
lcd.setCursor(0, 2);
lcd.print("C");//Cold
{
int value = analogRead(CTempSensorPin3);// Read Sensor
float millivolts = (value / 1024.0) * 5000;// Convert Reading to Millivolts
float celsius = millivolts / 10;//Convert Millivolts to Celsius //9.31 - 10 - 12?
lcd.setCursor(14, 2);
lcd.print((celsius * 9) / 5 + 32);//Convert Celsius To Fahrenheit
lcd.print("F");//Fahrenheit
lcd.setCursor(13, 0);
lcd.print("SM Tank");
lcd.setCursor(12, 2);
lcd.print("C");//Cold
{
delay(1000);//Delay Before Next Temp Reading
}
}
}
}
}