Stepper Motor Issue (Buzzing)

Hello! I am a beginner when it comes to arduino. I'm trying to have two joysticks move two stepper motors (left/right, and up/down). However, When testing it out, the stepper motor just buzzes when it's on.

Here is my frizting photo (I am new, sorry it is sloppy). FYI: for A11, it was suppose to be for VRY, not SW.

I'll also post my code:

#include <Stepper.h>

const int stepsPerRevolution = 2048;  // Number of steps per revolution for your stepper motor
const int rolePerMinute = 15;
const int X_pin = 8; // Analog pin connected to X output
const int Y_pin = 11; // Analog pin connected to Y output

// Declare two separate stepper motor objects
Stepper X_stepper(stepsPerRevolution, 22, 24, 26, 28);  // X-axis motor
Stepper Y_stepper(stepsPerRevolution, 31, 33, 35, 37);  // Y-axis motor (change pins as needed)

void setup() {
  X_stepper.setSpeed(rolePerMinute);  // Set speed for X-axis motor
  Y_stepper.setSpeed(rolePerMinute);  // Set speed for Y-axis motor
  Serial.begin(9600);
}

void loop() {
  // X-axis control
  Serial.print("X-axis: ");
  int a = analogRead(X_pin);
  Serial.println(a);
  
  if (a > 400 && a < 520) {  // Neutral zone
    // Stop the X motor
    for (int i = 2; i < 6; i++) {
      digitalWrite(i, LOW);
    }
  } else if (a < 400) {  // Move backward (left)
    X_stepper.setSpeed(rolePerMinute);
    X_stepper.step(-30);
  } else if (a > 530) {  // Move forward (right)
    X_stepper.setSpeed(rolePerMinute);
    X_stepper.step(30);
  }

  // Y-axis control
  Serial.print("Y-axis: ");
  int b = analogRead(Y_pin);
  Serial.println(b);

  if (b > 400 && b < 520) {  // Neutral zone
    // Stop the Y motor
    for (int i = 6; i < 10; i++) {
      digitalWrite(i, LOW);
    }
  } else if (b < 400) {  // Move down
    Y_stepper.setSpeed(rolePerMinute);
    Y_stepper.step(-30);
  } else if (b > 530) {  // Move up
    Y_stepper.setSpeed(rolePerMinute);
    Y_stepper.step(30);
  }
}

More important to debugging your project, what are the values you are seeing on the serial monitor for your two joysticks? Do they change as you move the joysticks? Do they fit the ranges you have coded in your program?

Yes they do! The stepper motor is just not spinning, but the LEDS on the driver is on.

Do what? Fit within the ranges you programmed? What are some of the values?

Yes they fit into the ranges I programmed with. For example, right now the x joystick is at 504. When I slide it to the left, it decrease and goes down to 0 if I push it all the way. When I push it to the right, the max is 1015.

Also the LEDs on the driver keep alternating from A to C and B to D whenever I keep on moving the joystick, which is not suppose to happen.

Ok, now what power supply do you have for the motors and doe each motor have it's own supply?

What do you mean? Like 5V?

Well, we don;t know what stepper motors you are using, so how are you powering them? A single tiny stepper could be powered by the 5 volts from an Arduino, but two certainly could not be.

Oh, the stepper motors are 28BYJ-48 5VDC, and the drivers are ULN2003AN

And the power supply for the two motors?

Reduce speed to 10 RPM.
If that does not help, change this:

Stepper X_stepper(stepsPerRevolution, 22, 24, 26, 28);

To:

Stepper X_stepper(stepsPerRevolution, 22, 26, 24, 28);

And this:

Stepper Y_stepper(stepsPerRevolution, 31, 33, 35, 37);

To:

Stepper Y_stepper(stepsPerRevolution, 31, 35, 33, 37);

Hi, @graces101
Welcome to the forum.

Can I suggest you leave your code for a while and run one of the example codes in the stepper library.
Just a simple code to make sure your hardware is good.

Can you post some images of your project?
So we can see your component layout.

What is your 5V supply for the steppers?

Do you have a DMM? (Digital MultiMeter)

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Hey, it worked but, it is like stopping and going (I dont know if that makes sense). I did test it with this single code and it worked smoothly. Here is the basic code:

#include <Stepper.h>

const int stepsPerRevolution = 2048;  // change this to fit the number of steps per revolution
const int rolePerMinute = 10;
const int X_pin = 8; // analog pin connected to X output

Stepper myStepper(stepsPerRevolution, 22, 26, 24, 28);
void setup() {
  myStepper.setSpeed(rolePerMinute);
  
  //Serial.begin(9600);

}

void loop() {
//  Serial.print("X-axis: ");
//  Serial.println(analogRead(X_pin));
  int a = analogRead(X_pin);
  if (a > 400 && a < 520)
  {
    for (int i = 2; i < 6; i++)
    {
      digitalWrite(i, LOW);
    }
  }
  else if (a < 400)
  {
    myStepper.setSpeed(rolePerMinute);
    myStepper.step(-30);
  }
  else if (a > 530)
  {
    myStepper.setSpeed(rolePerMinute);
    myStepper.step(30);
  }



}

Hello! Here is the basic code I ran for 1 stepper motor and it seems to be running smoothy.

However, now that I applied user JCA34F's suggestion to the code I originally had, it moves but it stops and goes. So it's overall slower. Also I will check if I have a DMM.




I will admit, I have other things attach to this for a bigger project I'm doing along with the joysticks, but it is attached to the other breadboard (not shown)

#include <Stepper.h>

const int stepsPerRevolution = 2048;  // change this to fit the number of steps per revolution
const int rolePerMinute = 10;
const int X_pin = 8; // analog pin connected to X output

Stepper myStepper(stepsPerRevolution, 22, 26, 24, 28);
void setup() {
  myStepper.setSpeed(rolePerMinute);
  
  //Serial.begin(9600);

}

void loop() {
//  Serial.print("X-axis: ");
//  Serial.println(analogRead(X_pin));
  int a = analogRead(X_pin);
  if (a > 400 && a < 520)
  {
    for (int i = 2; i < 6; i++)
    {
      digitalWrite(i, LOW);
    }
  }
  else if (a < 400)
  {
    myStepper.setSpeed(rolePerMinute);
    myStepper.step(-30);
  }
  else if (a > 530)
  {
    myStepper.setSpeed(rolePerMinute);
    myStepper.step(30);
  }



}

I am powering them both by 5V from the Arduino Mega

Have you measured the 5 volts while powering the steppers? Try a separate 5 volt supply, but connect the - of the supply to the arduino ground.