Help with controlling Nema 23 400 oz stepper and driver with an UNO.

Hi, i have looked on google to see how it is done and i only found one source. I connected it up and got the motor running, but it doesnt seem like its the best way to do it or im missing something because i cant even write simple code to just have the motor run for a few seconds and then to stop, and perhaps run the opposite direction.

here is an example of the code. pin 8 is Direction for the driver, and 9 is for the pulse. When i decrease the value of the delay, it runs faster. Ive tried to add a "break;" command to the end to stop the loop after the first iteration but i get a syntax error. Is there a standard library i need to import, as well as a library to code these things?

void setup()
{
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}

void loop()
{
digitalWrite(9, HIGH);
delayMicroseconds(500);
digitalWrite(9, LOW);
delayMicroseconds(500);
}

also, can someone clear up whats actually happening, when i set 9 to high, which means it sends 5v to the driver for how ever many seconds i set the "delay", shouldnt the motor constantly turn during that duration?

The Thread stepper motor basics may be useful.

A stepper motor moves one step for every pulse sent to the stepper driver.

The code

void loop()
{
  digitalWrite(9, HIGH);
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(500);
}

sends a step pulse every 1000 microseconds.

It could be rewritten as (and will work the same)

void loop()
{
  digitalWrite(9, HIGH);
  digitalWrite(9, LOW);
  delayMicroseconds(1000);
}

which may make things clearer and will make it easier to change the step rate as the time only needs to be changed in one place.

In the code linked to from stepper motor basics there is also an example that avoids the use of the delayMicroseconds() function. The Arduino can do nothing else during a delay().

...R

Its standard practice to send 10us pulses since that's the minimum width pulses
required by many motor drivers (due to the use of opto-couplers which are slow).

Look at AccelStepper - for a large motor you'll definitely want smooth acceleration
to get any decent performance.