Control KP39EM2-006 Stepper Motor by Arduino

Control KP39EM2-006 Stepper Motor by Arduino

This post for Kiheon, Han.

Schematic

Imgur

Arduino

int x;
void setup() {
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  digitalWrite(6, LOW);
  Serial.begin(9600);
}

void loop() {
  if (Serial.available()) {
    char c = Serial.read();
    if (c == 'a') {
      //clockwise
      Serial.println("Clockwise");
      digitalWrite(4, HIGH);

      for (x = 0; x < 800; x++)
      {
        digitalWrite(5, HIGH);
        delayMicroseconds(500);
        digitalWrite(5, LOW);
        delayMicroseconds(500);
      }
      delay(1000);

      Serial.println("Counter Clockwise");
      digitalWrite(4, LOW);
      for (x = 0; x < 800; x++)
      {
        digitalWrite(5, HIGH);
        delayMicroseconds(500);
        digitalWrite(5, LOW);
        delayMicroseconds(500);
      }
      delay(1000);
    }
  }
}