Control a Stepper Motor using a Joystick and an Arduino

Hey guys .

So i have a small issue that i am unable to solve right now. i am doing a project and i got stuck at coding.

I am using a stepper motor, easy driver , joystick and arduino nano.

now the code was taken from this link right here: https://www.brainy-bits.com/stepper-motor-easy-driver/

But this guy is dealing from the middle to either ends.

I want to start from the end to the max step ie 3200

can someone help me here please.

#define step_pin 3 // Pin 3 connected to Steps pin on EasyDriver
#define dir_pin 2 // Pin 2 connected to Direction pin
#define MS1 5 // Pin 5 connected to MS1 pin
#define MS2 4 // Pin 4 connected to MS2 pin
#define SLEEP 7 // Pin 7 connected to SLEEP pin
#define X_pin A0 // Pin A0 connected to joystick x axis

int direction; // Variable to set Rotation (CW-CCW) of the motor
int steps = 1600; // Assumes the belt clip is in the Middle

void setup() {
pinMode(MS1, OUTPUT);
pinMode(MS2, OUTPUT);
pinMode(dir_pin, OUTPUT);
pinMode(step_pin, OUTPUT);
pinMode(SLEEP, OUTPUT);

digitalWrite(SLEEP, HIGH); // Wake up EasyDriver
delay(5); // Wait for EasyDriver wake up

/* Configure type of Steps on EasyDriver:
// MS1 MS2
//
// LOW LOW = Full Step //
// HIGH LOW = Half Step //
// LOW HIGH = A quarter of Step //
// HIGH HIGH = An eighth of Step //
*/

digitalWrite(MS1, LOW); // Configures to Full Steps
digitalWrite(MS2, LOW); // Configures to Full Steps

}

void loop() {
while (analogRead(X_pin) >= 0 && analogRead(X_pin) <= 100) {
if (steps > 0) {
digitalWrite(dir_pin, HIGH); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(step_pin, HIGH);
delay(1);
digitalWrite(step_pin, LOW);
delay(1);
steps–;
}
}

while (analogRead(X_pin) > 100 && analogRead(X_pin) <= 400) {
if (steps < 800) {
digitalWrite(dir_pin, LOW); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(step_pin, HIGH);
delay(1);
digitalWrite(step_pin, LOW);
delay(1);
steps++;
}
if (steps > 800) {
digitalWrite(dir_pin, HIGH);
digitalWrite(step_pin, HIGH);
delay(1);
digitalWrite(step_pin, LOW);
delay(1);
steps–;
}
}

while (analogRead(X_pin) > 401 && analogRead(X_pin) <= 600) {
if (steps < 1600) {
digitalWrite(dir_pin, LOW);
digitalWrite(step_pin, HIGH);
delay(1);
digitalWrite(step_pin, LOW);
delay(1);
steps++;
}
if (steps > 1600) {
digitalWrite(dir_pin, HIGH);
digitalWrite(step_pin, HIGH);
delay(1);
digitalWrite(step_pin, LOW);
delay(1);
steps–;
}
}

while (analogRead(X_pin) > 601 && analogRead(X_pin) <= 900) {
if (steps < 2400) {
digitalWrite(dir_pin, LOW);
digitalWrite(step_pin, HIGH);
delay(1);
digitalWrite(step_pin, LOW);
delay(1);
steps++;
}
if (steps > 2400) {
digitalWrite(dir_pin, HIGH);
digitalWrite(step_pin, HIGH);
delay(1);
digitalWrite(step_pin, LOW);
delay(1);
steps–;
}
}

while (analogRead(X_pin) > 900 && analogRead(X_pin) <= 1024) {
if (steps < 3200) {
digitalWrite(dir_pin, LOW);
digitalWrite(step_pin, HIGH);
delay(1);
digitalWrite(step_pin, LOW);
delay(1);
steps++;
}
}
}

#code

Not enough information. Please read and follow the directions in the "How to use this forum" post, and post your code properly, using code tags.

Post links to the stepper motor data sheet or product page and the motor power supply.

done sir

Please edit your post to add code tags ("</>" button), as described in “How to use this forum”.

Post links to the stepper motor data sheet or product page and the motor power supply.

These links may help
Stepper Motor Basics
Simple Stepper Code

Be aware that AFAIK the Easydriver board defaults to microstepping so you may need to adjust my code to allow for that.

...R

do you have any codes for how to Control a Stepper Motor using a Joystick and an Arduino.
just a basic code sir, from 0 steps to 3200 steps.. using a joystick

If you want someone to write code for you, post on the Gigs and Collaborations forum section. You may be asked to pay for the help.