Stepper motor with limit switches for long term installation

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)