How can I swap a servo with a stepper motor? I'm looking for a way to swap servo 1 with a stepper motor to achieve a single direction circular motion with stops and delay. Instead, now I have the servo going back and forth to repeat the action.



This is the code I'm currently using to drive the servo:

void loop() {
  topServo.write(115);
  delay(500);

  for(int i = 115; i &gt; 65; i--) {
    topServo.write(i);
    delay(2);
}



This is a schematic of my project:







simulate this circuit &ndash; Schematic created using CircuitLab

Can anyone help me to configure this? or point me into the right direction.
Any help would be greatly appreciated!
Firstly, I'm going to assume that you got a ULN2003 Motor driver board something like this along with your 28-BYJ48 stepper motor.

Secondly, I would always recommend using a separate power supply for your stepper motors. Even a small stepper motor like the 28-BYJ48 can draw up to 320mA, (160mA per winding).



I've used the following code to test a setup using a 28-BYJ48 stepper motor and an Arduino. The connections to the driver board (IN1 - IN4) are mapped to pins 8-11 on the Arduino in this case. The code will cause the stepper to rotate 1 full revolution in one direction, pause for 1 second and then rotate one full revolution in the other direction.

(I've often found this simple piece of code really handy for troubleshooting!)

#include &lt;Stepper.h&gt;

const int stepsPerRev = 2048

// initialise the stepper library on pins 8, 9, 10 &amp; 11
Stepper myStepper(stepsPerRev, 8,10,9,11);        

void setup() {
  // set the speed
  myStepper.setSpeed(4);

}

void loop() {
  // step one revolution in one direction:
  myStepper.step(stepsPerRev);
  delay(1000);

  // step one revolution in the other direction:
  myStepper.step(-stepsPerRev);
  delay(1000); 

}