#include #define HALFSTEP 8 // To know about HalfStep Stepper Motor plzz check the above mentioned link // Motor pin definitions #define motorPin1 8 // IN1 on the ULN2003 driver 1 #define motorPin2 9 // IN2 on the ULN2003 driver 1 #define motorPin3 10 // IN3 on the ULN2003 driver 1 #define motorPin4 11 // IN4 on the ULN2003 driver 1 boolean dir = true; // To check whether its moving clockwise or anti-clockwise //If true then clockwise ....else anti-clockwise // Initialize construtor with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48 AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4); void setup() { stepper1.setMaxSpeed(1000); // 1000 coz....greater than 1000 is unreliable .....as told on the info page stepper1.setAcceleration(1000); stepper1.setSpeed(1000); stepper1.moveTo(4096); // 4096 steps for 1 rotation in 28BYJ-48 – 5V Stepper Motor }//--(end setup )--- void loop() { //Change direction when the stepper reaches the target position if (stepper1.distanceToGo() == 0) { if(dir == true) { dir = !dir; // This line inverts the value of 'dir' and stores on count itself stepper1.move(-4096); //Negative sign signifies anti-clockwise direction } if(dir == false) //Does just the opposite of the above { dir = !dir; stepper1.move(4096); } } stepper1.run(); // run the stepper to the destined position //NOTE:- Whenever the run() is called the stepper is moved only 1 step to the direction assigned....so its important to call it every instance....more checking and looping before the run()is called... slows down the actual speed set initially }