I am using unipolar 1.8 degree stepper motor. I have written code to rotate stepper motor i.e. when A0 pin becomes HIGH it should rotate in clockwise and when A1 pin becomes HIGH it should move anti clockwise but motor is rotating only once when I am making A0/A1 HIGH and then stops. After that it is not rotating even if i am making A0, A1 pin high. I am very new to this please tell how to solve this problem. I am using microstepping drive, nema 17 stepper motor and Arduino Uno board.
#include <Stepper.h>
#define STEPS_PER_MOTOR_REVOLUTION 32
#define STEPS_PER_OUTPUT_REVOLUTION 32 * 200 //2048
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 9, 8);
int Steps2Take;
int buttonApin = A0;
int buttonBpin = A1;
int dirpin = 8;
int steppin = 9;
void setup()
{
pinMode(buttonApin, INPUT);
pinMode(buttonApin, INPUT);
pinMode(dirpin, OUTPUT);
pinMode(steppin, OUTPUT);
small_stepper.setSpeed(1900);
}
void loop()
{
int valA = digitalRead(buttonApin);
if (valA == HIGH)
{ digitalWrite(dirpin, HIGH);
for (int x = 0; x < 100; x++)
{ digitalWrite(steppin, HIGH);
delayMicroseconds(1000);
digitalWrite(steppin, LOW);
delayMicroseconds(1000);
}
}
int valB = digitalRead(buttonBpin);
if (valB == HIGH)
{
digitalWrite(dirpin, LOW);
for (int x = 0; x < 100; x++)
{
digitalWrite(steppin, LOW);
delayMicroseconds(1000);
digitalWrite(steppin, HIGH);
delayMicroseconds(1000);
}
}
}