288YJ-48 Motor Continuously Spinning in a 2 Motor (Joystick Controlled) Setup

I'm sorry if this is in the wrong place, but here goes.

I've included a picture below of the code I'm using (it won't let me upload a picture of my wiring), but I have 1 Arduino linked to a Joystick that controls 2 drivers and stepper motors (all from a UNO R3 Kit). My problem is that the y-axis motor is constantly spinning (receiving the command to rotate in one direction). I've checked my wiring and changed out most of these parts, but the strange thing is that if I switch which driver is plugged into pins 8, 10, 9, and 11, it's the one plugged into those pins that will spin continuously. Do y'all have any suggestions? I'm really quite unsure as to what to try next.

A picture of the physical setup.

Read the forum guidelines to see how to properly post code. Images of code are nearly worthless. I cannot copy the code to a text editor or the IDE for examination.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Photos of the setup are great if we can clearly see where each wire goes and the photos are labeled. Please include a schematic. Schematics are less ambiguous.

I see you are defining the word "STEPS" in two different locations. Why?
Paul

#include <Stepper.h>
#define STEPS 2038 // the number of steps in one revolution of your motor (28BYJ-48)
Stepper stepper(STEPS, 8, 10, 9, 11);
Stepper stepper1(2038, 2, 4, 3, 5);
int potState = 0; 
int pot1State = 0;
void setup() {
  Serial.begin(9600); 
 }
 void loop() {
  potState = analogRead(A0); // y
  pot1State = analogRead(A1); // x
  
  Serial.println(pot1State);
  stepper.setSpeed(5);
  stepper1.setSpeed(5);

  if (potState > 600){
    stepper.step(10);
  }
  
  if (potState < 400){
    stepper.step(-10);
  }

  if (pot1State < 400){
    stepper1.step(-10);
  }
  if (pot1State > 600){
    stepper1.step(10);
  }
  
  }

Thanks for letting me know, I'm more asking about the code to see if there's things to change, I've check my wiring so much the picture was mainly for the context. I based the wiring off of the following image, but supplied power/GND to the two drivers using the small breadboard.

Does it work better when you have only ONE "STEPS"?
Paul

I'm afraid I sourced this code from someone else who was sharing their work for free use, I'm not very good at coding. Here's the link to the Project Board site if you want to see it.

Control 2 stepper motors with a joystick - Arduino Project Hub

It works the same, just a variable I think. If I change 'STEPS,' I have to change all occurrences and it doesn't change anything.

If you say so.

The problem is with 'stepper' (not 'stepper1') which is controlled by 'potState' (not 'pot1State'). I would add:

  Serial.print(potState);
  Serial.print(' ');

just before:
Serial.println(pot1State);

That way you can check the input value. If it is always above 600 or below 400 that would explain why the stepper does not stop moving.

Thank you so much! Turns out I was looking at the other input value, which needs a different parameter I suppose. I really appreciate it :). That will be perfect.

If you are going to post a image that is missing GND, use a editor and draw in the wiring changes.

image

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.