Stepper motor with limit switch for sliding window

Can any one tell me how to write a code for a Stepper motor to stop after reaching the limit switch?

This is for a sliding window. The Stepper motor will rotate and close or open the window. 2 limit switches are placed on both ends. So when the limit switch is activated, the Stepper motor stops operating.

Thank you.

Loop:
Take one step
test the switch
if (switch is not activated) go to Loop

jremington:
Loop:
Take one step
test the switch
if (switch is not activated) go to Loop

Can you please write a simple sketch for me?

Have you written any sketches for the Arduino?
What hardware do you have: Arduino type, motor link, motor driver board . . . ?
How is the motor going to be mechanically linked to the window?

.

These links may be of interest
Stepper Motor Basics
Simple Stepper Code

You really do need to post a link to the datasheet for your stepper motor - there are hundreds of different models, even when the physical size is the same.

...R

I am using Arduino UNO, L298N motor driver and the spec for my stepper motor is:
http://www.ebay.com/itm/Hybrid-Stepper-Motor-for-3D-Printer-3-5kg-DIY-Maker-DFRobot-BOOOLE-/171854482079
Rack and pinion gear is connected to the motor to drive the window forward and backwards.

I have no sketch yet. Still doing my research.

Please assist me.

Thank you

An L298 is not a good choice for driving a stepper motor, and especially one like yours with a low coil resistance. You should use a specialized stepper driver such as a Pololu DRV8825

And have a look at the AccelStepper library.

...R

jremington:
Loop:
Take one step
test the switch
if (switch is not activated) go to Loop

Argh, a goto! Unclean! Unclean!

  while (switch_not_activated ())
    take_one_step () ;

MarkT:
Argh, a goto! Unclean! Unclean!

  while (switch_not_activated ())

take_one_step () ;

How about if the switch is activated?

if (switch_activated?

Well this is just the way to handle the movement to the limit and stop at the limit - I think that's
enough pointer to get you started - once you've a sketch that does something post it? (Unless
you get everything working of course, then you are sorted). You know the details of your motor
and switch and so forth, so try to at least do something with them. If you already have some
code do post it.