Making vehicle stop in front of wall using stepper motor and ultrasonic (HELP)

Robin2:
I think you first need to deal with what people have said about the use of the pulseIn() function. I have never used it myself, but if it blocks the Arduino for a greater time than the interval between steps it would not be suitable in a one step at a time program.

If you were using a simple DC motor this would not be a problem.

...R

PS ... did you see the change I made to my previous Reply?

I tried taking another approach, would this work?

byte stepL = 2;
byte dirL = 3;
byte stepR = 4;
byte dirR = 5;
byte trig = 6;
byte son = 7;
byte button = 8;
byte ledRed = 9;
byte ledGreen = 10;
byte ledBlue = 11;
int distance = 0;
int duration = 0;
boolean buttonRead = LOW;
int steps = 0;
boolean readOut = LOW;

#include <Stepper.h>         // Stepper
Stepper links(200, 2, 3);
Stepper rechts(200, 4, 5);

void setup() {
  pinMode(2, OUTPUT);         //define pins
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, INPUT);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  left.setSpeed(200);           //set stepper speeds
  right.setSpeed(200);

}

void loop() {
  digitalWrite(trig, LOW);                    // check distance
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  duration = pulseIn(son, HIGH);
  distance = duration/29/2;            
  long distance, cm;

}
{
  if (cm > 10){
  ledGreen = 255;
  ledRed = 0;
  ledBlue = 0;
  left.setSpeed(200);
  right.setSpeed(200);
  left.step(-100);                          
  right.step(100);

}
{
  if (cm <= 10){
  ledGreen = 0;
  ledRed = 0;
  ledBlue = 0;
  left.setSpeed(0);
  right.setSpeed(0);
  left.step(0);                          
  right.step(0);

}

delay (50);