Better stepper method?

I am new to the Arduino, I have some very basic knowledge learned online. I have a program that will control level crossing gates on my model railway. It works very well, however I am using a simple stepper command from <stepper.h> the motor is the 28BYJ-48 with the ULN2003 driver board.


Where (gateOpen) is 512 which equates to 90 degrees of rotation. This works just fine, however I have to run the stepper slowly because I need the gate to take around 6 secs to close. While the stepper is running the program stops until it has completed. Is there a better way to do this where the program will continue to run while the stepper completes it's 512 steps?
Thanks for any ideas.

Using my crystal ball I guess that your sketch, which you have not posted (HINT), uses delay() between steps, but who knows ?

If that is the case then use millis() for timing instead of delay()
See Using millis() for timing. A beginners guide, Several things at the same time and the BlinkWithoutDelay example in the IDE

The stepper.h lib is blocking, i.e. your mystepper.step() call will not return until the movement is finished.
You could use my MobaTools lib, originally created with the model railroader in mind :wink: . This lib doesn't block while the stepper is moving. I also have an example for a level crossing with this lib, but unfortunately that is described and commented in German. But the lib contains other examples how to control a 28BYJ-48 with the ULN2003 driver board.

AccelStepper library is non-blocking.

Thanks guys, I guessed the problem was the library I will try some of your solutions. MicroBahner - haha yes, I would like to flash the warning lights continuously of course!

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