2

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.

enter image description here

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

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

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


This is a schematic of my project:

schematic

simulate this circuit – Schematic created using CircuitLab

Can anyone help me to configure this? or point me into the right direction.
Any help would be greatly appreciated!

  • When you got the 28-BYJ48 stepper motor, did you also get a ULN2003 Motor driver board? – sempaiscuba Aug 25 '17 at 21:58
  • 1
    @sempaiscuba Yes, I do have a ULN2003 Motor driver board – Delagone Aug 26 '17 at 8:33
1

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 <Stepper.h>

const int stepsPerRev = 2048

// initialise the stepper library on pins 8, 9, 10 & 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); 

}
  • thank you for your answer! I will give this a try. Is it mandatory to use a separate power supply for the stepper motor? I don't think it's drawing that much current. Or do you recommend this for other reasons? I don't have an extra power adapter laying around to test this at the moment. Could I use a battery instead? – Delagone Aug 26 '17 at 9:05
  • A suitable battery will work fine, but even a small stepper motor like the 28-BYJ48 can draw up to 320mA, (160mA per winding). – sempaiscuba Aug 26 '17 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.