heating control

hi there
on this heating project i'm doing when the control is turned off the fan will run for 30 secs but one problem i have is it will not start back up until the 30 secs are up what is not good?
and what i would like to do aswel i would like to have the delay variable so if the heater has been running for 20secs the over run with be 20 secs but max over run to be 30secs?

i had come across this for the variable over run but could not intergrate this into my code and make it still work and it does not have a max over run to

const int switchPin = 2;
const int led = 13;

long startTime;
long duration;

void setup()
{
pinMode(switchPin, INPUT);
digitalWrite(switchPin, HIGH);
pinMode(led, OUTPUT);
}

void loop()
{
if(digitalRead(switchPin) == HIGH)
{
digitalWrite(led, HIGH);
}

if(digitalRead(switchPin) == HIGH)
{
startTime = millis();
while(digitalRead(switchPin) ==HIGH)
;
long duration = millis() - startTime;
delay(duration);
digitalWrite(led, LOW);
}
}

this is my code
where the yellow glow saying // THIS IS WHERE MY DELAY IS this is where my delay is at mo

const int heatbutton = 2 ;
const int ignition_fan_2 = 10;
const int saleswitch = 4 ;
const int solenoid = 12;
const int photo_pressure = 3 ;
const int lockoutled = 8 ;
const int heatbutton_feed= 5 ;
const int fan = 9 ;
const int relay230_24 = 11;
const int ionisation_in = 7 ;
int ionisation = 5 ;
bool DoneInitialization = false;

void setup()
{
pinMode(heatbutton, INPUT );
pinMode(ignition_fan_2, OUTPUT);
pinMode(saleswitch, INPUT );
pinMode(solenoid, OUTPUT);
pinMode(photo_pressure, INPUT );
pinMode(lockoutled, OUTPUT);
pinMode(heatbutton_feed, OUTPUT);
pinMode(fan, OUTPUT);
pinMode(relay230_24, OUTPUT);
pinMode(ionisation_in, INPUT );
//-------------------------------------------
digitalWrite(heatbutton_feed, HIGH);
}

void loop() {
int val = analogRead(ionisation);
//--------------------------------------------------------------------

if (digitalRead(heatbutton)== HIGH) {
delay(10); //debounce
if (!DoneInitialization)
{
if (digitalRead(ionisation_in)== HIGH) { // if ionisation swith HIGH
if (val >900) {
digitalWrite(lockoutled, HIGH);
delay(10);
digitalWrite(heatbutton_feed, LOW);
return;
}
}
else {
if (digitalRead(photo_pressure)== HIGH) { // if photo swith HIGH
delay(10);
digitalWrite(lockoutled, HIGH);
delay(10);
digitalWrite(heatbutton_feed, LOW);
return;
}
}
digitalWrite(fan, HIGH);
delay(3000);

//---------------------------------------------------------------------
if (digitalRead(saleswitch)==HIGH) { // sale switch if HIGH
digitalWrite(relay230_24, HIGH); // 230V out put to ignition
digitalWrite(ignition_fan_2, HIGH);
delay(1000);
digitalWrite(solenoid, HIGH);
}
DoneInitialization=true; // Initialization is done, don't run it again until button has been low
}
//---------------------------------------------------------------------
if (digitalRead(saleswitch)== LOW) { // sale switch if LOW
digitalWrite(lockoutled, HIGH);
digitalWrite(solenoid, LOW);
digitalWrite(fan, LOW);
delay(10);
digitalWrite(heatbutton_feed, LOW);
}
//---------------------------------------------------------------------
delay(3000);
if (digitalRead(ionisation_in)== HIGH) {
if (val <900) { // ionisation if LOW
digitalWrite(lockoutled, HIGH);
delay(10);
digitalWrite(heatbutton_feed, LOW);
}
}

if (digitalRead(photo_pressure)==LOW) { // photo if LOW
delay(10);
digitalWrite(lockoutled, HIGH);
delay(10);
digitalWrite(heatbutton_feed, LOW);
}
//---------------------------------------------------------------------
else {
digitalWrite(ignition_fan_2, LOW);
}
}
//---------------------------------------------------------------------
else { // switching off
digitalWrite(solenoid, LOW);
digitalWrite(ignition_fan_2, LOW);
DoneInitialization=false; // resetting the count
delay(500);
digitalWrite(relay230_24, LOW);
delay(30000); // THIS IS WHERE MY DELAY IS
digitalWrite(fan, LOW); // THIS IS WHERE MY DELAY IS
}
//---------------------------------------------------------------------

}

