Skip to content

Instantly share code, notes, and snippets.

@neosarchizo
Last active September 25, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neosarchizo/1134ac9acb09185ad9ea to your computer and use it in GitHub Desktop.
Save neosarchizo/1134ac9acb09185ad9ea to your computer and use it in GitHub Desktop.
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);
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment