Making Timer Controls for Clothes Dryer.

Still pretty green to Arduino.

Trying to make a timer for use with the clothes dryer. The rotary switch is broken but the dryer still runs fine just no timer.

Starting simple here. Let me know what changes I need to make to let my sketch work.

//Clother Dryer Timer 6-19-2014
int dryerOn=13; //Pin 13 is dryer on switch output
int dryerOff=14; //Pin 14 is Dryer off switch output
int buttonOn=15; //Pin 15 is ON button press Input
int buttonOff=16; //Pin 16 is OFF button press Input


void setup()
{
pinMode (buttonOn, INPUT);
pinMode (buttonOff,INPUT);
pinMode (dryerOn, OUTPUT);
pinMode (dryerOff, OUTPUT);
if (buttonOn = HIGH) // If dryer on button pressed cycle start button. Delay 60 minutes and activate off switch
{digitalWrite(dryerOn,HIGH);
delay(1000);
digitalWrite(dryerOn,LOW);
delay(60*60*1000);
digitalWrite(dryerOff,HIGH);
delay(1000);
digitalWrite(dryerOff,LOW);
}
if (buttonOff = HIGH)// If button off pressed active dryer off switch
{digitalWrite(dryerOff,HIGH);
delay(1000);
digitalWrite(dryerOff,LOW);
}}
void loop()
{
}
if (buttonOn = HIGH) // If dryer on button pressed cycle start button. Delay 60 minutes and activate off switch

Oops. (Times two.)

I would look at the blink without delay program and start there. With the big delay that you have, it won't give you the option to stop your dryer.

The other thing I would do is, is check how the heater is hooked up to the dryer, because a lot of dryers will turn off the heat and then run the dryer through the last five minutes without heat so that the clothes have a chance to cool down. You could even add a one minute warning ding if you like.

jasit:
I would look at the blink without delay program and start there. With the big delay that you have, it won't give you the option to stop your dryer.

The other thing I would do is, is check how the heater is hooked up to the dryer, because a lot of dryers will turn off the heat and then run the dryer through the last five minutes without heat so that the clothes have a chance to cool down. You could even add a one minute warning ding if you like.

Looks like I need to learn millis.

Right now we just open the door to shut it off so I don't need to get to fancy yet. ]:smiley:

that's what I am saying, when you open the door, it won't register on the arduino in theory the arduino will continue to run until the 60 min is up.

I think I have something here.

unsigned long elapsedTime;
unsigned long elapsedTime1;
unsigned long onTime;
unsigned long onTime1;
 
void setup()
{
  onTime = millis();
  onTime1 = millis();
  onTime = elapsedTime;
  onTime = elapsedTime1;
  pinMode(10, OUTPUT);  //Initialize pin 12 as status LED
  pinMode(8, OUTPUT);
  pinMode(13, INPUT);    // Our button pin
  pinMode(12, INPUT);
}
 
void loop()
{
  if (digitalRead(13) == HIGH)   // Switch #1 is closed to start LED timer
         {
          digitalWrite(10, HIGH);  // LED #1 comes On  
          onTime = millis();  
          }
      if(onTime > 0 && millis() - onTime > 9000)  // Dryer Start button pres time
            {      
            digitalWrite(10, LOW);  // LED #1 goes off
          }
      if(onTime > 0 && millis() - onTime > 10000)  // Dryer Run cycle time.
            {
            digitalWrite(8, HIGH); //Dryer Stop Botton on
            delay(1000);  // 1 sec delay
            digitalWrite(8, LOW); // Dryer Stop button release
            onTime = 0; //miilis timer off
            }
           
  if (digitalRead(12) == HIGH)   // Switch #2 is closed to start LED timer
         {
          digitalWrite(8, HIGH);  // LED #2 comes On  
          onTime1 = millis();  //Millis#1 Timer Start
          }
      if(onTime1 > 0 && millis() - onTime1 > 5000)  // if on time#1 is greater than
            {      
            digitalWrite(8, LOW);  // LED #2 goes off
            digitalWrite(10, LOW); // Test for verification purposes. Disables start.
             onTime1 = 0; // Millis #1 Timer Off
             onTime = 0; //millis timer off / OVERIDES Timer for run cycle so sequence does not continue to run.
            }
}

Seems to work with LEDS. Now to figure out what kind of power I have running ot my switches in the dryer.

Disregard the times right now. they are for testing only.

onTime > 0

In this case the change will have a very minor affect but in general you will be far better served by having separate variables for state. I suggest you get in the habit now rather than endure a trial by fire later.

Awesome job, 100 times better than your original code.

I would verify this code, because at the start you set onTime1 =millis() in the setup, this code might run at the very start when it's not suppose to.

 if(onTime1 > 0 && millis() - onTime1 > 5000)  // if on time#1 is greater than
            {      
            digitalWrite(8, LOW);  // LED #2 goes off
            digitalWrite(10, LOW); // Test for verification purposes. Disables start.
             onTime1 = 0; // Millis #1 Timer Off
             onTime = 0; //millis timer off / OVERIDES Timer for run cycle so sequence does not continue to run.
            }

I would verify this code, because at the start you set onTime1 =millis() in the setup, this code might run at the very start when it's not suppose to.

Note taken! Thanks!

jasit:
Awesome job, 100 times better than your original code.

I would verify this code, because at the start you set onTime1 =millis() in the setup, this code might run at the very start when it's not suppose to.

 if(onTime1 > 0 && millis() - onTime1 > 5000)  // if on time#1 is greater than

{     
            digitalWrite(8, LOW);  // LED #2 goes off
            digitalWrite(10, LOW); // Test for verification purposes. Disables start.
            onTime1 = 0; // Millis #1 Timer Off
            onTime = 0; //millis timer off / OVERIDES Timer for run cycle so sequence does not continue to run.
            }




I would verify this code, because at the start you set onTime1 =millis() in the setup, this code might run at the very start when it's not suppose to.

I am not sure what you mean? It does do some funky stuff the first time it runs. So I assume this is what your talking about but I am not sure what to fix. Remove the millis() after &&?

You really don't want to set the ontime and ontime1 to millis until after you press the start button. they should be initially set to 0, once the start button is pressed. you want to start your calculations

Are you saying in setup that onTime and onTime1 should = 0 instead of millis()?

So that would mean initially onTime would equal 0 untill the button wa pressed then onTime=millis() would start the timer?

Sorry if its a newb question. I am still trying to grasp this stuff.

yes, if you look at your if statements,

if ontime >0 and if ontime1 > 0  because both of those are 0  the statements are false so they are bypassed.

The only two if statements that you may have issue with are the following because those buttons could be pressed in either order and at anytime, so you might want to look at them and see if they need to be changed or if they are fine.



 if (digitalRead(13) == HIGH)   // Switch #1 is closed to start LED timer
         {
          digitalWrite(10, HIGH);  // LED #1 comes On  
          onTime = millis();  
          }

and

 if (digitalRead(12) == HIGH)   // Switch #2 is closed to start LED timer
         {
          digitalWrite(8, HIGH);  // LED #2 comes On  
          onTime1 = millis();  //Millis#1 Timer Start
          }