Joes:
hi there
on this heating project i'm doing when the control is turned off the fan will run for 30 secs but one problem i have is it will not start back up until the 30 secs are up what is not good?

First off, use the Code tags, not the Quote tags.

As far as your question, you mean it doesn't respond to any input until after 30 seconds? That's what delay() does. If you want it to be able to recognize buttons/inputs/sensors during that 30 seconds, you'll need to re-implement it without delay(). Check out the Blink without Delay example to see how this kind of thing is done.

hi thanks for your reply
i have looked at blink without delay and cannot get to grips with it

Joes:
hi thanks for your reply
i have looked at blink without delay and cannot get to grips with it

As in you don't understand how it works?

Someone had a good analogy that I'm going to steal...

Say you're cooking something in oven that is going to take 10 minutes. How do you know when it is finished? Well, one way is to sit there count up to 10 minutes. That's is like how the delay() works. If someone knocks at the door, the phone rings, etc, you can't do anything until you finishing counting up. Now the Blink without delay would be like writing down the time you started, and periodically checking back. When you check back, you can figure out the time elapsed by subtracting the time you wrote down with the current time. If 10 minutes or more it's done. That will allow you to answer the phone, the door, or respond to other issues that need your attention.

So what you need to do, is record the time at which you turned the fan on, and on each loop, check to see if it's been longer than 30 seconds. If it has, turn it off.

It's a very simple concept once you see it, but it can take a few hours to get to that point - sounds like you need to put in a bit more time. Here's a suggestion from a few months ago if you're still stuck after that:

Unless this is your last Arduino project ever, you will almost certainly need to master Blink without delay eventually. When that day comes, if you still don't get it, you might want to break out the paper computer:

Print the program
On another piece of paper, rule off a grid & list the variables and items you need to track as columns. This is mercifully short for this program:
ledState, previousMillis, interval, currentMillis are your variables
you should also have a column for millis and one for the led itself - is it on or off

'Run' the program. Start at the top & 'execute' each statement. Run setup. At each statement, if it changes one of your variables, fill in a new row on the grid. if a statement uses one of the variables, look up the value it currently has in the grid.Do the same with loop, again & again. Remember that millis will have increased on each loop. Start by increasing it by one. When you realize that that's going to take forever, use 300 instead. This will be very tedious, but after a few rounds of running loop, you will suddenly see what is happening.

ok i have had a bit off a play with this (again lol) this seem to work but did miss the delay a couple of times but this is just on a test rig at mo so mite be ok then installed what do you think?

this is just delay with out delay at mo

const int heatbutton     = 2 ;
const int ignition_fan_2 = 10;
const int saleswitch     = 4 ;
const int solenoid       = 12;
const int photo_pressure = 3 ;
const int lockoutled     = 8 ;
const int heatbutton_feed= 5 ;
const int fan            = 9 ;
const int relay230_24    = 11;
const int ionisation_in  = 7 ;
int ionisation           = 5 ;   
bool DoneInitialization = false;        
int fandelay = LOW;
long previousMillis = 0;
long interval = 30000;
void setup()
{
  pinMode(heatbutton,       INPUT );    
  pinMode(ignition_fan_2,   OUTPUT);
  pinMode(saleswitch,       INPUT );
  pinMode(solenoid,         OUTPUT);
  pinMode(photo_pressure,   INPUT );
  pinMode(lockoutled,       OUTPUT);
  pinMode(heatbutton_feed,  OUTPUT);
  pinMode(fan,              OUTPUT);
  pinMode(relay230_24,      OUTPUT);
  pinMode(ionisation_in,    INPUT );
  //------------------------------------------- 
  digitalWrite(heatbutton_feed, HIGH);
}

