stepper motor help

I am trying to use this code I found online that is really close to what I need. I am pretty confident that it is mostly correct. Whenever I run the code, the homing sequence works fine. When entering a distance, it shows:
"Moving stepper into position: input."
But then immediately afterwards is displays "Moving stepper into position: 0." COMPLETED!
It is supposed to just show the first line and move it. However, I think right afterwards it sets the goal position to 0 which is the initial position which stops it from moving.
I can't see where in the code the target position is being set to zero.
Any help would be appreciated

stepper_v2.ino (4.02 KB)

You are using Serial.parseInt() which and sending information with a trailing newline \n or CR+NL \r\n which gets left in the input buffer so the second time through the loop, it parses as a 0.

Read Robin's excellent tutorial on how to do Serial properly Serial Input Basics

Also, it is much better to post your code inside code tags rather than attaching it. It allows people to see it directly, like this

/*  Motor Homing code using AccelStepper and the Serial Monitor

  Created by Yvan / https://Brainy-Bits.com
  This code is in the public domain...
  You can: copy it, use it, modify it, share it or just plain ignore it!
  Thx!

*/

#include "AccelStepper.h"
// Library created by Mike McCauley at http://www.airspayce.com/mikem/arduino/AccelStepper/

// AccelStepper Setup
AccelStepper stepperX(8, 10, 9, 11); // 1 = Easy Driver interface
// NANO Pin 2 connected to STEP pin of Easy Driver
// NANO Pin 3 connected to DIR pin of Easy Driver
// I added pin 4

// Define the Pins used
#define home_switch 5 // Pin 5 connected to Home Switch (MicroSwitch) //not necessary?

// Stepper Travel Variables

long TravelX;  // Used to store the X value entered in the Serial Monitor
int move_finished = 1; // Used to check if move is completed
long initial_homing = -1; // Used to Home Stepper at startup


void setup() {
  Serial.begin(57600);  // Start the Serial monitor with speed of 9600 Bauds

  pinMode(home_switch, INPUT_PULLUP);

  delay(5);  // Wait for Driver wake up

  //  Set Max Speed and Acceleration of each Steppers at startup for homing
  stepperX.setMaxSpeed(100.0);      // Set Max Speed of Stepper (Slower to get better accuracy)
  stepperX.setAcceleration(100.0);  // Set Acceleration of Stepper


  // Start Homing procedure of Stepper Motor at startup

  Serial.print("Stepper is Homing . . . . . . . . . . . ");

  while (digitalRead(home_switch)) {  // Make the Stepper move CCW until the switch is activated
    stepperX.moveTo(initial_homing);  // Set the position to move to
    initial_homing--;  // Decrease by 1 for next move if needed
    stepperX.run();  // Start moving the stepper
    delay(5);
  }

  stepperX.setCurrentPosition(0);  // Set the current position as zero for now
  stepperX.setMaxSpeed(100.0);      // Set Max Speed of Stepper (Slower to get better accuracy)
  stepperX.setAcceleration(100.0);  // Set Acceleration of Stepper
  initial_homing = 1;

  while (!digitalRead(home_switch)) { // Make the Stepper move CW until the switch is deactivated
    stepperX.moveTo(initial_homing);
    stepperX.run();
    initial_homing++;
    delay(5);
  }

  stepperX.setCurrentPosition(0);
  Serial.println("Homing Completed");
  Serial.println("");
  stepperX.setMaxSpeed(1000.0);      // Set Max Speed of Stepper (Faster for regular movements)
  stepperX.setAcceleration(1000.0);  // Set Acceleration of Stepper

  // Print out Instructions on the Serial Monitor at Start
  Serial.println("Enter Travel distance (Positive for CW / Negative for CCW and Zero for back to Home): ");
}

void loop() {

  while (Serial.available() > 0)  { // Check if values are available in the Serial Buffer

    move_finished = 0; // Set variable for checking move of the Stepper

    TravelX = Serial.parseInt(); // Put numeric value from buffer in TravelX variable
    if (TravelX < 0 || TravelX > 1350) {  // Make sure the position entered is not beyond the HOME or MAX position
      Serial.println("");
      Serial.println("Please enter a value greater than zero and smaller or equal to 1350.....");
      Serial.println("");
    } else {
      Serial.print("Moving stepper into position: ");
      Serial.println(TravelX);

      stepperX.moveTo(TravelX);  // Set new moveto position of Stepper

      // delay(1000);  // Wait 1 seconds before moving the Stepper
    }
  }

  if (TravelX >= 0 && TravelX <= 1350) {

    // Check if the Stepper has reached desired position
    if ((stepperX.distanceToGo() != 0)) {

      stepperX.run();  // Move Stepper into position

    }

    // If move is completed display message on Serial Monitor
    if ((move_finished == 0) && (stepperX.distanceToGo() == 0)) {
      Serial.println("COMPLETED!");
      Serial.println("");
      Serial.println("Enter Travel distance (Positive for CW / Negative for CCW and Zero for back to Home): ");
      move_finished = 1; // Reset move variable
    }
  }
}

Hello,
Thanks for the advice and pointing me to the tutorial. I'll be sure to check it out.