1 hr. delay with outputs left on.

I am new to this programming thing as well as this forum. so first, hello to all. I am trying to program an arduino duemlinove to run a wood burner, with fan outputs and 2 temp inputs. I have a button input that I call over ride. all i want it to do is when pushed, is turn on pin 13 (my solid state relay output) for 1 hr. I cant write:
digitalWrite(SSR, HIGH);
delay(3600000);
because it turns on my SSR for a split second and then delays (does nothing for 1 hr. ) How can i write this. I realize this may be the most basic of questions, you will have to excuse me as i am very new to this. Thanks! here is the section of code:
#define SSR 13 // solid state relay blower output
#define OR 12 //override input
#define WT 0 // water temp
#define OT 1 // outside temp
int ost = 0; // outside temp var
int wt = 0; //water temp var

void setup()
{ pinMode(12, INPUT);
pinMode(13, OUTPUT);
pinMode(0, INPUT);
pinMode(1, INPUT);
}

void loop(){
digitalRead(OR); //IS THE OVERRIDE ACTIVE OR NOT?
delay(500); // WAIT 1/2 SECOND
if(OR, HIGH){
digitalWrite(SSR, HIGH); } //IF OVERRIDE IS ACTIVE, SSR IS ON.
delay(3600000);} //override is active for 1hr.
else{

Hello and welcome to the forum.

if(OR, HIGH){
digitalWrite(SSR, HIGH); } //IF OVERRIDE IS ACTIVE, SSR IS ON.
delay(3600000);} //override is active for 1hr.
else{

You probably do not want the highlighted } there because it closes the if. That makes your delay run every time, regardless of the override switch.

Then the next } (the one on the delay(...) line) closes the loop(). Don't you get a compile error on the else?