void loop() {
  int val = analogRead(ionisation);
  //--------------------------------------------------------------------

  if (digitalRead(heatbutton)==        HIGH) {
    delay(10);    //debounce
    if (!DoneInitialization) 
    {                                                  
      if (digitalRead(ionisation_in)==   HIGH) {           // if ionisation swith HIGH 
        if (val >900) {                                        
          digitalWrite(lockoutled,            HIGH);
         delay(10); 
          digitalWrite(heatbutton_feed,       LOW); 
          return;
        } 
      }   
      else {
        if (digitalRead(photo_pressure)==     HIGH) {         // if photo swith HIGH 
        delay(10);
          digitalWrite(lockoutled,            HIGH); 
         delay(10);         
          digitalWrite(heatbutton_feed,       LOW);
         return;
       } 
      } 
      digitalWrite(fan,                    HIGH); 
      delay(3000);        
      
    //---------------------------------------------------------------------
    if (digitalRead(saleswitch)==HIGH) {           // sale switch if HIGH
    digitalWrite(relay230_24,    HIGH);        // 230V out put to ignition
    digitalWrite(ignition_fan_2, HIGH);
    delay(1000);
      digitalWrite(solenoid,     HIGH); 
    }
    DoneInitialization=true;                           // Initialization is done, don't run it again until button has been low
    }
    //---------------------------------------------------------------------
    if (digitalRead(saleswitch)==   LOW) {          // sale switch if LOW
      digitalWrite(lockoutled,      HIGH);
      digitalWrite(solenoid,        LOW); 
      digitalWrite(fan,             LOW);
       delay(10); 
      digitalWrite(heatbutton_feed, LOW);
    }
    //---------------------------------------------------------------------
    delay(3000);
    if (digitalRead(ionisation_in)== HIGH) {
      if (val <900)                         {            // ionisation if LOW
        digitalWrite(lockoutled,      HIGH); 
        delay(10);
        digitalWrite(heatbutton_feed, LOW);
      } 
    }

    if (digitalRead(photo_pressure)==LOW)  {          // photo if LOW
      delay(10);
      digitalWrite(lockoutled,       HIGH);
      delay(10); 
      digitalWrite(heatbutton_feed,  LOW);
    }
    //---------------------------------------------------------------------
    else {
      digitalWrite(ignition_fan_2, LOW); 
    }
  }
    //---------------------------------------------------------------------
    else {                                          // switching off
    digitalWrite(solenoid,       LOW);
    digitalWrite(ignition_fan_2, LOW);
    DoneInitialization=false;                    // resetting the count 
    delay(500);
    digitalWrite(relay230_24,    LOW);
          unsigned long currentMillis = millis();
   if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;
  if (fandelay == LOW)
    digitalWrite(fan, LOW); 
      digitalWrite(fan, fandelay);
  }
    } 
  //---------------------------------------------------------------------
}
int fandelay = LOW;
...
  if (fandelay == LOW)
    digitalWrite(fan, LOW); 
      digitalWrite(fan, fandelay);

What exactly are you trying to accomplish with this part?

You created a variable fandelay that never changes. You then check if that variable is LOW (as it never changes it always is) and then have two redundant statements that set the fan pin to LOW.

Also, the "check if it's been long enough" code will only run if your button is HIGH. Is that your intention? In other words, fan won't go low unless it's been long enough AND heatbutton is HIGH.

Also, fandelay is a terrible name for a state. When I see a variable named fandelay, I assume the variable holds some time/interval value.

What exactly are you trying to accomplish with this part?

im trying just to do the delay without delay at the moment

Also, the "check if it's been long enough" code will only run if your button is HIGH. Is that your intention? In other words, fan won't go low unless it's been long enough AND heatbutton is HIGH.

my intention is to delay the fan when turning off so when the heat button goes from high to low it will delay.

but i do want to include as i said earlier that the time delay is dependent on the time the heat button has been high upto a set time.

Joes:
im trying just to do the delay without delay at the moment

I was referring to that specific part of the code, explaining how redundant it is.

my intention is to delay the fan when turning off so when the heat button goes from high to low it will delay.

