Step Motor 28BYJ-48 ULN2003 Driver Board and UNO R3 Project Advice

Hello,

I have my step motor operating with a code that gives half rotation clockwise and then half rotation counter clockwise. I wonder if it is possible to programme for a narrower angle than 180 degrees movement, for example 90 degrees?

I'm using step motor: 28BYJ-48, ULN2003 driver board and UNO R3

Many thanks for any advice.

You need to post your program.

You can make a stepper motor move by as many or as few steps as you wish.

...R

Watch this YouTube video:

https://www.youtube.com/watch?v=0qwrnUeSpYQ&list=PLN0OZKrXk7Tp6WILmSXHjaBR2hJRyrZP9&index=60&t=0s

  //
  #define STEPPER_PIN_1 9
  #define STEPPER_PIN_2 10
  #define STEPPER_PIN_3 11
  #define STEPPER_PIN_4 12
  int step_number = 0;
 void setup() { 
  pinMode(STEPPER_PIN_1, OUTPUT);
  pinMode(STEPPER_PIN_2, OUTPUT);
  pinMode(STEPPER_PIN_3, OUTPUT);
  pinMode(STEPPER_PIN_4, OUTPUT);
  
}

void loop() {

  for(int a = 0; a < 1000; a ++){
    OneStep(false);
    delay(2);
  }
  
  for(int a = 0; a < 1000; a ++){
    OneStep(true);
    delay(2);
  }
    
  }

  void OneStep(bool dir){
    if(dir){
      switch(step_number){
      case 0:
      digitalWrite(STEPPER_PIN_1, HIGH);
      digitalWrite(STEPPER_PIN_2, LOW);
      digitalWrite(STEPPER_PIN_3, LOW);
      digitalWrite(STEPPER_PIN_4, LOW);
      break;
      case 1:
      digitalWrite(STEPPER_PIN_1, LOW);
      digitalWrite(STEPPER_PIN_2, HIGH);
      digitalWrite(STEPPER_PIN_3, LOW);
      digitalWrite(STEPPER_PIN_4, LOW);
      break;
      case 2:
      digitalWrite(STEPPER_PIN_1, LOW);
      digitalWrite(STEPPER_PIN_2, LOW);
      digitalWrite(STEPPER_PIN_3, HIGH);
      digitalWrite(STEPPER_PIN_4, LOW);
      break;
      case 3:
      digitalWrite(STEPPER_PIN_1, LOW);
      digitalWrite(STEPPER_PIN_2, LOW);
      digitalWrite(STEPPER_PIN_3, LOW);
      digitalWrite(STEPPER_PIN_4, HIGH);
    
    }
      }else{
        switch(step_number){
      case 0:
      digitalWrite(STEPPER_PIN_1, LOW);
      digitalWrite(STEPPER_PIN_2, LOW);
      digitalWrite(STEPPER_PIN_3, LOW);
      digitalWrite(STEPPER_PIN_4, HIGH);
      break;
      case 1:
      digitalWrite(STEPPER_PIN_1, LOW);
      digitalWrite(STEPPER_PIN_2, LOW);
      digitalWrite(STEPPER_PIN_3, HIGH);
      digitalWrite(STEPPER_PIN_4, LOW);
      break;
      case 2:
      digitalWrite(STEPPER_PIN_1, LOW);
      digitalWrite(STEPPER_PIN_2, HIGH);
      digitalWrite(STEPPER_PIN_3, LOW);
      digitalWrite(STEPPER_PIN_4, LOW);
      break;
      case 3:
      digitalWrite(STEPPER_PIN_1, HIGH);
      digitalWrite(STEPPER_PIN_2, LOW);
      digitalWrite(STEPPER_PIN_3, LOW);
      digitalWrite(STEPPER_PIN_4, LOW);
    }
      }
      step_number++;
      if(step_number > 3){
        step_number = 0;

}
  }

Robin2:
You need to post your program.

You can make a stepper motor move by as many or as few steps as you wish.

…R

Robin2:
You need to post your program.

You can make a stepper motor move by as many or as few steps as you wish.

…R

In this piece of code

  for(int a = 0; a < 1000; a ++){
    OneStep(false);
    delay(2);
  }

the number 1000 determines how many steps are taken and the number 2 determines how fast the motor moves.

This would be more obvious if variables with meaningful names are used in place of the “magic” numbers - for example

  for(int a = 0; a < numberOfSteps; a ++){
    OneStep(false);
    delay(intervalBetweenSteps);
  }

And at the top of the program you could define the variables as

int numberOfSteps = 1000;  // or whatever number you want
int intervalBetweenSteps = 2;

…R

Thank you for your reply. How would I adapt my code to narrow the degree of revolution from a half revolution to a quarter revolution?

Tell us what this does:
for(int a = 0; a < 1000; a ++)

jarjam:
Thank you for your reply. How would I adapt my code to narrow the degree of revolution from a half revolution to a quarter revolution?

I had hoped you would be able to figure that out from what I wrote in Reply #4

…R

1 rev for a 28BYJ-48 is 2048 full steps, 512 for a quarter rev.

Try experimenting.

Change 1000 to 500 etc.

for(int a = 0; a < 500; a ++)

larryd:
Tell us what this does:
for(int a = 0; a < 1000; a ++)

Perfect! Thank you for help and speedy replys, much appreciated.