Problem with Input for an electric furnace using the keypad!

Hello, I have this project which is basically an electric furnace with user controls via a keypad, buttons, and an arduino. I use 4 buttons to input the mode of the furnace, which consists of a "Start", "Stop", "Reflow", and "Heat Treatment" button, now what I intend to happen is that the keypad should only work during the heat treatment so I can use it to input a set temperature, as for the reflow it should already have a setpoint.

Now my problem is the codes for my heating loop does not work, I can't seem to set my temperature, I can input the value and the LCD will display it but it seems that my value only works for that specific loop, which is not ideal because I intend to use it as my reference temperature for the duration of the heating. :confused:

Here are my codes for the project:

#include <LiquidCrystal.h>
#include <Keypad.h>

long set_temp;
long soaking_time;
int time1 = millis()/1000;
int time2 = 0;
int time3 = 0;
int firstreading;
int startPin;

LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
char customKey;
const byte ROWS = 4; //four rows
const byte COLS = 3; //four columns
//define the cymbols on the buttons of the keypads
char keys [ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#',}
};
byte rowPins[ROWS] = {35, 41, 39, 37}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {36, 34, 38}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); 


void setup()
{
  Serial.begin(9600);
  pinMode(9, OUTPUT);
  startPin = 23;
  pinMode(startPin, INPUT_PULLUP);   
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Set Temp:");
  lcd.setCursor(0,1);
  lcd.print("Set Time:");  
  if (time1 == 0)
  {
    firstreading = analogRead(A0);
    Serial.print("first reading: ");
    Serial.println(firstreading);
  }
}

void(* resetFunc) (void) = 0;
void loop()
{   
 customKey = customKeypad.getKey();
 switch(customKey) 
 {
    
 case '0' ... '9': // This keeps collecting the first value until a operator is pressed "+-*/"
 lcd.setCursor(10,0);
 set_temp = set_temp * 10 + (customKey - '0');
 lcd.print(set_temp);
 break;

 case '#':
 if (set_temp > 1000)
 {
   set_temp = firstreading;
   Serial.print("Set temp :   ");
   Serial.println("ERROR");
   lcd.setCursor(10,0);
   lcd.print("ERROR");
  }
  else if (set_temp < 100 )
  {
    set_temp = firstreading;
    Serial.print("Set temp :   ");
    Serial.println("ERROR");
    lcd.setCursor(10,0);
    lcd.print("ERROR");
   }
   else
   {
    Serial.print("Set temp :   ");
    Serial.println(set_temp);
    lcd.setCursor(10,0);    
    lcd.print(set_temp);
   }
    soaking_time = SecondNumber(); // get the collected the second number
    set_temp = 0, soaking_time = 0; // reset values back to zero for next use
    break;

  case '*':
    resetFunc();
    break;
  }
}
long SecondNumber()
{
  while( 1 )
  {
    customKey = customKeypad.getKey();
    if(customKey >= '0' && customKey <= '9')
    {
      soaking_time = soaking_time * 10 + (customKey - '0');
      
      lcd.setCursor(10,1);
      lcd.print(soaking_time);
    }
    
    if(customKey == '#') 
    break;  //return second;


    if(customKey == '*')
    {
    resetFunc();
    break;
    }
  }
  if (soaking_time > 120)
    {
      soaking_time = 0;
      Serial.print("Soaking Time :   ");
      Serial.println("ERROR");
      lcd.setCursor(10,1);
      lcd.print("ERROR");
    }
    else if (soaking_time < 5 )
    {
      soaking_time = 0;
      Serial.print("Soaking Time :   ");
      Serial.println("ERROR");
      lcd.setCursor(10,1);
      lcd.print("ERROR");
    }
    else
    {
    Serial.print("Soaking Time :   ");
    Serial.println(soaking_time);
    lcd.setCursor(10,1);    
    lcd.print(soaking_time);
    }
 return soaking_time;
 
 if (digitalRead(startPin) == HIGH)
 {
   heating(); 
 }
 
}

void heating()
{
  int sensorValue = analogRead(A0); 
   if  (sensorValue <= set_temp)
   {
   time3++;
   Serial.print("time3: ");
   Serial.println(time3);
     if  (sensorValue < 2*time3 + firstreading)
     {
     digitalWrite(9, HIGH); 
     Serial.print("reqd_reading:  ");
     Serial.println(2*time3 + firstreading);
     }    
   }  
   else if (sensorValue > set_temp)
   {
   time2++; 
   Serial.print("time2: ");
   Serial.println(time2);
   if (sensorValue > 802)
    {
      digitalWrite(13, LOW);
    }
    else if(sensorValue < 798)
    {
      digitalWrite(13, HIGH);
    }
   } 
   
  Serial.print("sensorValue: ");
  Serial.println(sensorValue);
  delay(1000);        // delay in between reads for stability
}