What I really think you want is to change the if line to
if (OR == HIGH) {

It's difficult to interpret code snippets like this without seeing the entire sketch, so I could be missing something important here.

Firstly you need to assign the digitalread(OR) to a variable, as you have it will digital read pin OR (12) and throw the result into the programming ether.
Secondly, your if statement ( if(OR==HIGH) ) will always return false because OR is defined as 12 in your code and 12 will never equal 1 (unless big brother says it does)

Alec

Yes, halabut, you are correct. There are lots of things to change in this sketch. :-/

thanks for the input so far guys, i will post the entire sketch so you get the whole picture. here is the whole story: it is controlling an outdoor wood burner that heats water. as the temp outside gets colder i want the water temp in the boiler to get hotter. if the water temp gets too cold, it shuts down. when an over ride button is pressed the ssr runs the fan for 1 hr. I say again, i am a beginner with a basic grasp on this, so thanks for understanding, that this is not perfect or even close. Again thanks for any help.

#define SSR 13 // solid state relay blower output
#define OR 12 //override input
#define WT 0 // water temp
#define OT 1 // outside temp
int ost = 0; // outside temp var
int wt = 0; //water temp var
int or = 0; // override state var.

void setup()
{ pinMode(OR, INPUT); //digital input for override switch
pinMode(SSR, OUTPUT); //output to solid state relay
pinMode(0, INPUT);
pinMode(1, INPUT);
}

//SSR is solid state relay that turns on inducer fan
void loop(){
or = digitalRead(OR); //IS THE OVERRIDE ACTIVE OR NOT?
delay(500); // WAIT 1/2 SECOND
if(or == 1){
digitalWrite(SSR, HIGH); //IF OVERRIDE IS ACTIVE, SSR IS ON.
delay(3600000);} //override is active for 1hr.

else{
wt = analogRead(WT); //read water temp, store to wt var.
while (wt > 720) { //if water temp is 70F or colder, shutdown
digitalWrite(SSR, LOW);
wt = analogRead(WT);}
ost = analogRead(OT); //read outside temp store to ost var.
wt = analogRead(WT); //read water temp, store to wt var.
while (ost <= 675){ // ost greater than or = 32F
if ((wt >= 475) && (wt <= 490)) { //water temp 140-150F
digitalWrite(SSR, HIGH);} //turn inducer fan on
ost = analogRead(OT); // read outside temp
wt = analogRead(WT);} //read water temp
while ((ost > 676) && (ost <= 710)){ // outside temp between 20-32
if ((wt >= 460) && (wt <= 474)) { // water temp 150 - 160
digitalWrite(SSR,HIGH);} // turn fan on
ost = analogRead(OT); // read outside temp
wt = analogRead(WT);} // read water temp
while ((ost > 711) && (ost <= 750)) { //outside temp 10 - 19
if ((wt <= 420) && (wt <= 459)) { // water temp 170-180
digitalWrite(SSR, HIGH);}
ost = analogRead(OT); //read outside temp
wt = analogRead(WT);} // read water temp
while (ost > 750) { // outside temp 9 and lower
if ((wt <= 458) && (wt >= 428)) { // water temp 190
digitalWrite(SSR, HIGH);} // turn fan on
}}}

Heres a tip :
You could also try the blink without delay example in the IDE which uses a similar method.

// time and hrloop are unsigned long type.
time = millis():
if (time >= hrloop){  // 1 hour loop
       hrloop = time + 3600000;
     //do stuff you want doing every hour here  
};
// continue in main loop

First can you write in plain english for every ot the wt you want. I assume the fan makes the fire burn hotter.

Secondly do not use the construct: while ((ost > 676) && (ost <= 710)){  // outside temp between 20-32Instead think about repeatedly running through loop(), and at every loop you do the following:

  • read ot and wt
  • assume new ssr value (after loop()) newssr is LOW
  • check the combinations of ot and wt to decide if the new ssr should be on by using a sequence of if statements like if ((ot <= xxx) &&  (wt>= yyy)) newssr = HIGH; * At the end of loop() update SSR to the value just calculated with digitalWrite(SSR, newssr);

I think this will simplify, and clarify, the logic. You will also read the override button continously.

mr lundin. first, thankyou for your help. you are right, when the fan is on the fire is burning making the water hotter. here is the breakdown I think will work best. I can always adjust later.
32 and warmer: water temp between 150-160F
20 - 31F: WT between 161 - 170F
10 - 19F: WT between 171 - 180F
9F and colder: 181 - 190F
if the fire goes out and the water temp drops below say, 90F, i want the fan to turn off (no use running the fan if the fire is out) this is where the override comes in. when i hit the override it will over look the water temp and just run the fan until the water temp gets above the 90F shutdown point.
I am controlling this thing manually with thermostats, if it gets colder out and isnt working as efficient I go out and crank the tstat up. if the fire goes out the fan just runs needlessly. these are the temps i think will work best. It works fine now (just a bother to keep adjusting the tstat). I am a tinkerer at heart and when i stumbled accrossed this awesome hobby I thought I could put it to work doing something useful. I have a few books and am totally self taught and have been beating my brain over this for a couple months now. I have a lot to learn, and i want to figure this all out because i have alot of little things i can do with these boards to make my life easier, not to mention, more fun. Thank you all for your help so far.

So lets make a slight rephrasing of your rules.

define a variable ssr outside both setup() and loop()

in the loop we adjust ssr as follows
(if no adjustment is made it keeps its old value, and the fan state is unchanged)

if ot warmer than 32
if wt warmer than 158 ssr = LOW
if wt colder than 152 ssr = HIGH
else if ot warmer than 20 /* at this point we know that ot<32 /
if wt warmer than 168 ssr = LOW
if wt colder than 162 ssr = HIGH
else if ot warmer than 10 /
at this point we know that ot<20 */
if wt warmer than 178 ssr = LOW
if wt colder than 172 ssr = HIGH

etc

and at the end of loop()
set SSR to the updated value of ssr

For each ot interval we try to keep the wt in the corrsponding range by turning the fan on when wt is 2F above the lower limit and turning off the fan when wt is 2F below the lower limit. This is the basic thermostat function.

This is now very close to C code.

These limits may have to be adjusted.

are you talking something like this mr lundin? I wrote this up quik, it seems like it could work good. The numbers i have in the sketch resemble real temps, not the number value returned by the program. I need to test/calibrate my thermistor to get acurrate numbers at the temps I want. the serial prints are for me to plug in during testing and see what my "beast" is thinking. It might be rough yet, but it is making sense to me. what do you think? Thanks Guys.

#define SSR 13 // solid state relay blower output
#define OR 12 //override input
#define WT 0 // water temp
#define OT 1 // outside temp
int ot = 0; // outside temp var
int wt = 0; //water temp var
int ovr = 0;
int ssrst = 0;

//SSR is solid state relay that turns on inducer fan

void setup()
{ pinMode(OR, INPUT); //digital input for override switch
pinMode(SSR, OUTPUT); //output to solid state relay
pinMode(0, INPUT);
pinMode(1, INPUT);
Serial.begin(9600);
}

void loop(){
wt = analogRead(WT);
ot = analogRead(OT);
ovr = digitalRead(OR);
if((ovr = 1) && (wt < 90)) {
ssrst = 1; } //override will be active until wt = 170
if((ovr = 1) && (wt > 170)) {
ssrst = 0;}

if((ot >= 32) && (wt < 150)) {
ssrst = 1; } //ot over 32 makes wt between 150-160
if((ot >= 32) && (wt > 160)) {
ssrst = 0;}

if((ot <= 31) && (ot >= 20) && (wt < 160)) {
ssrst = 1;} // ot between 20-31 makes wt between 160-170
if((ot <= 31) && (ot >= 20) && (wt > 170)) {
ssrst = 0;}

if((ot <= 19) && (ot >= 10) && (wt < 170)) {
ssrst = 1;} //ot between 10-19 makes wt between 170-180
if((ot <= 19) && (ot >=10) && (wt > 180)) {
ssrst = 0;}

if((ot <= 9) && (wt < 180)) {
ssrst = 1;} // ot below 9 makes wt between 180-190
if((ot <= 9) && (wt > 190)) {
ssrst = 0;}

if(ssrst = 1) { //ssrst = 1 turns fan on
digitalWrite(SSR, HIGH);}
if(ssrst = 0) { //ssrst = 0 turns fan off
digitalWrite(SSR, LOW);}

Serial.println(ssrst);
delay(500);
Serial.println(wt); //diagnostic/testing
delay(500);
Serial.println(ot);
}

Yes, without checking the details, this is getting much cleaner.

You can use the values HIGH and LOW for ssrst, instead of 0 and 1, so the extra conversion form 0,1 to LOW,HIGH is not necessary.

And then I would recomment a function analogToWt (and analogToOt) that handles the conversion betwen thermistar/adc readings and actual temperatures. So the temperature reading becomes:

wt = analogToWt(analogRead(WT));

Then the temperature control logic contains "real" temperatures, and the conversion function handles the thermistor calibration. Much less chance of error.

Happy coding.

Thanks again for all the help, I hope im not being a pest. I am interested in this function wt = analogToWt(analogRead(WT));
if i plug this directly into my sketch I get an error: 'analogTo' was not declared in this scope. i need to define this somehow? I tried searching This function "analogTo" and I cant find it. I think this conversion is a great idea, but do not understand this function or how it works.

Well you must write it :slight_smile: . It is specific for your thermistors.
Use the map function. http://arduino.cc/en/Reference/Map

Enter pairs of temperature, analog read values denoted by t1,a1 and t2,a2 below. Measured at say 100 F and 190 F for wt and 10 F and 32 F for ot, since these are the temperature ranges of most interest for this application.

int analogToWt(int adc) {
  return map(  adc,  a1, a2, t1, t2 ); /* Replace a1,a2,t1,t2 with measured calibration values */
}

And the a similar function for ot.