Ignore that part, it looked, at first, to still be within the headbutton high scope.

but i do want to include as i said earlier that the time delay is dependent on the time the heat button has been high upto a set time.

So to accomplish this, you need to implement some sort of edge detection on your heatbutton. Edge detection would be determining the instant when the button goes from HIGH to LOW or LOW to HIGH. To do this, you need to keep track of the previous reading of heatbutton and compare it to the current reading. This will allow you to record the time when it first goes HIGH and then goes LOW. The difference of those two times would be the time it was pressed down for. You could then plug those values into some formula to determine the interval at which you want it to be on for.

I was referring to that specific part of the code, explaining how redundant it is.

o sorry how as can i write this?

???

Joes:

I was referring to that specific part of the code, explaining how redundant it is.

o sorry how as can i write this?

  if (fandelay == LOW)
    digitalWrite(fan, LOW); 
      digitalWrite(fan, fandelay);

Unless you plan on changing fandelay somewhere in the code (and renaming it, as the name is confusing if it just holds HIGH/LOW), you the above can be accomplished by removing the first and third line.

hi there

but i wont get the delay if i remove the first and third line will I?

i can change the name of fandelay to somthing else dont no what?

Joes:
hi there

but i wont get the delay if i remove the first and third line will I?

i can change the name of fandelay to somthing else dont no what?

What delay? None of those three lines do any delay other than the clock cycles needed to execute.

Calling it fandelay when it just holds a constant value of LOW really makes no sense, you may as well just remove the variable altogether. I couldn't recommend a better name because nothing in the code gives any indication to it's purpose.

In your own words, what do you think those 3 lines of code do?

i have no idea all i have dun is looked at blink with out delay and tried splicing it in to my code what does not work.
dont no how else to make this work?

Joes:
i have no idea all i have dun is looked at blink with out delay and tried splicing it in to my code what does not work.
dont no how else to make this work?

Then I would recommend spending more time learning what code does and probably look at, and most importantly, understand how, the examples work before you try to start a new project. If you can't at least explain what a couple line is supposed to do, then that tells me that you are just blindly copying parts of code from examples into your code without understanding how they work.

If you want to hit a bullseye, you first have to learn how the bow and arrow works.

i have looked and looked and i dont understand it hence why i have posted this to seek help.
and i have written the whole of this code apart from the delay without delay which is what i dont understand. hence why i am asking.

Joes:
i have looked and looked and i dont understand it hence why i have posted this to seek help.
and i have written the whole of this code apart from the delay without delay which is what i dont understand. hence why i am asking.

Well, there are two analogies on the previous page the should help with your understanding of how the Blink without Delay example works, so I recommend reading those and using them as a tool to help you understand how that example works. Delaying code without the use of Delay() is such a fundamental aspect of the Arduino, that I would seriously advise everyone getting started with it to learn exactly how it works before trying any non-trivial project. If you have specific questions about how it works, then feel free to ask.

still having issues ive given up looking at the blink without delay as the more i look at it the more confused im getting so had a look generally on the internet and come across this idea but still doesnt work i seemed to get it to not have a delay or have an endless delay
doing my head in now lol

 else {                                          // switching off
    digitalWrite(solenoid,       LOW);
    digitalWrite(ignition_fan_2, LOW);
    DoneInitialization=false;                    // resetting the count 
    delay(1000);
    digitalWrite(relay230_24,    LOW);
          static unsigned long starttime;
          static int fanstate = LOW;
    if (fanstate == LOW && millis() - starttime > 10000) {
        fanstate = HIGH;
        digitalWrite(fan,           LOW); 
        starttime = millis();
    }
  }

I've been following this and understand finally what your problem is Joes.
This is maybe important project for you, but please follow the advise of Arrch.
You need to put in the time to understand it for your next project. You trying to
run, but at the end you really can't run, because you never learn to crawl properly.
Be patient with " blink without delay" play with it. Tinker with it. Then only you will trully know what to do and what to ask to finish your project.That's my advise. Best of luck my friend and remember this is not a insult. It's rather a push in the right direction.
Groete
F