Running stepper motor at a set time interval

I am very inexperienced in Arduino, but I need to figure out run a 28BYJ-48 stepper motor at set intervals. So, for example, the motor needs to do so many steps at 11 o'clock, then wait till 5 o'clock and run again. I cannot find anywhere that explains how to do this, and I am not experienced enough to develop my own code and setup. Can someone point me to any opensource code or examples? Or offer any guidance? Thank you!

How accurate do those times of day need to be? The Arduino by itself is a poor time keeper in terms of time of day. Use a Real Time Clock (RTC) to keep time. Then it is not hard to compare the current time to the required turn on and turn off times and take appropriate action. There are libraries for each of the RTC modules that will help with that. I like the DS3231 RTC modules.

Is there a way I could avoid an RTC by using a really large delay between times, or would this run into the same issue?

Sure you can. Use delay if there is absolutely nothing else (like a manual turn on or off or abort) that has to happen during the delay time. The delay() function completely blocks execution (except interrupts). Avoid interrupts until you have some experience.

Or use millis() to do the timing. Other things, like a manual turn on or off or abort, can be sensed while executing a millis() delay.
Non-blocking timing tutorials:
Blink without delay().
Beginner's guide to millis().
Several things at a time.

But, like I said, the timing will not be very accurate and will drift. If what you want to happen at 5 PM one day might drift so that it happens at 6 PM a few days later.

The other issue with delay is that if the power goes out briefly, the timing will be way off until you take action to fix it.

1 Like

+1 for what @wildbill said.

RTC modules are cheap and really not difficult to program. The RTC libraries come with examples that will help a lot. And most, if not all, of the RTC come with battery backup so they will not lose time in a power outage.

Ok, thank you! I might try several different setups then. For the millis(), can you recommend a tutorial for adapting that to a stepper motor? I appreciate the help!

I don't know what that means. I linked the best tutorials that I know of in reply #4.

Write some code. If you have trouble, post the code and a description of what the code actually does (does not work is no description) and how that differs from what you want. Then we can help you to make your project a reality.

Read the forum guidelines to see how to properly post code and some hints on how to get the most from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Ok, thanks!

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