4 Ultrasonic Sensors - Stepper Motor

#include <NewPing.h>
#define SONAR_NUM  4
#define MAX_DISTANCE 100
#define PING_INTERVAL 33

unsigned long pingTimer[SONAR_NUM];
unsigned int cm[SONAR_NUM];
uint8_t currentSensor = 0;

NewPing sonar[SONAR_NUM] = {
  NewPing(4,8,MAX_DISTANCE),
  NewPing(5,9,MAX_DISTANCE),
  NewPing(6,10,MAX_DISTANCE),
  NewPing(7,11,MAX_DISTANCE)
  };
int step_pin=2;    
int dir_pin=3;        


int run;
int startPin;

int customDelay,customDelayMapped; 
     
void setup() {
  Serial.begin(115200);
  pingTimer[0] = millis() +75;
  for(uint8_t i = 1; i<SONAR_NUM; i++)
    pingTimer[i]=pingTimer[i-1]+PING_INTERVAL;
    
   pinMode(dir_pin, OUTPUT);   
   pinMode(step_pin, OUTPUT);   
   
   digitalWrite(dir_pin, LOW); 

     run = 0;
     startPin = 13;
     pinMode(startPin,INPUT_PULLUP);
   
}

void loop() {
  customDelayMapped = speedUp();
if(digitalRead(startPin)==LOW)
{
 {
 digitalWrite(step_pin, HIGH);
  delayMicroseconds(customDelayMapped);
  digitalWrite(step_pin, LOW);
  delayMicroseconds(customDelayMapped);
 }
for (uint8_t i = 0; i < SONAR_NUM; i++) { // Loop through all the sensors.
    if (millis() >= pingTimer[i]) {         // Is it this sensor's time to ping?
      pingTimer[i] += PING_INTERVAL * SONAR_NUM;  // Set next time this sensor will be pinged.
      sonar[currentSensor].timer_stop();          // Make sure previous timer is canceled before starting a new ping (insurance).
      currentSensor = i;                          // Sensor being accessed.
      cm[currentSensor] = 0;                      // Make distance zero in case there's no ping echo for this sensor.
      sonar[currentSensor].ping_timer(echoCheck); // Do the ping (processing continues, interrupt will call echoCheck to look for echo).
    }
  }

if (cm[0]==15)
 {digitalWrite(step_pin,LOW);
 delayMicroseconds(customDelayMapped);}
  
}
}
  void echoCheck() { // If ping received, set the sensor distance to array.
  if (sonar[currentSensor].check_timer()) {
    cm[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM;
    pingResult(currentSensor);
  }
}
  void pingResult(uint8_t sensor) { // Sensor got a ping, do something with the result.
  // The following code would be replaced with your code that does something with the ping result.
  Serial.print(sensor);
  Serial.print(" ");
  Serial.print(cm[sensor]);
  Serial.println("cm");
}

 
  
  int speedUp() {
    int customDelay = analogRead(A0); 
    int newCustom = map(customDelay, 1023, 0, 0,1600); 
    return newCustom;
  
  }

I want to do a conveyor belt with 4 distance sensor to stop a thing in middle of belt
I have a stepper motor(with EasyDriver), on off button and a potentiometer for speed controll…
Can someone help me please?

Can someone help me please?

Not with the little information you provided. We have no ideal how the sensors are oriented or how large the structure is.

It is not clear why you need 4 sensors.

  void pingResult(uint8_t sensor) { // Sensor got a ping, do something with the result.

But not anything useful...

Just setting the step pin LOW will not be sufficient. You cause stepping to happen by setting the pin LOW then HIGH, NOT just by setting it LOW and leaving it there.

So, sensor will tell me dimension for one box for example and i want to stop the box in middle of belt. Belt have 40 cm lenght and 15 width. All sensor are directed to center of belt....(Sorry for my bad english)

I need all 4 sensor because i wanna know dimensions of box. A robotic arm will come and get the box, and i want to know how much i need to open the claw.

I don't know what problem you are having. You are currently reading 4 sensors, though not doing anything useful with the data.

You need to make the conveyor move, somehow, until two readings are equal. Then, your box, of unknown size will be centered (approximately) in left-to-right direction. I don't see how you will move the box in the other direction, so I don't know how you will center it front-to-back.

I dont want to center it front-back ... that 2 sensor are just for know width and position of box ....

So, what do you need help with?

I want to tell me how i stop the motor when the box is center, and tell me why the 4th sensor didnt apear on serial monitor (sensor its fine)....

symysan:
I want to tell me how i stop the motor when the box is center, and tell me why the 4th sensor didnt apear on serial monitor (sensor its fine)…

First of all you need some means to know where the centre is.
Then you need to know whether you are before the centre position, at the centre position or after the centre position.

When you have all that figured the stepper code should be straightforward - like this pseudo code

readSensors and figure out values
   if (centrePos > currentPos) 
      move forward 1 step
   else if (centrePos < currentPos) 
      move backward 1 step
   else  if (centrePos== currentPos) 
     flag that centre has been reached
   else
      repeat

…R