stepper motor control issues.

Unable to control stepper motor it just constantly turns without the joystick input, I cant control the direction or speed it is turning.

I have no idea how to make a diagram like the one in the link below to include

code and project are from - Stepper Motor Control with Arduino and Joystick - SIMPLE PROJECTS

Hardware-
Arduino UNO R3 board(prototype shield v5)
28BYJ-48 stepper motor (with 2ph85309A driver board)
Joystick
5V power source(USB cable for joystick & Arduino) stepper motor & driver board(battery pack "AA"
Bread board
Jumper wires

Any and all assistance is appreciated as I'm new to the Arduino & the forum.

Please post your program here. See How to use the forum.

...R

This is the code I'm using.

// include Arduino stepper motor library
#include <Stepper.h>
 
// define number of steps per revolution
#define STEPS 32
 
// define stepper motor control pins
#define IN1  11
#define IN2  10
#define IN3   9
#define IN4   8
 
// initialize stepper library
Stepper stepper(STEPS, IN4, IN2, IN3, IN1);
 
// joystick pot output is connected to Arduino A0
#define joystick  A0
 
void setup()
{
  
}
 
void loop()
{
  // read analog value from the potentiometer
  int val = analogRead(joystick);
 
  // if the joystic is in the middle ===> stop the motor
  if(  (val > 500) && (val < 523) )
  {
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
  }
 
  else
  {
    // move the motor in the first direction
    while (val >= 523)
    {
      // map the speed between 5 and 500 rpm
      int speed_ = map(val, 523, 1023, 5, 500);
      // set motor speed
      stepper.setSpeed(speed_);
 
      // move the motor (1 step)
      stepper.step(1);
 
      val = analogRead(joystick);
    }
 
    // move the motor in the other direction
    while (val <= 500)
    {
      // map the speed between 5 and 500 rpm
      int speed_ = map(val, 500, 0, 5, 500);
      // set motor speed
      stepper.setSpeed(speed_);
 
      // move the motor (1 step)
      stepper.step(-1);
 
      val = analogRead(joystick);
    }
 
  }
 
}

Do you have info on the 2ph85309A driver board?

I'm not sure what you're specifically looking for but, I didn't receive any paperwork with the Arduino starter kit.

Please post a photo of the driver board. The usual driver for a 28BYJ-48 stepper motor is a ULN2003.

See this Simple Image Posting Guide

...R

Not gonna down play it at all I 100% read the link you sent on how to get photos about 3 times and finally randomly fumbled my way to this. /shrug/ hope this worked!

HA! The ubiquitous ULN2003 module.
Do you have a separate 5V, 500mA power supply for the motor? You can run 1 motor from the UNO but I wouldn't risk it.
OOPS! You're running with batteries, that's OK, but we need to know how everything is wired together, can you draw a simple diagram, photograph or scan and post it?

If nothing is connected to the analog input pin, it is "floating" , picking up noise that is being interpreted as a signal, put a 10k resistor from pin to GND when the joystick is not connected.
I added a serial print so you can see the value of "val".

// include Arduino stepper motor library
#include <Stepper.h>
 
// define number of steps per revolution
#define STEPS 32
 
// define stepper motor control pins
#define IN1  11
#define IN2  10
#define IN3   9
#define IN4   8
 
// initialize stepper library
Stepper stepper(STEPS, IN4, IN2, IN3, IN1);
 
// joystick pot output is connected to Arduino A0
#define joystick  A0

uint32_t tStart, tEnd = 250;
 
void setup()
{
   Serial.begin(9600);
}
 
void loop()
{
  // read analog value from the potentiometer
  int val = analogRead(joystick);
  if(millis() - tStart > tEnd)
  {
     Serial.println(val);
     tStart += tEnd;
  }
  // if the joystic is in the middle ===> stop the motor
  if(  (val > 500) && (val < 523) )
  {
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
  }
 
  else
  {
    // move the motor in the first direction
    while (val >= 523)
    {
      // map the speed between 5 and 500 rpm
      int speed_ = map(val, 523, 1023, 5, 500);
      // set motor speed
      stepper.setSpeed(speed_);
 
      // move the motor (1 step)
      stepper.step(1);
 
      val = analogRead(joystick);
    }
 
    // move the motor in the other direction
    while (val <= 500)
    {
      // map the speed between 5 and 500 rpm
      int speed_ = map(val, 500, 0, 5, 500);
      // set motor speed
      stepper.setSpeed(speed_);
 
      // move the motor (1 step)
      stepper.step(-1);
 
      val = analogRead(joystick);
    }
 
  }
}



as for the diagram I'm not 100% sure what freeware to use. Currently looking into it and hope to have something posted soon. Any suggestions on a free software to use for this kind of thing would be helpful.
p.s. I just tried EAGLE and unless I just hadn't found the basic diagram this goes waaaaaaay beyond my understanding of electronics

.arduino uno R3 (prototype shield v5)

5v & gnd to bottom 2 rows

breadboard left side of middle divider-

.joystick


slot1 - SW to n/a
slot2 - VRY to n/a
slot3 - VRX to Arduino analog 0
slot4 - +5V to breadboard positive "by Arduino +5v"
slot5 - GND to breadboard GND "by Arduino GND"

2ph85309A driver board

stepper motor
GND - to AA power source
VCC - to AA power source
IN1 - Arduino digital 8
IN2 - Arduino digital 9
IN3 - Arduino digital 10
IN4 - Arduino digital 11

kalebkzc:
Not gonna down play it at all I 100% read the link you sent on how to get photos about 3 times and finally randomly fumbled my way to this. /shrug/ hope this worked!

[img]http://file:///C:/Users/rcowa/OneDrive/Desktop/Joystick.jpg[/img]

[...............]

As you can see it did not work. You cannot get images to show directly from files on your PC on any website. You have to upload the file to the Forum first and then make the image visible.

Please read the instructions a few more times :slight_smile:

...R

PS I added nobbc /nobbc tags around your link to make it visible

slowly figuring this out.......

I dont seem to be able to upload all of the photos on 1 post. the size of the post.

kalebkzc:
I dont seem to be able to upload all of the photos on 1 post. the size of the post.

You should be able to. Maybe you need to downsize your image files. Smaller images (640x480 is usually enough) are kinder to those of us with slow or expensive internet connections.

...R

JCA34F:
If nothing is connected to the analog input pin, it is "floating" , picking up noise that is being interpreted as a signal, put a 10k resistor from pin to GND when the joystick is not connected.
I added a serial print so you can see the value of "val".

// include Arduino stepper motor library

#include <Stepper.h>

// define number of steps per revolution
#define STEPS 32

// define stepper motor control pins
#define IN1  11
#define IN2  10
#define IN3  9
#define IN4  8

// initialize stepper library
Stepper stepper(STEPS, IN4, IN2, IN3, IN1);

// joystick pot output is connected to Arduino A0
#define joystick  A0

uint32_t tStart, tEnd = 250;

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

void loop()
{
  // read analog value from the potentiometer
  int val = analogRead(joystick);
  if(millis() - tStart > tEnd)
  {
    Serial.println(val);
    tStart += tEnd;
  }
  // if the joystic is in the middle ===> stop the motor
  if(  (val > 500) && (val < 523) )
  {
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
  }

else
  {
    // move the motor in the first direction
    while (val >= 523)
    {
      // map the speed between 5 and 500 rpm
      int speed_ = map(val, 523, 1023, 5, 500);
      // set motor speed
      stepper.setSpeed(speed_);

// move the motor (1 step)
      stepper.step(1);

val = analogRead(joystick);
    }

// move the motor in the other direction
    while (val <= 500)
    {
      // map the speed between 5 and 500 rpm
      int speed_ = map(val, 500, 0, 5, 500);
      // set motor speed
      stepper.setSpeed(speed_);

// move the motor (1 step)
      stepper.step(-1);

val = analogRead(joystick);
    }

}
}

I can't begin to count howmany times I tried a new video, tutorial, code, hardware rewiring.
I finally got it to work just now.

so what I can confirm for anyone that may read this with the same issue. . is when I went to serial monitor it was spamming randomly. which I believe is what you were calling a "floating Pin".

Since then I rewired and tried a simple potentiometer with the built-in example code "basics Analog Read Signal". Everything worked so I rewired the original project (joystick controlling step motor) **did not use a AA battery to power the stepper drive board, however, since the drive board was receiving power I don't believe this was the issue. **

So to sum up the believed issue:

  1. by using serial.print and serial monitor to view this data I had a floating pin
  2. floating pin - a pin that is neither connected to VCC or GND thus randomly outputs "on/off" or in this case the numerical values
  3. rewired which is the believed fix for this