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.
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!