Move stepper by steps.

The stepper driver I am using.

The stepper I am using.
jk42hs34-0404 nema 17

So I searched a lot on the internet about how to move a stepper by steps like a servo.
I am trying to build a robotic arm with two steppers, but to do that I need to make it move a certain amount of steps.

Here is my code to make it the two steppers move back and forth:

int Distance = 0;
void setup(){
pinMode(8, OUTPUT);

pinMode(9, OUTPUT);

pinMode(10, OUTPUT);

pinMode(11, OUTPUT);

digitalWrite(8, LOW);

digitalWrite(9, LOW);

digitalWrite(10, LOW);

digitalWrite(11, LOW);

void loop() {

digitalWrite(8, HIGH);
digitalWrite(10, HIGH);


digitalWrite(8, LOW);
digitalWrite(10, LOW);


Distance = Distance + 1;

if (Distance == 6400) { 

if (digitalRead(9) == LOW) {

digitalWrite(11, HIGH);
digitalWrite(9, HIGH); }

else {

digitalWrite(11, LOW);
digitalWrite(9, LOW);


Distance = 0; 



How do I move the stepper to the steps i want Ex: move the stepper to the 153rd step.


The university of new orleans robotics club has a guide of motion workshops that may be able to help: They use “bit-banging” with specific registers.

here’s some pseudocode that uses digitalWrite() that may help as well:

const int MOTOR = 8; //whatever pin number step is connected to
const int STEPS = 5000; //number of steps you want to move

for (int i =0; i < STEPS; i++) {

digitalWrite(MOTOR, HIGH);
delayMicroseconds(1000); //change this delay to change the speed of the motor
digitalWrite(MOTOR, LOW); //you may have to adjust the step mode. this code assumes 1/4 step


You may also have a problem that your driver does not have a 5V threshold voltage. Check the data sheet to see if you can trigger it with an arduino.

Another helpful thing are these drivers from pololu: Pololu - DRV8825 Stepper Motor Driver Carrier, High Current

What are pins 8, 9, 10 and 11 connected to?
It would be better for the pin numbers to be represented by variable names indicating what they do.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile: