Pages: [1]   Go Down
Author Topic: Does Arduino have an automatic time-out?  (Read 341 times)
0 Members and 1 Guest are viewing this topic.
Midwest USA
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm very new to the Arduino world and I have no experience with programming language.  I'm using my Arduino UNO R3 to run an automatic door operator.  I want the door to open, stay open for a set time, close, and stay closed for a set time, repeat (24 hour cycle).  I have developed the following sketches to accomplish this task using an Arduino R3 motor shield.  My  sketch #1 (quick test) works perfectly but when I upload sketch #2 (my desired timing) the door will open and never will shut.  I wonder if the Arduino has an automatic time-out function that I'm not aware of.  Can you guys help me trouble-shoot my sketch?  Is there a better way to do long term motor shutdown times?  Thanks.
_______________________________________________________________
Code:
// Sketch #1 (my quick test sketch)
//Drive DC motor CW 10 seconds, pause 2 seconds, run motor CCW 10 seconds, pause 2 seconds, repeat.
//L. C. H. 2/23/2013

// Motor definitions
int DIR_A = 12;
int SPEED_A = 3;
int BREAK_A = 9;

void setup()
{
  pinMode(SPEED_A, OUTPUT);
  pinMode(DIR_A, OUTPUT);
  pinMode(BREAK_A, OUTPUT);
 
  // release break
  digitalWrite(BREAK_A, LOW);
}

void loop()
{
  // run motor CW full speed.  (Max is 250)
  digitalWrite(DIR_A, HIGH);
  analogWrite(SPEED_A, 250);

  // run motor for 10 seconds
  delay(10000);

 // stop motor
  analogWrite(SPEED_A, 0);
 
  // pause 2 seconds
  delay(2000);

  // move motor CCW full speed.  (Max is 250)
  digitalWrite(DIR_A, LOW);
  analogWrite(SPEED_A, 250);

  // run motor for 10 seconds
  delay(10000);

 // stop motor
  analogWrite(SPEED_A, 0);
 
  // pause 2 seconds
  delay(2000);

 }
_______________________________________________________________
Code:
//Sketch #2 (my long-term-pause sketch w/desired timing)
//Drive DC motor CW for 18 seconds, pause 14 hours, run CCW for 18 seconds, pause 10 hours, repeat.
//L. C. H. 2/24/2013

// Motor A definitions
int DIR_A = 12;
int SPEED_A = 3;
int BREAK_A = 9;

void setup()
{
  pinMode(SPEED_A, OUTPUT);
  pinMode(DIR_A, OUTPUT);
  pinMode(BREAK_A, OUTPUT);
 
  // release break
  digitalWrite(BREAK_A, LOW);
}

void loop()
{
  // run motor CW full speed.  (Max is 250)
  digitalWrite(DIR_A, HIGH);
  analogWrite(SPEED_A, 250);

  // run motor for 18 seconds to open
  delay(18000);
 
 // stop motor
  analogWrite(SPEED_A, 0);

  // pause door open 14 hours (minus 18000 ms runtime)
  delay(50398200);

 // run motor CCW full speed.  (Max is 250)
  digitalWrite(DIR_A, LOW);
  analogWrite(SPEED_A, 250);

  // run motor for 18 seconds to close
  delay(18000);
 
  // stop motor
  analogWrite(SPEED_A, 0);

  // pause door closed 10 hours (minus 18000 ms runtime)
  delay(35998200);
  
}
« Last Edit: March 24, 2013, 06:54:36 pm by PlayStationFarm » Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 986
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your constants are being evaluated as 16-bit int variables,and some of the values are too large to fit.

Marking your large constants with UL to make them unsigned long might help:

Code:
  delay(50398200UL);

-br
Logged

Värmland, Sweden
Offline Offline
Sr. Member
****
Karma: 9
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Using delay or millis for schedules like that will not work well. You will be surprised how much drift you will see over a few days and if the power is lost your Arduino will start opening and closing your door at totally different times.
Consider adding an RTC to keep track of the actual time instead.
Logged

Midwest USA
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know what an RTC is.  What is it and how is it used? Thanks.

Edit: I have been reading many posts here and I found that RTC means "real time clock".  I'll study more.
« Last Edit: March 24, 2013, 05:58:42 pm by PlayStationFarm » Logged

Värmland, Sweden
Offline Offline
Sr. Member
****
Karma: 9
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

DS1307 is probably the most popular one but there are other options.
http://playground.arduino.cc/Main/InterfacingWithHardware#time

The easiest way to get started is a kit or ready-made module including the RTC chip, battery, crystal and other necessary components.
http://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit
Logged

Pages: [1]   Go Up
Jump to: