How to change speed on stepper motor

Hi all,

My stepper motor uses a specific code, since it’s plugged into a shield and not the arduino uno directly. I was wondering if someone could help me lower the rpm’s.

Here is my code:

int dirPin1 = 3;
int stepperPin1 = 2;
int dirPin2 = 7;
int stepperPin2 = 6;

void setup() {
  pinMode(dirPin1, OUTPUT);
  pinMode(stepperPin1, OUTPUT);
  pinMode(dirPin2, OUTPUT);
  pinMode(stepperPin2, OUTPUT);

void step(boolean dir,int steps){

  for(int i=0;i<steps;i++){
    digitalWrite(stepperPin1, HIGH);
    digitalWrite(stepperPin2, HIGH);
    digitalWrite(stepperPin1, LOW);
    digitalWrite(stepperPin2, LOW);

void loop(){

The delays in the calls to delayMicroseconds are setting the pulse rate.

You should look at using AccelStepper or Stepper libraries to talk to this motor. The shield just
needs step and direction inputs, so its driven just like any other chopper driver module such as
DRV8825 or A4988 stepper boards.

All of those delay() functions take time and determine the amount of time between steps (stepper speed). Best is to get rid of the delay()s and use the blink without delay (see IDE examples) method for timing. Or use a stepper library that allows you to set the speed (AccelStepper)

To use the code as is, include an argument to your step function that lets you control the delayMicrosecond() duration.

void step(boolean dir,int steps, unsigned long stepDelay)
and later 

Thank you! using delayMicrosecond() I fixed my problem :slight_smile: