To use 28BYJ H48 as fast as possible with accelStepper.

Hi everybody,

I'm trying to simulate this movement simulation rotation - YouTube

As you can see it's quite slow but sometimes there is acceleration.

I manage the movement with the position given by Processing (positionX) to
Arduino thanks to the function stepper.moveTo(positionX).

It works rather well but at low speed.

I have also read a manner to drive the stepper motor 28BYJ H48 faster with L298D

But with the code given, I won't be able to manage positions as I do with accelStepper

I have seen that we can convert this stepper motor from unipolar to biipolar by cutting the central wire (the red one) and replugging the others wire, but I think, It rise up the couple and not the speed. Am I right?

Thanks for your lights!

Here 's the program to control the position (if we can speed it up..)

// ProportionalControl.pde
// -*- mode: C++ -*-
//
// Make a single stepper follow the analog value read from a pot or whatever
// The stepper will move at a constant speed to each newly set posiiton, 
// depending on the value of the pot.
//
// Copyright (C) 2012 Mike McCauley
// $Id: ProportionalControl.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>
#define HALFSTEP 4 //--> 2048 step. if Halfstep 8 --> 4096 pas
#define HALFSTEP 2 //--> it doesn't work

#define motorPin1  A8     // IN1 on the ULN2003 driver 1
#define motorPin2  A9     // IN2 on the ULN2003 driver 1
#define motorPin3  A10     // IN3 on the ULN2003 driver 1
#define motorPin4  A11     // IN4 on the ULN2003 driver 1

#define ANALOG_IN A7

int analog_in, positionX;

// the previous reading from the analog input
int previous = 0;


void setup()
{  
  Serial.begin (115200);
  stepper.setMaxSpeed(3000);//  15 rpm/ max?
   stepper.setAcceleration(100);
}

void loop()
{
  // Read new position
 analog_in = analogRead(ANALOG_IN);
 
// positionX= map ( analog_in, 0, 1027, 0, 4096); // hafp step 8 slow
  positionX= map ( analog_in, 0, 1027, 0, 2048); // haph step 4 faster

 }

     stepper.setAcceleration(100);
   stepper.moveTo(positionX);
  stepper.setSpeed(1000);
  stepper.runSpeedToPosition();

   // remember the previous value of the sensor
  previous = positionX;
  
  Serial.print ( "A0: " ) , Serial.println ( analog_in );
  Serial.print ( "posX: " ) , Serial.println ( positionX );
  Serial.print ( "prevoius: " ) , Serial.println ( previous );

}

Your program seems to be missing the line that creates an AccelStepper instance - something like

