Stepper Motor Troubleshooting

Hi,

Does anybody have an idea why this will not work?



// William Sargent
// Stepper Motor w/LEDS


int LEDS[] = {2, 3, 4, 5, 6, 7,}; //Array to define ouput pin numbers

int number;

int setspeed;



#include <Stepper.h>

const int stepsPerRevolution = 2048;  // change this to fit the number of steps per revolution



int rolePerMinute = 0;         // Adjustable range of 28BYJ-48 stepper is 0~17 rpm



Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11); //sets outputs to be used to allow motor to spin







void setup()

// put your setup code here, to run once:

{

  for (int i = 0; i < 6; i++)

  {

    pinMode(LEDS[i], OUTPUT);  //LEDs control pins are set up as outputs

  }

  Serial.begin(9600); // sets baud rate for serial comms with Serial Monitor

  Serial.println("Select a speed between 1 and 9:"); //displays prompt on serial monitor opening

}



void loop()

// put your main code here, to run repeatedly:

{

  {

    Serial.flush();   // clear and "junk" out of the serial buffer before waiting

    while (Serial.available() == 0)

    {

      //do nothing until something enters the serial buffer

    }

    while (Serial.available() > 0)    //read the number in the serial buffer

    {

      number = Serial.read() - '0';     //remove the ASCII text offset for zero: '0'

      for (int i = 0; i < 6; i++)

        digitalWrite(LEDS [i], LOW);

    }

  }

  if (number >= 0 && number <= 9) // test to ensure correct value for motor speed is selected

  {

    if (number == 1) //if the number selected matches an 'if', the following LEDs are illuminated

    {

      setspeed = 1;

      digitalWrite (LEDS [0], HIGH);

    }

    if (number == 2)

    {

      setspeed = 3;

      digitalWrite (LEDS [0], HIGH);

      digitalWrite (LEDS [1], HIGH);

    }



    if (number == 3)

    {

      setspeed = 5;

      digitalWrite (LEDS [0], HIGH);

      digitalWrite (LEDS [1], HIGH);

      digitalWrite (LEDS [2], HIGH);

    }

    if (number == 4)

    {

      setspeed = 7;

      digitalWrite (LEDS [0], HIGH);

      digitalWrite (LEDS [1], HIGH);

      digitalWrite (LEDS [2], HIGH);

    }



    if (number == 5)

    {

      setspeed = 9;

      digitalWrite (LEDS [0], HIGH);

      digitalWrite (LEDS [1], HIGH);

      digitalWrite (LEDS [2], HIGH);

      digitalWrite (LEDS [3], HIGH);

    }

    if (number == 6)

    {

      setspeed = 11;

      digitalWrite (LEDS [0], HIGH);

      digitalWrite (LEDS [1], HIGH);

      digitalWrite (LEDS [2], HIGH);

      digitalWrite (LEDS [3], HIGH);

    }



    if (number == 7)

    {

      setspeed = 13;

      digitalWrite (LEDS [0], HIGH);

      digitalWrite (LEDS [1], HIGH);

      digitalWrite (LEDS [2], HIGH);

      digitalWrite (LEDS [3], HIGH);

      digitalWrite (LEDS [4], HIGH);

    }

    if (number == 8)

    {

      setspeed = 15;

      digitalWrite (LEDS [0], HIGH);

      digitalWrite (LEDS [1], HIGH);

      digitalWrite (LEDS [2], HIGH);

      digitalWrite (LEDS [3], HIGH);

      digitalWrite (LEDS [4], HIGH);

    }

    if (number == 9)

    {

      setspeed = 17;

      digitalWrite (LEDS [0], HIGH);

      digitalWrite (LEDS [1], HIGH);

      digitalWrite (LEDS [2], HIGH);

      digitalWrite (LEDS [3], HIGH);

      digitalWrite (LEDS [4], HIGH);

      digitalWrite (LEDS [5], HIGH);

    }



    Serial.print("Speed Selected:"); //display the selected speed in the serial monitor

    Serial.println(number);

    Serial.print("RPM:");//display the equivalent RPM in the serial monitor

    Serial.println(setspeed);

    myStepper.setSpeed(rolePerMinute = setspeed); //use the setspeed integer taken from 'number'

    myStepper.step(stepsPerRevolution);//fixed 2048 steps to allow motor to spin



    digitalWrite(8, LOW); //set the motor outputs low so the motor doesnt burn out when not asked to move

    digitalWrite(9, LOW);

    digitalWrite(10, LOW);

    digitalWrite(11, LOW);



  }

}

Define, "will not work".

Look it up. That is not what it does.

Don’t see an Arduino common GND connection ! :thinking:

The breadboard power supply will definitely over heat when it powers the stepping motor. :open_mouth:


BTW
By convention, the red wire in a power cable is usually connected to the power supply positive.


Some of your LEDs seem to be installed backwards.

image