how to control a stepper motor with a4988 driver and arduino code example
Example 1: tb6600 stepper motor driver arduino code
int PUL=7;
int DIR=6;
int ENA=5;
void setup() {
pinMode (PUL, OUTPUT);
pinMode (DIR, OUTPUT);
pinMode (ENA, OUTPUT);
}
void loop() {
for (int i=0; i<6400; i++)
{
digitalWrite(DIR,LOW);
digitalWrite(ENA,HIGH);
digitalWrite(PUL,HIGH);
delayMicroseconds(50);
digitalWrite(PUL,LOW);
delayMicroseconds(50);
}
for (int i=0; i<6400; i++)
{
digitalWrite(DIR,HIGH);
digitalWrite(ENA,HIGH);
digitalWrite(PUL,HIGH);
delayMicroseconds(50);
digitalWrite(PUL,LOW);
delayMicroseconds(50);
}
}
Example 2: l298n stepper motor driver
const int stepsPerRevolution = 200;