AccelStepper stepper ( .....

I don't imagine any other driver would be better than the ULN2003.

What is the maximum value of setSpeed() that works for you?

How much faster do you want it to move?

...R

Thanks.

Indeeed i forgot to copy/paste my entire program.

I don't remember what maximum value of setSpeed() that works for me.
But when I measure time/revolution, I can make it in 4 sec, so I can go to 15 rpm.

I have L293D to drive it.

Lastly, I would like to make one revolution "exactly" at each revolution. If I make 100 rounds, I would like to comeback at the same original point. (as good as possible).

I would like to simulate this movement I have done with Processing

Maybe, I should buy NEMA17 driven with L293D for each one?

I have seen them in Alixexpress
https://fr.aliexpress.com/item/4000130492082.html?spm=a2g0o.detail.100009.1.74863456ZyLBFc&gps-id=pcDetailLeftTopSell&scm=1007.13482.95643.0&scm_id=1007.13482.95643.0&scm-url=1007.13482.95643.0&pvid=c6e7e3c5-30e3-44a4-8621-e3c80d6a07db

What do you think about them?

bvking:
Indeeed i forgot to copy/paste my entire program.

Please post the complete program.

I don't remember what maximum value of setSpeed() that works for me.

Please run the program again and figure out what the maximum is and let us know.

...R

/* Example sketch to control a 28BYJ-48 stepper motor with ULN2003 driver board and Arduino UNO. More info: https://www.makerguides.com */

// Include the Arduino Stepper.h library:
#include <Stepper.h>

// Define number of steps per rotation:
const int stepsPerRevolution = 2048;

#define motorPin1  A8     // IN1 on the ULN2003 driver 1
#define motorPin2  A9     // IN2 on the ULN2003 driver 1
#define motorPin3  A10     // IN3 on the ULN2003 driver 1
#define motorPin4  A11     // IN4 on the ULN2003 driver 1

#define motor2Pin1  7  // IN1 on the ULN2003 driver 1
#define motor2Pin2  6   // IN2 on the ULN2003 driver 1
#define motor2Pin3  5    // IN3 on the ULN2003 driver 1
#define motor2Pin4  4     // IN4 on the ULN2003 driver 1

// Wiring:
// Pin 8 to IN1 on the ULN2003 driver
// Pin 9 to IN2 on the ULN2003 driver
// Pin 10 to IN3 on the ULN2003 driver
// Pin 11 to IN4 on the ULN2003 driver

// Create stepper object called 'myStepper', note the pin order:
Stepper myStepper = Stepper(stepsPerRevolution,motorPin1, motorPin3, motorPin2, motorPin4);
Stepper myStepper1 = Stepper(stepsPerRevolution,motor2Pin1, motor2Pin3, motor2Pin2, motor2Pin4);

void setup() {
 // Set the speed to 5 rpm:
 myStepper.setSpeed(20);
 
 // Begin Serial communication at a baud rate of 9600:
 Serial.begin(115200);
}

void loop() {
 // Step one revolution in one direction:
 Serial.println("clockwise");
 myStepper.step(stepsPerRevolution);
 // myStepper1.step(stepsPerRevolution);
 delay(500);
 
 // Step one revolution in the other direction:
 Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
//  myStepper1.step(-stepsPerRevolution);
 delay(500);
}

I can go to 20 rpm. With 21 there is rumble.
It is driven with uln2003 with 6 volt (5 volt is enough).

I don't understand why I can't control 2 motors together, whereas I can do it with the program below

// ProportionalControl.pde
// -*- mode: C++ -*-
//
// Make a single stepper follow the analog value read from a pot or whatever
// The stepper will move at a constant speed to each newly set posiiton, 
// depending on the value of the pot.
//
// Copyright (C) 2012 Mike McCauley
// $Id: ProportionalControl.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

#define HALFSTEP 4 //--> 2048 step. Si Halfstep 8 --> 4096 pas


#define motorPin1  A8     // IN1 on the ULN2003 driver 1
#define motorPin2  A9     // IN2 on the ULN2003 driver 1
#define motorPin3  A10     // IN3 on the ULN2003 driver 1
#define motorPin4  A11     // IN4 on the ULN2003 driver 1


#define motor2Pin1  7  // IN1 on the ULN2003 driver 1
#define motor2Pin2  6   // IN2 on the ULN2003 driver 1
#define motor2Pin3  5    // IN3 on the ULN2003 driver 1
#define motor2Pin4  4     // IN4 on the ULN2003 driver 1


AccelStepper stepper(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
AccelStepper stepper2(HALFSTEP, motor2Pin1, motor2Pin3, motor2Pin2, motor2Pin4);


#define ANALOG_IN A7

int analog_in, positionX;

// the previous reading from the analog input
int previous = 0;
 int positionVirtuelle;

void setup()
{  
  Serial.begin (115200);
  stepper.setMaxSpeed(3000);//  20 rpm/ max?
   stepper.setAcceleration(1000);
   stepper2.setMaxSpeed(3000);//  20 rpm/ max?
   stepper2.setAcceleration(1000);
}

void loop()
{
  // Read new position
 analog_in = analogRead(ANALOG_IN);
  // Quand le potar est au plus bas à -2048, va au dernier pas à 2048.
  // Donc, il fait un tour complet. 
// positionX= map ( analog_in, 0, 1027, 0, 4096); // hafp step 8 slow
  positionX= map ( analog_in, 0, 1027, 0, 2048); // haph step 4 faster


 }

      stepper.setAcceleration(1000);
  
   stepper.moveTo(positionX);
  stepper.setSpeed(1000);
  stepper.runSpeedToPosition();
  
      stepper2.setAcceleration(1000);

   stepper2.moveTo(positionX);
  stepper2.setSpeed(1000);
  stepper2.runSpeedToPosition();

   // remember the previous value of the sensor
  previous = positionX;
  
  Serial.print ( "A0: " ) , Serial.println ( analog_in );
  Serial.print ( "posX: " ) , Serial.println ( positionX );
  Serial.print ( "prevoius: " ) , Serial.println ( previous );

}

:o

bvking:
I can go to 20 rpm. With 21 there is rumble.

Thank you for the program.

However RPM is useless. You need to tell us the maximum steps per second that work - that is what the AccelStepper library produces.

...R

// Include the AccelStepper library:
#include <AccelStepper.h>

// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
/*
#define motorPin1  A8     // IN1 on the ULN2003 driver 1
#define motorPin2  A9     // IN2 on the ULN2003 driver 1
#define motorPin3  A10     // IN3 on the ULN2003 driver 1
#define motorPin4  A11     // IN4 on the ULN2003 driver 1
*/
#define motorPin1  7  // IN1 on the ULN2003 driver 1
#define motorPin2  6   // IN2 on the ULN2003 driver 1
#define motorPin3  5    // IN3 on the ULN2003 driver 1
#define motorPin4  4     // IN4 on the ULN2003 driver 1

#define motorInterfaceType 4

// Create a new instance of the AccelStepper class:
AccelStepper stepper(motorInterfaceType, motorPin1, motorPin3, motorPin2, motorPin4);

void setup() {

  Serial.begin(115200);
  // Set the maximum speed in steps per second:
  stepper.setMaxSpeed(682);// If ican do 20 rpm with 2048 step/revolution. Max speed should be 1 revolution each 3 sec.
  // So 2048/3 step in one sec = 682.XXX 
}

void loop() { 
  // Set the current position to 0:
  stepper.setCurrentPosition(0);

  // Run the motor forward at 620 steps/second until the motor reaches 2048 steps (1 revolutions):
  while(stepper.currentPosition() != 2048)
  {
    stepper.setSpeed(665);
    stepper.runSpeed();
  }

  delay(1000);
  Serial.println ("Motor made 1 revolution 665step/s");

  // Reset the position to 0:
  stepper.setCurrentPosition(0);

  // Run the motor backwards at -625 steps/second until the motor reaches -2048 steps (1 revolution):
  while(stepper.currentPosition() != -2048) 
  {
    stepper.setSpeed(-665);
    stepper.runSpeed();
  }

  delay(1000);
    Serial.println ("Motor made 1 revolution -665");

  // Reset the position to 0:
  stepper.setCurrentPosition(0);

  // Run the motor forward at 400 steps/second until the motor reaches 600 steps (3 revolutions):
  while(stepper.currentPosition() != 1024)
  {
    stepper.setSpeed(665);
    stepper.runSpeed();
  }

  delay(3000);
   Serial.println ("Motor made 1/2 revolution ");
}

So the speed limit is 665 step/ s.

But sometimes, there is rumble. So, I prefer 660 to make one revolution in 3.1 sec.
But , again when I change the way of rotation sometimes there is rumble >:(

If I change the ULN2003 2003 with the L298N, won't it be faster, with rumbling?
Why stepper library seems to be faster than accelstepper?
Thanks.

bvking:
So the speed limit is 665 step/ s.

As your code is nice and simple

 while(stepper.currentPosition() != 2048)
  {
    stepper.setSpeed(665);
    stepper.runSpeed();
  }

that does seem to be the case.

However you may well get a higher speed if you use acceleration. Try this

 stepper.setSpeed(1000);
 stepper.setAcceleration(200);
 while(stepper.currentPosition() != 6144) // 3 revolutions of the output shaft
  {
    stepper.run();
  }

...R

Hi,
I have changed the code as you said and now I can go to 22 rpm !.
I give here

// Include the AccelStepper library:
#include <AccelStepper.h>

// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
/*
#define motorPin1  A8     // IN1 on the ULN2003 driver 1
#define motorPin2  A9     // IN2 on the ULN2003 driver 1
#define motorPin3  A10     // IN3 on the ULN2003 driver 1
#define motorPin4  A11     // IN4 on the ULN2003 driver 1
*/
#define motorPin1  7  // IN1 on the ULN2003 driver 1
#define motorPin2  6   // IN2 on the ULN2003 driver 1
#define motorPin3  5    // IN3 on the ULN2003 driver 1
#define motorPin4  4     // IN4 on the ULN2003 driver 1

#define motorInterfaceType 4

// Create a new instance of the AccelStepper class:
AccelStepper stepper(motorInterfaceType, motorPin1, motorPin3, motorPin2, motorPin4);

void setup() {

  Serial.begin(115200);
  // Set the maximum speed in steps per second:
  stepper.setMaxSpeed(682);// If ican do 20 rpm with 2048 step/revolution. Max speed should be 1 revolution each 3 sec.
  // So 2048/3 step in one sec = 682.XXX 
  // Set at 650 step/s --> 3.15 sec / 1 revolution. --> 19.04 rpm.
  // Set the maximum acceleration in steps per second^2:
  stepper.setAcceleration(10);  // useless ???
 }
 
void loop() { 
  // Set the current position to 0:
  stepper.setCurrentPosition(0);
  Serial.println ("Motor begin 1 revolution 650step/s");
  // Run the motor forward at 650 steps/second until the motor reaches 2048 steps (1 revolutions):
  while(stepper.currentPosition() != 2048)
  {
  
    stepper.setSpeed(650);
    stepper.setAcceleration(200);
    stepper.runSpeed();
 //   Serial.print ("currentposition: "); Serial.println (stepper.currentPosition());
  }
  Serial.println ("Motor made 1 revolution 650step/s");
  delay(1000);
  

  // Reset the position to 0:
  stepper.setCurrentPosition(0);
  
    Serial.println ("Motor begin the come back");
  // Run the motor backwards at maxixum steps/second until the motor reaches -2048 steps (1 revolution):
  while(stepper.currentPosition() != -2048*3) 
  {
    stepper.setSpeed(-1000);
    stepper.setAcceleration(200);
    stepper.run();
  }
   Serial.println ("Motor made 3 revolution at X rpm");
   // I have checked thanks to the serial monitor 
   
  //12:21:55.210 -> Motor begin the come back
  //12:22:04.322 -> Motor made 3 revolution at X rpm
  //12:22:06.892 -> Motor made 1/2 revolution 

  // I need 8.112 sec to make 3 revolution--> So 1 revolution made in 2.7 s--> 60/2.7= 22,22 rpm.

  delay(1000);
   

  // Reset the position to 0:
  stepper.setCurrentPosition(0);

  // Run the motor forward at 400 steps/second until the motor reaches 600 steps (3 revolutions):
  while(stepper.currentPosition() != 1024)
  {
    stepper.setSpeed(650);
    stepper.runSpeed();
  }
Serial.println ("Motor made 1/2 revolution ");
  delay(3000);
   
}

But when I want to modulate the position with a potar, step motor react twice more slowly??

How can I give the position to the step motoring by keeping the speed ?

// ProportionalControl.pde
// -*- mode: C++ -*-
//
// Make a single stepper follow the analog value read from a pot or whatever
// The stepper will move at a constant speed to each newly set posiiton, 
// depending on the value of the pot.
//
// Copyright (C) 2012 Mike McCauley
// $Id: ProportionalControl.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

#define HALFSTEP 4 //--> 2048 step. Si Halfstep 8 --> 4096 pas


#define motorPin1  A8     // IN1 on the ULN2003 driver 1
#define motorPin2  A9     // IN2 on the ULN2003 driver 1
#define motorPin3  A10     // IN3 on the ULN2003 driver 1
#define motorPin4  A11     // IN4 on the ULN2003 driver 1


#define motor2Pin1  7  // IN1 on the ULN2003 driver 1
#define motor2Pin2  6   // IN2 on the ULN2003 driver 1
#define motor2Pin3  5    // IN3 on the ULN2003 driver 1
#define motor2Pin4  4     // IN4 on the ULN2003 driver 1



/*
#define motorPin1  13   // IN1 on the ULN2003 driver 1
#define motorPin2  12    // IN2 on the ULN2003 driver 1
#define motorPin3  11     // IN3 on the ULN2003 driver 1
#define motorPin4  10     // IN4 on the ULN2003 driver 1
*/

AccelStepper stepper(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
AccelStepper stepper2(HALFSTEP, motor2Pin1, motor2Pin3, motor2Pin2, motor2Pin4);


#define ANALOG_IN A7

int analog_in, positionX;

// the previous reading from the analog input
int previous = 0;


void setup()
{  
  Serial.begin (115200);
  stepper.setMaxSpeed(1000);//  22 rpm max
  stepper.setAcceleration(200);
  stepper2.setMaxSpeed(1000);
  stepper2.setAcceleration(200);
}

void loop()
{
  // Read new position
 analog_in = analogRead(ANALOG_IN);
  // Quand le potar est au plus bas à -2048, va au dernier pas à 2048.
  // Donc, il fait un tour complet. 
// positionX= map ( analog_in, 0, 1027, 0, 4096); // hafp step 8 slow
  positionX= map ( analog_in, 0, 1027, -2048, 2048); // haph step 4 faster

  stepper.setSpeed(650);
  stepper.runSpeedToPosition();
   stepper.setAcceleration(200);
//   stepper.moveTo(positionX);
  stepper.moveTo(2048);

   stepper2.setSpeed(650);
   stepper2.runSpeedToPosition();
   stepper2.setAcceleration(200);
  
  stepper2.moveTo(positionX);
 // stepper2.move(positionX); // no difference with above.
 

   // remember the previous value of the sensor
  previous = positionX;
  
  Serial.print ( "A0: " ) , Serial.println ( analog_in );
  Serial.print ( "posX: " ) , Serial.println ( positionX );
  Serial.print ( "prevoius: " ) , Serial.println ( previous );

}

bvking:
I have changed the code as you said and now I can go to 22 rpm !.

What did I say earlier about RPM ?

...R

Robin2:
However RPM is useless. You need to tell us the maximum steps per second that work - that is what the AccelStepper library produces.

Ok no matter about the RPM.

For my installation, I need the motor to be able to follow the virtual movement as faithfully as possible. And 20 or 23 rpm is too just.
Here's the movement :https://www.youtube.com/watch?v=kgDw_a2reSk&t=66s.

So I'm going to buy NEMA 17s.
I need 10. Can they work with L298N. Do I need a particular power supply, or 12 V, 1.5 A power supplies connected in parallel could suffice? Thanks Robin.

bvking:
So I'm going to buy NEMA 17s.

Nema 17 just means that the front face measures 1.7 inches. There are hundreds of different models. You need to choose one that has the required torque at the speed you require. Stepper motor torque falls off sharply as speed rises. The better maufacturers show graphs of torque at different speeds an voltages.

I need 10. Can they work with L298N.

No.

You need a specialised stepper motor driver. I can't make a suggestion until you have identified the particular motor that meets your need. However you should be aware that the low cost DRV8825 stepper drivers can only operate a motor that uses less than about 1.7 amps. Motors that require more current will require more expensive drivers.

In general the Arduino won't care what driver you use as they are almost all controlled by step and direction signals.

Do I need a particular power supply, or 12 V, 1.5 A power supplies connected in parallel could suffice?

For high stepper speeds you will need a higher voltage power supply. Again, without the manufacturer's graph it is impossible to be specific. I would consider 12v to be the minimum.

The total power supply current that is required will depend on the wattage needed by each motor. The power supply will need to be comfortably able to supply enough watts for all the motors as stepper motors draw full power even when stationary.

...R
Stepper Motor Basics
Simple Stepper Code

NEMA 17 is the most popular and therefore the cheapest. I have seen smaller ones, but they are more expensive and with less torque.

For my model, I want to make movements with good acceleration and deceleration (1 turn in a 1/2 s = 120 rpm) and turn most of the time between 0 and 100 rpm.

On these engines, I will fix a flat metal bar of 10-20 cm (a "square plate" in French). On the latter, I will put a ping pong ball. So that the weight is as light as possible.

So for the best fluidity and responsiveness of the movement do I need a DRV8825 driver? Or better?

bvking:
NEMA 17 is the most popular and therefore the cheapest.

It seems like you did not read the first paragraph of Reply #11 sufficiently carefully.

So for the best fluidity and responsiveness of the movement do I need a DRV8825 driver? Or better?

It seems like you did not read paragraph 3 carefully either. If the DRV8825 is suitable for your chosen motor then it will do the job perfectly well.

And did you study the links I gave you?

...R

I have just seen the NEMA 17 with the manufacturer's graph below

DRV8825 or other?

bvking:
DRV8825 or other?

As the Rated Current is only 1.2 amps the DRV8825 will be fine. In Reply #11 I mentioned that a DRV8825 can work at currents up to 1.7 amps.

Note that the graph is based on a 24v motor power supply.

...R