Hello Folks,
I am using EasyDriver and Arduino UNO to control a stepper motor (200 step/rev). My target is to run in a specific speed up to specific steps. For example, I want to run 20 rpm for 300 step (or 1.5 rev, or 2400 micro-steps etc.)
By using Timer1 library and attached code I have been able to run for specific time.
#include "TimerOne.h"
int Distance = 0; // Record the number of steps we've taken
int time_count = 0;
int i =0;
void setup() {
// initialization for stepper motor
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
// initialization of timer1
Timer1.initialize (50000); // initialize timer1, and set a 1/2 second period
Timer1.attachInterrupt (callback); // attaches callback() as a timer overflow interrupt
Serial.begin (9600); // open the serial port at 9600 bps:
}
void callback () {
time_count = time_count + 1; // increment timer_count value
}
void loop() {
digitalWrite(9, HIGH);
delayMicroseconds(10000);
digitalWrite(9, LOW);
delayMicroseconds(10000);
Distance = Distance + 1; // record this step
Serial.print ("\ntime value is now:"); // prints a label
Serial.print (time_count); // prints a label
if(time_count >200)
{
Serial.print("\n Timer Out"); // prints a label
Serial.print(time_count); // prints a label
for(;;)
{
Serial.print("now stop");
Serial.print("Timer Out\n");
delay(1000);
}
}
}
After that it stops. I could not control directly by commanding number of steps/micro-steps to run. In addition, using this code, if I change the delayMicroseconds (in void loop), the speed of motor is supposed to change. But it is not??? ![]()
Can anyone help me to correct or to give me a full code to control my stepper motor? That would be GREAT help for me. Thank you very much for your time.
I used this wiring and the details of my stepper (0.4A/phase and 30 ohm/phase) is here

