Hi all,
My heater is a coil from a heat gun, I dont know if it makes it easy to understand.
Yes, of course I could switch on and off to keep it at certain temperature. What I understood of his comment was to leave it on for 4 min.
This is my code so far:
int outputpin = 0; //Analog 0
float temp;
float tempMin = 0;
float tempMax = 0;
#define RELAY1 8
void setup() {
Serial.begin(115200);
pinMode(0, OUTPUT);
pinMode(8, OUTPUT);
tempMin = readTemp();
tempMax = tempMin + 20.0;
Serial.print("this is tempMin: ");
Serial.println(tempMin);
Serial.print("this is tempMax: ");
Serial.println(tempMax);
// initialize the LED pins 2, 3, 4, 5:
for (int thisPin = 2; thisPin < 7; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}
void loop() {
temp = readTemp();
Serial.print("TEMP=");
Serial.print(temp);
Serial.println();
if((temp >= tempMin)&&(temp<tempMin+5)){ //1
digitalWrite(RELAY1, HIGH);
digitalWrite(2, HIGH);
delay (500);
digitalWrite(RELAY1, LOW);
digitalWrite(2, LOW);
delay (3000);
}
else if((temp >= tempMin + 5)&&(temp <tempMin + 10)){ //2
digitalWrite(RELAY1, HIGH);
digitalWrite(3, HIGH);
delay (1500);
digitalWrite(RELAY1, LOW);
digitalWrite(3, LOW);
delay (3000);
}
else if((temp >= tempMin + 10)&&(temp <tempMin + 15)){ //3
digitalWrite(RELAY1, HIGH);
digitalWrite(4, HIGH);
delay (1800);
digitalWrite(RELAY1, LOW);
digitalWrite(4, LOW);
delay (2000);
}
else if((temp >= tempMin + 15)&&(temp <tempMin + 20)){ //4
digitalWrite(RELAY1, HIGH);
digitalWrite(5, HIGH);
delay (2000);
digitalWrite(RELAY1, LOW);
digitalWrite(5, LOW);
delay (2000);
}
else{
digitalWrite(RELAY1, LOW);
digitalWrite(6, HIGH);
delay(180000);
digitalWrite(6, LOW);
temp = readTemp();
Serial.print("TEMP=");
Serial.print(temp);
Serial.println();
}
}
float readTemp()
{
float rawvoltage = analogRead(outputpin);
float mmv = ((rawvoltage/1024)*5000); //milivolts
temp = mmv/10;
return temp;
}
For each if-else I have one LED so I know which one is being executed. The delays are very random, im just trying to follow that rate (5°C/min) which doesn't happen most of the time.
It is not repeatable and after it reached tempMax it just turns off and lets it cool down for 3 min. then starts the cycle again.
How can I add another loop in order to keep the temp for 4 more min?
Do you guys have any other input to my code to make it more repeatable?
Thank you!