Force crash Arduino Uno to pass by the time counter limit

Hi everyone, I am doing a project where I need to make a motor turn by phases and loop it indefinitely. To do so, I use:

  • Arduino Uno
  • Nema 17 motor
  • A4988 Stepper Motor Driver

My issue is the following: as I need to have this programme running “forever” (several months/years) without any external influence, I would like to find a way to make the Arduino reboot/reset at the end of every cycle in order to have the time counter reset.

would you have any idea how to do so ?

thanks in advance !!!

Show us your code and we can show you how to avoid th problem, which sounds also like this might be of interest to you just now:

For deployment that might literally be years you might have other reasons to “force crash” your system, but time counter reset is unnecessary as you can read above.

HTH

a7

Watchdog timer springs to mind

Thank you for your answer. I am a very beginner in theses things so I didn’t understand everything in the link about millis rollover.

my code is currently as follow:

int x;
#define BAUD (9600)

void setup()
{
Serial.begin(BAUD);
pinMode(6,OUTPUT); // Enable
pinMode(5,OUTPUT); // Step
pinMode(4,OUTPUT); // Dir (rotation)
digitalWrite(6,LOW); // Set Enable low
}

void loop()
{
digitalWrite(6,LOW); // Set Enable low
digitalWrite(4,HIGH); // Set Dir (rotation) high
Serial.println(“Loop 1600 steps (1 rev)”);
for(x = 0; x < 12000; x++) // Loop for x milisec
{
digitalWrite(5,HIGH); // Output high
delay(2); // Wait
digitalWrite(5,LOW); // Output low
delay(3); // Wait
}
Serial.println(“Pause”);
delay(690000); // pause milisec

digitalWrite(6,LOW); // Set Enable low
digitalWrite(4,LOW); // Set Dir high
Serial.println(“Loop 1600 steps (1 rev)”);
for(x = 0; x < 12000; x++) // Loop for x milisec
{
digitalWrite(5,HIGH); // Output high
delay(2); // Wait
digitalWrite(5,LOW); // Output low
delay(3); // Wait
}
Serial.println(“Pause”);
delay(690000); // pause milisec

}

I computed various codes I found online and with help, managed to adapt it and understand it as much as I could. The actual situation is the following:

  • motor turning for 2 minutes (12000 milisec) at speed 5 (2+3);
  • pause for 11,5 minutes (690000 milisec)
  • motor turning the other way for 2 minutes (12000 milisec) at speed 5 (2+3);
  • pause for 11,5 minutes (690000 milisec)

I want this program to work indefinitely, over and over…
what do you think?

thks

Maybe I misunderstand the problem, but the Arduino “millis()” counter rolls over to zero on the next tick after hitting the maximum count (about 49 days). There’s no need to explicitly reset the counter, but any code using the count has to tolerate these rollover events.

That should run 4ever, happily doing nothing most of the time.

If there is loss of power, it will mean an inexact entrance into the sequence. As I noted before, there may be good reasons to reset the whole works from time to time; here’s where we’d all like to know more about what exactly it is you are up to if you wouldn’t need to kill us after you say.

I wouldn’t send this into orbit around Mars without a great deal more care to seeing that it could perform to your specifications.

BTW power to the physical things attached is often a source of problems in these circumstances, equal care must be taken with the hardware. Just sayin’.

The timing isn’t super accurate so it may drift if you compare it to the clock on the wall expecting it to stay synchronized.

And 12000 is the number of times those for loops will run, not the number of milliseconds. It will take approximately 12000 * (2 + 3) milliseconds, check my maths that’s 60 seconds, so 24000 instead for two minutes.

I’ll trust your calculations for the long delay() between motor motion CCW an CW. The 690000 looks right for ~11.5 minutes.

If the timings and durations are critical or the power glitch thing would be bad, you might consider adding a real time clock module or RTC to you circuit. Easy, cheap and giving you a different way to time the steps in your sequence.

And it may be that so doing would open up other things the Arduino could be doing asides twiddling its thumbs most of the time.

a7

To answer your several points:

  1. the aim of this program is to run a step by step motor (as you already understood) in order to build a watch winder.
  2. I indeed checked and the 12000 had to be changed to 24000 to get 2 minutes. but I didn’t understand what this figures stand for…
  3. a new question: what does stand for the:
    pinMode(6,OUTPUT); // Enable
    I Dion’t actually use the 6th pin but the motor is moving as I want.
  4. I am not sure about the clock as I am a very beginner in this wold and wouldn’t be able to make it work ;). Would you have in mind a simpler way ?

Thks

Hi everyone, I am a total beginner in this whole field and all I can read at the moment is gibberish to me… I am trying to run a motor according to the following cycle:

  • runs 120 seconds at 10 sec per revolution
  • pause 528 seconds
  • turns 120 seconds in the other direction at the same speed
  • pause 528 seconds
    → start again continuously.

the goal of all this is to build a watch winder :wink:

I have an Arduino Uno, a Nema 17 motor, a TB6600 stepper, and I would like to integrate a DS1302 clock to keep track of time and to be able to run for an “unlimited” time …
I’ve tried to do it myself but I can’t get anything done…
Can you help me with the code and the wire connections?

Thank you very much in advance !!!

Show what you tried

and DON’T double post, and keep things into the same thread as you had one open.

This seems a great ask for the Gigs and Collaboration forum. Make sure you mention your budget.

I have merged your topics @gabrielcdf9. It’s OK to create multiple topics as long as they have distinct subject matter. However, once they converge into parallel discussions of the same subject matter, it only wastes the time of the people trying to help you due to duplicate efforts.

ok thank you, I am not very familiar with the forum yet… I hope I will get more help ! :wink:
thank you

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.