ARDUINO
Arduino Code /* This program drives bipolar stepper motor. The motor is attached to digital pins 9 - 12 of the Arduino. Using Stepper Motor from Adafriut 200 steps/rev, 12V, 350mA Phase 1 Red and Yellow Phase 2 Green and Grey Motor Driver L293d H bridge Chip from Texas Intruments */ int button_1 = 2; int button_2 = 3; int limit1 = 4; int limit2 = 5; int val1 = 0; int val2 = 0; int val3 = 0; int val4 = 0; int stepCount = 0; const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution // for your motor Stepper myStepper(stepsPerRevolution,9,10,11,12);// initialize the stepper library on pins 9 through 12: void setup() { pinMode(button_1, INPUT); pinMode(button_2, INPUT); pinMode(limit1, INPUT); pinMode(limit2, INPUT); myStepper.setSpeed(20);// set the speed at 60 rpm: Serial.begin(9600); }// initialize the serial port: void loop() { val1 = digitalRead(button_1); val3 = digitalRead(limit1); if((val1 == HIGH) && (val3 == HIGH)) { Serial.println("clockwise");// motor turns clockwise while the button is pushed myStepper.step(1); stepCount ++; } else val1 = digitalRead(button_1); val3 = digitalRead(limit1); if((val1 == HIGH) && (val3 == LOW))//motor stops when limit switch activated { Serial.println("stop"); myStepper.step(0); } else val2 = digitalRead(button_2); val4 = digitalRead(limit2); if((val2 == HIGH) && (val4 == HIGH)) { Serial.println("anticlockwise");// motor turns anticlockwise while the button is pushed myStepper.step(-1); stepCount ++; } else val2 = digitalRead(button_2); val4 = digitalRead(limit2); if((val2 == HIGH) && (val4 == LOW))//motor stops when limit switch activated { Serial.println("stop"); myStepper.step(0); } }