How to make a start button

Hello everybody,

I’m new to arduino controllers.

I making stepper motor controlling program.

Heres the code:

#include <AFMotor.h>
AF_Stepper motor(48, 2);

void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println(“Stepper test!”);
motor.setSpeed(150); // 10 rpm


void loop() {
motor.step(200, FORWARD, SINGLE);
motor.step(200, BACKWARD, SINGLE);

Now when i start controller my motor go to 200 steps then wait 3000 and go to 200 steps.

I want to do something like a button or anything, that i can execute command from serial port and it dones 200 steps and stops, dont do anything.

Thanks for any help.

easiest way, would be to put a toggle/momentary switch between 5V and a digital pin, and use an if (pin = high) conditional to run the code inside loop(). It would run infinitely until you turned the toggle off, or only as long as you had the momentary down.