Hi Guys
I had this post similar previously in the design section but got no help.
please I am quite new so be patient. I did the control unit as in
circuits4you.com arduino temperature controller
I basically just copied and pasted the code and now I’m trying to add set points with 2 push buttons and add a hysteresis. I have looked every post, tutorial etc and cannot find any help to carry on.
Please look at the code and let me know.
/*
Digital Temperature Controller
*/
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(9, 8, 7, 6, 5, 4);
const int LED_RED = 10; // Red LED
const int LED_GREEN = 11; // Green LED
const int RELAY = 12; // 220v 10amp fan relay
//Key connections with arduino
const int up_key = 3; // up key
const int down_key = 2; // down key
int SetPoint = 30;
void setup() {
pinMode(LED_RED, OUTPUT);
pinMode(LED_GREEN, OUTPUT);
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
lcd.begin(16, 2); // set up the LCD’s number of columns and rows:
lcd.print(“EJHG. Artois.”); // Print a message to the LCD.
lcd.setCursor(0, 1); // Move coursor to second Line
lcd.print(“Temp. Controller”); // Print a message to the LCD.
digitalWrite(LED_GREEN, HIGH); // Green LED Off
digitalWrite(LED_RED, LOW); // Red LED On
digitalWrite(RELAY, LOW); // Turn off fan relay
delay(5000);
}
void loop() {
double Temperature = ((4.6 / 1024.0) * analogRead(A0)) * 100; //10mV per degree 0.01V/C.
lcd.setCursor(0, 0);
lcd.print(“Temperature:”);
lcd.print(Temperature);
//Get user input for setpoints
if (digitalRead(down_key) == LOW)
{
if (SetPoint > 0)
{
SetPoint–;
}
}
if (digitalRead(up_key) == LOW)
{
if (SetPoint < 150)
{
SetPoint++;
}
}
lcd.setCursor(0, 1);
lcd.print(“Set Point:”); //Display Set point on LCD
lcd.print(SetPoint);
lcd.print(" Cel");
if (Temperature > SetPoint) //Check Temperature is in limit
{
digitalWrite(RELAY, LOW); // Turn off fan
digitalWrite(LED_RED, LOW);
digitalWrite(LED_GREEN, HIGH); // Turn on Green LED
}
else
{
digitalWrite(RELAY, HIGH); // Turn on fan
digitalWrite(LED_GREEN, LOW); // Turn off Green Led
digitalWrite(LED_RED, HIGH); // Turn on RED LED
}
delay(500); //Update at every 500mSeconds
if ((Temperature - 2) > SetPoint) //Check Temperature is in limit
{
digitalWrite(RELAY, LOW); // Turn off fan
digitalWrite(LED_RED, LOW); // Turn off RED LED
digitalWrite(LED_GREEN, HIGH); // Turn on Green LED
}
if ((Temperature + 2) < SetPoint)
{
digitalWrite(RELAY, HIGH); // Turn on fan
digitalWrite(LED_GREEN, LOW); //Turn off Green LED
digitalWrite(LED_RED, HIGH); // Turn on RED LED
}
}