28BYJ-48 With Joystick

Hello! I am trying to get a 5V 28BYJ-48 stepper motor with a ULN2003 driver to work with a joystick. I want it so that if the x value of the joystick is below a certain value, the stepper motor will turn for a certain amount of steps and if the joystick is above a certain value, it will turn opposite for the same amount of steps. I ran the stepper motor with test code and it works just fine, so the wiring is correct to my knowledge. Once I integrate it with the joystick, it doesn't turn anymore and just vibrates.
Right now I just have one x-direction coded just to test it out. Any help is appreciated! :slight_smile:


//Includes the Arduino Stepper Library
#include <Stepper.h>

// Defines the number of steps per rotation
const int stepsPerRevolution = 2038;
#define VRX_PIN A0
#define VRY_PIN A1

int xValue = 0;
int yValue = 0;

// Creates an instance of stepper class
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
Stepper myStepper = Stepper(stepsPerRevolution, 1, 3, 2, 4);

void setup() {
  Serial.begin(9600);
}

void loop() {
  xValue = analogRead(VRX_PIN);
  yValue = analogRead(VRY_PIN);

  if(xValue < 200) {
    myStepper.setSpeed(5);
    myStepper.step(1000);
    delay(1000);
  }
}

Which controller are You using? Several controllers use I/O 0 and 1 for download and debug. Use other pins.

Try
Stepper myXStepper = Stepper(stepsPerRevolution, 2, 3, 4, 5);
Stepper myYStepper = Stepper(stepsPerRevolution, 6, 7, 8, 9);

add
if(yValue < 200) {
myYStepper.setSpeed(5);
myYStepper.step(1000);
// delay(1000);
}

Use one delay(1000); at the end of loop.

It was simply the issue of D1 being used for download and debug. I'm fairly new to Arduino, so I never knew that those pins couldn't really be used. Thanks!

mark his answer as solution

Congrats and thanks! Sometimes guesses works out well.
You're not the first member being tricked that way.