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] = {
int step_pin=2;    
int dir_pin=3;        

int run;
int startPin;

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

     run = 0;
     startPin = 13;

void loop() {
  customDelayMapped = speedUp();
 digitalWrite(step_pin, HIGH);
  digitalWrite(step_pin, LOW);
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)
  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;
  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(" ");

  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)....

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