End Switch for a ultrasonic range finder controlled stepper

Hey, this is my first post.

I need an end switch for a project involving a ultrasonic range finder for controlling a stepper motor, and im kind of troubled about the programing part.

The end switch would be for stopping the stepper once it reaches it and holding its position for as long as the reading is = to certain value or higher.

the electronics are a MaxBotix Ultrasonic Range Finder - MB1010 LV-MaxSonar-EZ1, a TB6560 stepper driver, and an arduino uno

this is the code as far as i've got it

float cm = 0.00;
float pcm = cm; //cm previo = cm actual
int SonarPin = A0;
int sensorValue;

void setup() {
pinMode(SonarPin, INPUT);
Serial.begin(9600);
// Stepper config
stepper.setMaxSpeed(5000.0);
stepper.setSpeed(1000);
stepper.setAcceleration(9000.0);
}

void loop() {
readSonar();
if (abs(cm - pcm > 5)) { //calcula delta entre lectura actual y lectura anterior
gotoPosition(cm); //si es menor a 10, va a la posición leída
}
}

void readSonar() {
pcm = cm;
sensorValue = analogRead(SonarPin); //lee el valor de entrada del sensor
delay(10);
Inch = (sensorValue * 0.497); //calculo en pulgadas
cm = Inch * 2.54; //calculo en cms
}

void gotoPosition(float target) {
float newPos = map(target, 0, 100, 0, 8000);
Serial.print("cm = ");
Serial.print(cm);
Serial.print(" - new position = ");
Serial.println(newPos);
stepper.runToNewPosition(newPos);
}

  float newPos = map(target, 0, 100, 0, 8000);

The map() function does NOT return a float. For scaling by 80, map() is wasteful.

The end switch would be for stopping the stepper once it reaches it

You need to post a diagram. What is the relationship between the stepper, the switch, and the sonar?

this is the code as far as i've got it

Which does nothing about reading the state of a pin with a switch connected to it. What IS the problem?