Stepper motor with limit switches for long term installation

Hi, I am a new user of accelstepper and have some experience with arduino. Ordinarily I would take the time to research and fully understand the solutions to my problem but I have a very limited amount of time because this system is going to be installed inside a store window in several days and it will on display for an extended period of time...

I have a bipolar stepper motor being driven by a gecko (g251x) motor driver and currently using the accelstepper library. The motor is connected to an acme screw which moves an object back and forth along a single 48" axis. I would like to program a series of movements with delays and alternating direction (object goes near one end of ball screw, delay, object moves near the other end, delay, etc). My concern is as if/when someone disconnects the system, it will start up again without any memory of how far it is from the end and then just crash into the bearing blocks. I can install limit switches but I am not sure of how to incorporate them so that the system causes the motor to reverse direction and essentially re-zero the sequence in a fluid manner. The sequence is does not need to be very complicated, maybe four or five arbitrary movements back and forth with delays in between plus some contingency plan if/when the object reaches the end of travel. I am starting to get a grasp on how to go about this but I do not want to run out of time.
Thanks for any and all help.

What driver are you using for the stepper ?

I'm using a gecko g251x
http://www.geckodrive.com/geckodrive-step-motor-drives/g251x.html

The motor turns and behaves as it should using example code as well as some simple code that I have added. I just don't have a strong enough grasp of how to code something like this. Thanks.

You need to have a routine that is called from setup() which slowly (step by step) moves the system to the end of the track where the limit switch is situated. After each move check to see if the switch has been pressed. If it has you are at the Zero position.

...R

If you use a limit switch that is some distance from the hard endstop you can home the drive more rapidly, which is useful.
After homing at speed, rehome at a lower speed to gain accuracy - just reverse slowly till the switch deactivates.

MarkT:
If you use a limit switch that is some distance from the hard endstop you can home the drive more rapidly, which is useful.
After homing at speed, rehome at a lower speed to gain accuracy - just reverse slowly till the switch deactivates.

+1

...R

Here's a tutorial.

I would write some code for you but I don't have a motor to test it with so you should probably do that yourself.
(I think I'll buy a small one for software testing)