Step Motor controlled with pullup button

Helllo,
I am not programmer, ( beginner at best)
i just make many tries and errors..
i have a 28byj-48 stepper motor and unl2003 driver connected in arduino uno the 4 pin in 8,9,10,11, and the pullup button in pin 7,
My idea is to make a motor that by pressing a pull up button will make half rev and in the thes button press will make half but in the opposite direction..
until now this is arduino... i cant understand why it count but it doesnt rotate ?

#define sm1 8
#define sm2 9
#define sm3 10
#define sm4 11
#define button_pin 7

int Pins[] = {sm1,sm2,sm3,sm4};
int button_state = 0;
int button_i = 0;
int prev_button_state = 0;

void setup() {
  Serial.begin(9600);
  pinMode (button_pin, INPUT_PULLUP); 
  for (int x=8; x<11; x++){
    pinMode(x, OUTPUT);
  pinMode (13, OUTPUT);
  }
}

void loop() {
  button_state = digitalRead(button_pin);
  if (button_state != prev_button_state) {
    if (button_state == HIGH) {
      digitalWrite(13, LOW);
      if (button_i % 2 != 0) {
        delay(100);
        int seq[][4] = {{0,0,0,1},
                        {0,0,1,0},
                        {0,1,0,0},
                        {1,0,0,0}};

        for (int x=0; x<256; x++){
          for(int step1=0; step1<4; step1++){
            for(int pin=0; pin<4; pin++){
              digitalWrite(Pins[pin], seq[step1][pin]);
            }
            delayMicroseconds(25);
          }
        }
      }
      else{
        delay(100);
        int seq[][4] = {{1,0,0,0},
                        {0,1,0,0},
                        {0,0,1,0},
                        {0,0,0,1}};

        for (int x=0; x<256; x++){
          for(int step1=0; step1<4; step1++){
            for(int pin=0; pin<4; pin++){
              digitalWrite(Pins[pin], seq[step1][pin]);
            }
            delayMicroseconds(25);
          }
        }
      }
    }else {
      digitalWrite(13, HIGH);
      button_i++;
      Serial.println(button_i);
    }
  delay(50);
  }  
prev_button_state = button_state;
} 

because arduino is not able to drive stepper motor directly

We can't either. How you suggest we find out?
Try and post schematics, no toy Fritzing pictures..
Also post links to the datasheet of driver, motor....

i have a 28byj-48 stepper motor and unl2003 driver connected in arduino uno the 4 pin in 8,9,10,11, and the pullup button in pin 7,

// Sketch to turn around one unipolar Stepper motor with ULN2003 driver

const byte Pin0 = 8;
const byte Pin1 = 9;
const byte Pin2 = 10;
const byte Pin3 = 11;
byte Step = 1;
boolean dir = true;
void setup() {
  pinMode(Pin0, OUTPUT);
  pinMode(Pin1, OUTPUT);
  pinMode(Pin2, OUTPUT);
  pinMode(Pin3, OUTPUT);
}
void loop() {
  for (byte V = 0; V < 255; V++) {
    switch (Step) {
      case 1:
        digitalWrite(Pin0, LOW);
        digitalWrite(Pin1, LOW);
        digitalWrite(Pin2, LOW);
        digitalWrite(Pin3, HIGH);
        break;
      case 2:
        digitalWrite(Pin0, LOW);
        digitalWrite(Pin1, LOW);
        digitalWrite(Pin2, HIGH);
        digitalWrite(Pin3, HIGH);
        break;
      case 3:
        digitalWrite(Pin0, LOW);
        digitalWrite(Pin1, LOW);
        digitalWrite(Pin2, HIGH);
        digitalWrite(Pin3, LOW);
        break;
      case 4:
        digitalWrite(Pin0, LOW);
        digitalWrite(Pin1, HIGH);
        digitalWrite(Pin2, HIGH);
        digitalWrite(Pin3, LOW);
        break;
      case 5:
        digitalWrite(Pin0, LOW);
        digitalWrite(Pin1, HIGH);
        digitalWrite(Pin2, LOW);
        digitalWrite(Pin3, LOW);
        break;
      case 6:
        digitalWrite(Pin0, HIGH);
        digitalWrite(Pin1, HIGH);
        digitalWrite(Pin2, LOW);
        digitalWrite(Pin3, LOW);
        break;
      case 7:
        digitalWrite(Pin0, HIGH);
        digitalWrite(Pin1, LOW);
        digitalWrite(Pin2, LOW);
        digitalWrite(Pin3, LOW);
        break;
      case 8:
        digitalWrite(Pin0, HIGH);
        digitalWrite(Pin1, LOW);
        digitalWrite(Pin2, LOW);
        digitalWrite(Pin3, HIGH);
        break;
    }
    if (dir) Step++;
    else Step--;
    if (Step > 8)Step = 1;
    if (Step < 1)Step = 8;
    delay(2);
  }
  delay(1000);
}

Repeating what You already wrote doesn't add anything.

my goal is when i press the pull-up button, the first time (i=1)
the step motor will move half circle CW (180°),
then the motor will pause until i press again the button,
the second time (i=2)
the step motor will move half circle CCW (-180°)
then again will wait until the next press of the button
....
(i=odd) -> 180° CW
(i=even) ->-180° CCW

is it better explanation ?

How are you powering the stepper?

right now via USB (com3)
after i i will plug it (AC)

That is quite likely the reason that your motor isn't rotating.

because it is connected via USB ?!
i tried the @kolaha version and it works (with AC or USB)
the problem wasnt with powering but i thing somewhere maybe my code has a flow..

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