I've been working on a pretty simple sketch to control the temperature of my kegerator.
The program works well for the first 24 hours or so, but after that the program seems to freeze.
Not sure what I am doing wrong but I am sure its something obvious, I just cant see it.
Thank in advance for the help!
/**
*/
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 for a 16 chars and 2 line display
DallasTemperature sensors(&oneWire);
int potPin1 = A1; //set pot to pin A1
int Comp=7; //Compressor pin
float SetTemp;
float SetTempPrint1;
float val;
float Celcius=0;
float Fahrenheit=0;
void setup()
{
Serial.begin(9600);
lcd.begin();
lcd.backlight();
lcd.clear();
sensors.begin();
pinMode(potPin1, INPUT);
pinMode(Comp,OUTPUT);
}
void loop()
{
val = analogRead(potPin1);
SetTemp = map(val, 0, 1023, 280, 500);
float SetTempPrint = (SetTemp/10);
sensors.requestTemperatures(); // Send the command to get temperature readings
Celcius=sensors.getTempCByIndex(0);
Fahrenheit=sensors.toFahrenheit(Celcius);
SetTempPrint1 = SetTempPrint + 2;
lcd.setCursor(0,0); // Sets the cursor to col 0 and row 0
lcd.print(F("ST:")); // Prints Sensor Val: to LCD
lcd.print(SetTempPrint, 1); // Prints value on Potpin1 to LCD
lcd.print((char)223);
lcd.print(F("F"));
lcd.setCursor(0,1);
lcd.print(F("AT:"));
lcd.print(Fahrenheit, 1); // Why "byIndex"?
lcd.print((char)223);
lcd.print(F("F"));
if(SetTempPrint1<Fahrenheit){ //lighting up the Comp
do {
digitalWrite(Comp,HIGH);
lcd.setCursor(14,0);
lcd.print(F(" "));
lcd.setCursor(13,0); // Sets the cursor to col 0 and row 0
lcd.print(F("ON"));
val = analogRead(potPin1);
SetTemp = map(val, 0, 1023, 280, 500);
SetTempPrint = (SetTemp/10);
sensors.requestTemperatures(); // Send the command to get temperature readings
Celcius=sensors.getTempCByIndex(0);
Fahrenheit=sensors.toFahrenheit(Celcius);
SetTempPrint1 = SetTempPrint + 2;
// statement block
lcd.setCursor(0,0); // Sets the cursor to col 0 and row 0
lcd.print(F("ST:")); // Prints Sensor Val: to LCD
lcd.print(SetTempPrint, 1); // Prints value on Potpin1 to LCD
lcd.print((char)223);
lcd.print(F("F"));
lcd.setCursor(0,1);
lcd.print(F("AT:"));
lcd.print(Fahrenheit, 1); // Why "byIndex"?
lcd.print((char)223);
lcd.print(F("F"));
delay(500);
} while (SetTempPrint<Fahrenheit);
}
else
digitalWrite(Comp,LOW);
lcd.setCursor(13,0); // Sets the cursor to col 0 and row 0
lcd.print(F("OFF"));
delay(500);
}