The Newbie and the step motor

Hi all,

I am trying to use a step motor which would be controlled by code i.e. manual switch on, rotate a certain number of times CW then pause, then rotate a similar number of times CCW until switched off.

I am starting from scratch and have found code that controls a motor by potentionmeter etc but it is the automation that is leaving me at a loss.

I would be grateful for some help folks!

Thanks in advance.

We need to know what sort of stepper motor and stepper motor driver you are using. Please post a link to the datasheet for your stepper motor.

These links may help
Stepper Motor Basics
Simple Stepper Code

also look up the AccelStepper library

...R

Hi, the stepper motor is a 28BYJ-48 and the driver is a ULN2003

I hope that's what you want?

Is your 28BYJ-48 5 volt or 12 volt? Which Arduino are you using? How fast do you want the motor to turn? How many turns? If turned off in the process of turning, should it complete the turn or stop immediately?

Hi JCA34F,

It's a 5V motor, I'm using an UNO one revolution over two seconds would be good and yes, I would like it to complet a turn when tuned off.

Thank you.

one revolution over two seconds would be good

Well, that's 30 RPM, too fast for the 28BYJ-48 with it's 64 : 1 gear ratio, but I was able to get 24 RPM using the AccelStepper library. So install that library from the IDE library manager and give this a shot.

/*
 *  Connect UNO pin 11 to ULN2003 pin 1,
 *                  10                2,
 *                  9                 3,
 *                  8                 4 
 */
#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper(4, 8, 10, 9, 11);

void setup()
{  
  // Change these to suit your stepper if you want
  stepper.setMaxSpeed(820.0);
  stepper.setAcceleration(1000.0);
  
}

void loop()
{
    static int stepsPerRev = 2048,
               turns = 4; // set number of turns here
    // If at the end of travel go to the other end
    if (stepper.distanceToGo() == 0)
      stepper.moveTo(stepsPerRev * turns);
    if (stepper.distanceToGo() == 0)
      stepper.moveTo(0);

    stepper.run();
}

Thank you for this, you have given me an 'in' and I can take it from here.

Once again, thank you for your time!