Help would be appreciated, Cheers!

 case '#':
   {
    Serial.print("Set temp :   ");
    Serial.println(set_temp);
    lcd.setCursor(10,0);    
    lcd.print(set_temp);
   }
    soaking_time = SecondNumber(); // get the collected the second number
    set_temp = 0, soaking_time = 0; // reset values back to zero for next use
    break;

When someone presses '#' you display set_temp, gather soaking_time, and then set both to zero?!?

Yes, I put it in there for resetting the input back to zero for the next time it will be used without having to turn it off. The '#' is basically used as an erase key, but it seems that it does not reset my input the way I intended, since the values don't reset?

Shouldn't you store the values somewhere before you erase them? How is the heater going to know the set_temp
and soaking_time if you erase them as soon as you set them?

I'm actually having trouble with storing the values? What would you recommend? Sorry I'm pretty new to this.

iSEYA:
I'm actually having trouble with storing the values? What would you recommend? Sorry I'm pretty new to this.

Just copy the values to variables that you are NOT going to immediately set to zero.

I need to be able to store my input values (set_temp) in the loop for use as the set-point? I need to use those values later in the program? Will I have to set them to a new variable before using them in the loop? How do I go about copying them? The setting to zero is only used as a reset function actually for next use.

iSEYA:
Yes, I put it in there for resetting the input back to zero for the next time it will be used without having to turn it off. The '#' is basically used as an ENTER key, but it seems that it does not reset my input the way I intended, since the values don't reset?

EDIT: Sorry I meant enter key.

I've also tried this new approach, the values have been set but it no longer loops only showing once?

#include <LiquidCrystal.h>
#include <Keypad.h>

int set_temp;
int soaking_time;
int time1 = millis()/1000;
int time2 = 0;
int time3 = 0;
int firstreading;
const byte ROWS = 4;
const byte COLS = 3;
const byte ssrPin = 13;

char keys[ROWS][COLS] = {                    
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

byte rowPins[ROWS] = {35, 41, 39, 37}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {36, 34, 38}; //connect to the column pinouts of the keypad
 
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); 
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);

void setup()
{
  Serial.begin(9600);
  pinMode(ssrPin, OUTPUT);
  digitalWrite(ssrPin, LOW);                     
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Set Temp:");
  lcd.setCursor(0,1);
  lcd.print("Set Time:");
  if (time1 == 0)
  {
    firstreading = analogRead(A0);
    Serial.print("first reading: ");
    Serial.println(firstreading);
  }
}
void(* resetFunc) (void) = 0;

int GetNumber()
{
   int num = 0;
   char key = kpd.getKey();
   while(key != '#')
   {
      switch (key)
      {
         case '0': case '1': case '2': case '3': case '4':
         case '5': case '6': case '7': case '8': case '9':
            lcd.setCursor(10,0);
            num = num * 10 + (key - '0');
            lcd.print(num);
            break;

         case '*':
            num = 0;
            resetFunc();
            break;
      }

      key = kpd.getKey();
   }

   return num;
}

int GetNumber2()
{
   int num2 = 0;
   char key1 = kpd.getKey();
   while(key1 != '#')
   {
      switch (key1)
      {
         case '0': case '1': case '2': case '3': case '4':
         case '5': case '6': case '7': case '8': case '9':
            lcd.setCursor(10,1);
            num2 = num2 * 10 + (key1 - '0');
            lcd.print(num2);
            break;

         case '*':
            num2 = 0;
            resetFunc();
            break;
      }

      key1 = kpd.getKey();
   }

   return num2;
}

void loop()
{
   set_temp = GetNumber();
   soaking_time = GetNumber2();
   int sensorValue = analogRead(A0); 
   
Serial.print("set_temp: ");
Serial.println (set_temp);
Serial.print("soaking time: ");
Serial.println (soaking_time);

Serial.print("sensor:  ");
Serial.println(sensorValue);
delay(1000);  


if(sensorValue <= set_temp)
{    
  time2++;
  Serial.print("time2: ");
  Serial.println(time2);
  if(sensorValue >= firstreading + 2 * time2)
  {
    digitalWrite(ssrPin, LOW);  
    Serial.print("reqd_reading:  ");
    Serial.println(firstreading + 2 * time2);
  }
  else if(sensorValue < firstreading + 2 * time2)
  {
    digitalWrite(ssrPin, HIGH);        
    Serial.print("reqd_reading:  ");
    Serial.println(firstreading + 2 * time2);
  }
}
else if(sensorValue > set_temp)
{
  time3++;
  Serial.print("time3: ");
  Serial.println(time3);
  if (time3++ < soaking_time)
  {
    if(sensorValue > set_temp + 2)
    {
      digitalWrite(ssrPin, LOW);    
    }
    else if(sensorValue < set_temp)
    {
      digitalWrite(ssrPin, HIGH);    
    }    
    Serial.print("current temp:  ");
    Serial.println(sensorValue); 
   }
   else if (time3++ >= soaking_time)
   {
    digitalWrite(ssrPin, LOW);   
   }
}
}