// This is very much a work in progress by a clueless amateur so please disregard all the errors!
// Purpose is to activate a cooling circuit via relay when the temp gets hotter than target
//
#include <LiquidCrystal_I2C.h>
int reading = 0;
int sensorPin = A0;
int relay =7;
const int up_key = 10;
const int down_key = 9;
int SetPoint = 30; // Start-up setpoint - adjustable with push keys
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
//
lcd.init(); // initialize the lcd
lcd.backlight(); // open the backlight
//
pinMode(relay,OUTPUT);
pinMode(up_key, INPUT);
pinMode(down_key, INPUT);
digitalWrite(up_key, HIGH); // Pull up for setpoint button
digitalWrite(down_key, HIGH); // Pull up for setpoint button
pinMode(13, OUTPUT); // LED output
}
void loop() {
reading = analogRead(sensorPin);
int celsius = reading/2;
lcd.setCursor(0, 0); // Setting cursor position to row 1 char 1
lcd.print("Spa Temp: ");
//lcd.setCursor(0,1);
lcd.print((celsius/10), DEC); // Creating a plausible value from the potentiometer in place of a temp sensor..
lcd.print((char)223); // the degree symbol
lcd.print("C");
if ((celsius/10) > SetPoint)
{
digitalWrite(7,HIGH); // Relay output if temp is over setpoint
digitalWrite(13, HIGH); // LED output for same
}
else
{digitalWrite(7,LOW); // Relay output if temp is under setpoint
digitalWrite(13, LOW); // LED output for same
}
//
if (digitalRead(up_key) == LOW) // "Up" input for setpoint
{
if (SetPoint < 40)
{
SetPoint++;
}
}
if (digitalRead(down_key) == LOW) // "Down" input for setpoint
{
if (SetPoint > 20)
{
SetPoint--;
}
}
lcd.setCursor(0, 1); // Set cursor position
lcd.print("Target: "); // Display Set point on LCD
lcd.print(SetPoint);
lcd.print((char)223);
lcd.print("C");
delay(400);
// lcd.clear();
}