Temperature controller with LCD, LM35

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
}
}

Hi all
SORRY guys the code was all there and I managed to get it all working just had to re-adjust.
What I’M trying to find out is to make an adjustable hysteresis set point.
(Temperature - 1) > SetPoint)
(Temperature +1) < SetPoint)
if possible using the same 2 keys, 2 and 3 please guide me how

/*
   EJHG. Artois 
   Digital Temperature Controller
       20161217
  With thanks to "(circuits4you.com) for the basic project code and
  ALL The Arduino Forum Team Mwmbers with their help.     
*/

#include <LiquidCrystal.h>
#include <InputDebounce.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
const int temp_sensor = A0;      // Lm 35DT Temperature sensor
const int up_key = 2;            // adjust up key
const int down_key = 3;          // adjust down key
int Vin = A0;                    // Variable to read the value from Pin A0
float Temperature;   // variable that receives the converted voltage
int SetPoint = 25;   // Start-up,setpoint adjustable with push keys 2 and 3

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);                     // 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(2000);
}

void loop() {

  Vin = analogRead(0);    //Tell the Arduino to read the voltage on pin A0
  Temperature = (5.0 * Vin) * 93.10 / 1024; // Convert read value into a voltage
  delay(200);
  lcd.setCursor(0, 0);                   // Move coursor to first Line
  lcd.print("Temperature:");             // Print a message to the LCD.
  lcd.print(Temperature);

  if (digitalRead(down_key) == LOW)   // Get input for setpoint
  {
    if (SetPoint > -8)
    {
      SetPoint--;
    }
  }
  if (digitalRead(up_key) == LOW)     // Get input for setpoint
  {
    if (SetPoint < 40)
    {
      SetPoint++;
    }
  }
  lcd.setCursor(0, 1);
  lcd.print("Set Point:");           // Display Set point on LCD
  lcd.print(SetPoint);
  lcd.print(" Cel");                 // Display degree celcius

  if ((Temperature - 1) > 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 + 1) < SetPoint)  //Check Temperature is in + limit
  {
    digitalWrite(RELAY, HIGH);      // Turn on fan
    digitalWrite(LED_RED, HIGH);    // Turn on RED LED
    digitalWrite(LED_GREEN, LOW);   // Turn off Green Led
   
  if (Temperature > 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
    } else {
      digitalWrite(RELAY, HIGH);     // Turn on fan
      digitalWrite(LED_RED, HIGH);   // Turn on RED LED
      digitalWrite(LED_GREEN, LOW);  // Turn off Green Led
    }
  }
}

Hi again
I’m trying to complete my project can someone please tell where i’m going wrong in the following piece of my sketch please I need help.
What i"m trying to do:

// If fridge reaches setpoint temperature
// fridge relay = LOW
// start 3 minute delay (fridge compressor to cool)
// 3 minute delay over complete
// check temperature
// If temperature above setpoint
// fridge relay HIGH
// else
// keep fridge relay LOW

unsigned long currentMillis = millis();
int FridgeRightTime = millis();
if (Temperature < SetPoint)
digitalWrite(Relay, LOW);
FridgeRightTime = millis();
if (Temperature > SetPoint)
FridgeRightTime < (1 * 60 * 100);
digitalWrite(Relay, HIGH);
} else {
digitalWrite(Relay, LOW);

Please read the "How to use this forum" post and follow the directions. Post your code properly, using code tags -- ALL of it, not just fragments.

H
The complete code

[code]
/*
   EJHG. Artois
   Digital Temperature Controller
       20161217
  With thanks to "(circuits4you.com) for the basic project code and
  ALL The Arduino Forum Team Mwmbers with their help.
*/

#include <LiquidCrystal.h>
#include <InputDebounce.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 fridge relay (yellow led)
const int Temp_Sensor = A0;      // Lm 35DT Temperature sensor
const int Up_Key = 2;            // adjust up key
const int Down_Key = 3;          // adjust down key

int Vin = A0;                    // Variable to read the value from Pin A0
float Temperature;    // variable that receives the converted voltage
int SetPoint = 25;    // Start-up,setpoint adjustable with push keys 2 and 3
int RelayState = LOW;            // state of the fridge relay (yellow Led)
int FridgeRightTime = millis();

void setup() {

  pinMode(Led_Red, OUTPUT);
  pinMode(Led_Green, OUTPUT);
  pinMode(Relay, OUTPUT);              // test with yellow led
  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);                     // 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 fridge relay (yellow led)
  delay(2000);
}

