Turning motor in one direction

I am wanting to turn my motor in only one direction. Below is the code I am using. I took out the last two lines of the code expecting the motor to only turn one way, but it still does 2 revolutions cw and 2 revolutions ccw. Any suggestions on what I should add/delete?

#define stepPin 5
#define dirPin 2


void setup() {


pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);


}


void loop() {


digitalWrite(dirPin, HIGH); //sets which direction shaft rotates


//makes 800 pulses for making 4 revolutions
for(int x = 0; x < 800; x++) {


digitalWrite(stepPin, HIGH);
delayMicroseconds(37500 );
digitalWrite(stepPin, LOW);
delayMicroseconds(37500);


}
}




Which "two lines"? If it was these two, the code won't compile without errors.

}
}

Could you check the wiring of the 4 wires to the stepper motor ?

When I use the wiring in a common way, then the stepper motor turns in one direction.
It can be useful to use the Serial Monitor and add a pause.

Your sketch works in a simulation:

Are you sure you posted the correct sketch ???

As long as the state of dirPin is not changed the direction of the shaft should not change at all.

Could you please post the code you started with (before making changes)?

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.