I have been working on this project for some time now and Dont quite know what I am doing wrong...Not to mention know what I am doing right ;D. I am a shinny new beginner in the micro controller programming world with no formal training in it. Here is my deal.
I have made a controller for my outdoor wood stove that heats water and pumps it into the house for home heating. The controller has a input for water temp, and thermostat state. 2 outputs, One for fan control and one for pump control. I want the pump to come on when the thermostat calls for heat, and the fan to come on when the water temp gets over a certain temp. if it does not reach that temp in 5 minutes, I want the pump to shut down and the controller to stop and wait for 1 hr before trying the cycle again. Here is the code I have, right now it waits, sees tstat input and starts the pump, the fan starts and the whole thing keeps running regardless if the tstat opens. I dont know what I am doing wrong. Im sure you all will find plenty of errors. Thanks in advance.
#define TSTAT 12 //OR.OR/W
#define FAN 13 //BR.BR/W
#define TEMP 0 // BL.BL/W
#define PUMP 11 //G.W
#define LITE 10
int temp = 0; //read and store coil temp
int tstat = 0; //thermostat state
void setup(){
pinMode(TSTAT, INPUT); // tstat state input
pinMode(FAN, OUTPUT); // fan control output
pinMode(TEMP, INPUT); //coil temp
pinMode(PUMP, OUTPUT); //pump control OUTPUT
Serial.begin(9600);
}
void loop(){
tstat = digitalRead(TSTAT); // read input from tstat
Serial.println(tstat);
delay(1000);
switch(tstat){
case 0: // tstat open = pump off
digitalWrite(PUMP, LOW);
break;
case 1: //tstat closed = pump on
digitalWrite(PUMP, HIGH); //turn pump on
temp = analogRead(TEMP); //read coil temp
Serial.println(temp); //print coil temp
tstat = digitalRead(TSTAT); // print tstat state
while (temp < 475) { //while coil is hot (>125F) and
digitalWrite(FAN, HIGH); //tstat is closed turn fan on
tstat = digitalRead(TSTAT); // check tstat state
temp = analogRead(TEMP); // check coil temp
break;}}
delay(360000); // delay 5 min 300000ms
if (temp > 475) { // shut down if coil temp is low
digitalWrite(PUMP,LOW);
digitalWrite(FAN, LOW);
delay(3600000);} // lock out for 1 hr if coil temp is low
temp = analogRead(TEMP); // read coil temp
tstat = digitalRead(TSTAT); //check tstat state
delay(1000); // wait a second
if (temp >= 475) { // if temp is low, turn fan/pump off (<125F)
digitalWrite(FAN, LOW);
digitalWrite(PUMP, LOW);
}
if (tstat == 0) { //if tstat is open, turn pump off
digitalWrite(PUMP, LOW);
}
}