void loop() {

  Vin = analogRead(0);    //Tell the Arduino to read the voltage on pin A0
  Temperature = (5.0 * Vin) * 93.10 / 1024; // Convert read value into a voltage
  delay(200);
  lcd.setCursor(0, 0);                 // Move coursor to first Line
  lcd.print("Temperature:");           // Print a message to the LCD.
  lcd.print(Temperature);

  if (digitalRead(Down_Key) == LOW)   // Get input for setpoint
  {
    if (SetPoint > -8)                // value to set temperatue
    {
      SetPoint--;                     // set, set point value higher than -8 deg
    }
  }
  if (digitalRead(Up_Key) == LOW)     // Get input for setpoint
  {
    if (SetPoint < 40)                // value to set temperature
    {
      SetPoint++;                     // set, set point value lower than 40 deg
    }
  }
  lcd.setCursor(0, 1);
  lcd.print("Set Point:");            // Display Set point on LCD
  lcd.print(SetPoint);
  lcd.print(" Cel");                  // Display degree celcius

  if ((Temperature - 0.5) > SetPoint)   // Check Temperature is in - limit
  {
    digitalWrite(Relay, LOW);         // Turn off fridge relay (yellow led)
    digitalWrite(Led_Red, LOW);       // Turn off Red led
    digitalWrite(Led_Green, HIGH);    // Turn on Green LED
  }
  if ((Temperature + 0.5) < SetPoint)   //Check Temperature is in + limit
  {
    digitalWrite(Relay, HIGH);        // Turn on fridge relay (yellow led)
    digitalWrite(Led_Red, HIGH);      // Turn on RED LED
    digitalWrite(Led_Green, LOW);     // Turn off Green Led

    if (Temperature > SetPoint)       // Check Temperature is in limit
    {
      digitalWrite(Relay, LOW);       // Turn off fridge relay (yellow Led)
      digitalWrite(Led_Red, LOW);     // turn off Red Led
      digitalWrite(Led_Green, HIGH);  // Turn on Green LED
    } else {
      digitalWrite(Relay, HIGH);      // Turn on fridge relay (yellow Led)
      digitalWrite(Led_Red, HIGH);    // Turn on Red Led
      digitalWrite(Led_Green, LOW);   // Turn off Green Led
    }
    unsigned long currentMillis = millis();
    int FridgeRightTime = millis();
    if (Temperature < SetPoint)
      digitalWrite(Relay, LOW);
    FridgeRightTime = millis();
    if (Temperature > SetPoint)
      FridgeRightTime < (1 * 60 * 100);
    digitalWrite(Relay, HIGH);
  } else {
    digitalWrite(Relay, LOW);

    // If fridge reaches setpoint temperature
    // fridge relay = LOW
    // start 3 minute delay (fridge compressor to cool)
    // 3 minute delay over complete
    // check temperature
    // If temperature above setpoint
    // fridge relay HIGH
    // else
    // keep fridge relay LOW
  }
}

[/code]

The instructions also tell you to clearly and carefully describe what you want the program to do, and what the program does instead.

However, your main problem is that you are trying to run before you’ve learned to crawl.

We recommend going through the examples that come with the Arduino development software, so that you understand the programming language and the special features of the Arduino environment.

Hi j
The previous post clearly shows what i'm trying to do, and what I wrote clearly explains in the // ..// what I would like it to do. All i'm asking is to show me why I'm doing wrong and how to rectify what is wrong, with maybe an explanation if you have the time. I have downloaded multiple E- books and gone through them and find ,bet i'm not the only person to find the millis () a difficult thing to grasp. Suppose it's a piece of cake once you have grasped it. So if someone can show me to a descent tutorial site I would be ever so grateful. All the tutorials on the arduino pages are all stupid blinking leds, even in the E-books.

Hi,

I am a little reticent about making posts on this forum as it isn't that easy to know where to post questions in the right place without being told off about it, so normally I don't bother, but on this occasion because I am doing a very similar thing I thought i'd try and help (for what it's worth) the best I can.
Could I also say to ('experienced old hands') it's unhelpful to make comments that undermine people who are new to this subject, and ultimately dissuade them from continuing.
The Arduino platform is sold on the sales mantra of 'fun and educational', but sometimes (now and then) it doesn't seem quite like that.
I know your post is getting on a bit now, (there's a warning message at the top of the the message box warning me about it) but just for the record here's my thoughts about it,

I too am a beginner and I also downloaded the code to make a controller for a hot water bath,
and basically it works the way I want it, however I did modify the hysteresis function a little, if you want my modified code i'll post it if you like.

Anyway could I recommend that you (respectfully) learn some C++, there's a great document free to download by an American gentleman named Richard L. Halterman, google it you should find it, the first part is an excellent tutorial on the basics of C++(as I see it Arduino is essentially C++) and is an enlightening read, however as you progress it does get to be heavy going,
I've been studying this document for some 2 years now and am just starting to get to get to grips with the OOP structure.
Not massively helpful I know but I've read this document and it's given me a great insight to the Arduino platform programming language
Regards

You have copy/paste the code without understanding what it does. Forums are problem solving platforms and not meant for spoon feeding. First learn language basics, platform basics, OS, data structures, Algorithm, OOPS, etc.... before writing real code.