First of all I am pretty new to coding in general and probably am just misunderstanding something simple but I cannot seem to figure it out.
I am trying to use an arduino to automate a dishwasher to keep it going for many cycles. I have a series of actions that happen to open/close the door of the dishwasher and then push the start button using a servo motor. The issue I am having is with the timing. When I am testing the code with a short cycle time (i.e. 30 seconds to a few minutes) the code seems to work but when I try to run it for an hour is doesn't end up restarting the dishwasher. I am using elapsed millis to track the run time and then a while loop to keep it looping for the duration of the cycle and then once the elapsed time is greater than the cycle time it runs back through the button pushing portion of the code and resets the time. At first i thought the arduino might be going to sleep but that wasn't happening and then I realized I was initializing the cycle time as an integer and not a long but even after those things it still won't work.
If anyone has any insight that would be awesome.
#include <elapsedMillis.h>
elapsedMillis time;
unsigned long cycletime = (1000*60*62);
int cyclenumber = 1;
#include<Servo.h>;
Servo servoone;
int DoorSwitch = 9; //switches door to "open" door between cycles
//unsigned long time;
void setup() {
Serial.begin(9600);
pinMode(DoorSwitch, OUTPUT);
}
void loop() {
time = 0;
Serial.print(" ");
Serial.print(" Cycle Number: ");
Serial.print(cyclenumber);
// Opens and Closes door
digitalWrite(DoorSwitch, LOW);
delay (3000);
digitalWrite(DoorSwitch, HIGH);
Serial.print(" the door has been closed ");
delay(3000);
//Button Pusher to start the dishwasher
Serial.print(" button pressed ");
servoone.write(60);
servoone.attach(10);
delay(100);
servoone.write(60);
delay(100);
servoone.write(130);
delay(1000);
servoone.write(60);
servoone.detach();
delay(1000);
servoone.write(60);
servoone.attach(10);
delay(100);
servoone.write(60);
delay(100);
servoone.write(130);
delay(1000);
servoone.write(60);
servoone.detach();
delay(1000);
servoone.write(60);
servoone.attach(10);
delay(100);
servoone.write(60);
delay(100);
servoone.write(130);
delay(1000);
servoone.write(60);
servoone.detach();
servoone.write(60);
delay(100);
servoone.write(130);
delay(1000);
servoone.write(60);
servoone.detach();
Serial.print(" while loop start ");
while (time < cycletime) {
Serial.print("looping");
Serial.print(time);
delay(5000);
}
Serial.print(" while loop done ");
Serial.print(" Cycle Time: ");
Serial.print(cycletime/1000);
digitalWrite(DoorSwitch, LOW);
cyclenumber++;
}
elapsedMillis.h (4.2 KB)