HC SRO4s return 0 on multiple sensors.

For a robotics project I am using HC SRO4s to allow the robot to detect obstacles in it's surroundings. However, when connected to any Arduino Mega 2560 the sensors return the distance as 0. Four of the sensors I have used previously, and five I purchased two days ago. All Arduinos worked previously and work when other sensors are connected to them.

The error can be recreated using this source code:

const int triggerI = 22;
const int echoI = 23;
int distanceI;
long durationI;
void setup() {
  pinMode(triggerI, OUTPUT);
  pinMode(echoI, INPUT);
  Serial.begin(9600);
}
void loop() {
  digitalWrite(triggerI, LOW);
  delayMicroseconds(2);
  digitalWrite(triggerI, HIGH);
  delayMicroseconds(10);
  digitalWrite(triggerI, LOW);
  durationI = pulseIn(echoI, HIGH);
  distanceI = durationI * 0.017;
  Serial.println(distanceI);
  Serial.println(durationI);
}

if (decider = 1)oops

If I remove the if statement and any variables related to it and have the source code originally contained within the IF statement 0 is just printed continuously on the serial monitor.

The if statement, with its assignment instead of comparison, will display the same behaviour, present or absent.

Sorry, although thank you for pointing that error out. Any ways, what can I do to solve this issue?

Check your wiring, check and simplify the code.

I have. The wiring is correct and I see no feasible way to simplify it.

Ok.

You can't say I didn't try.

Good luck.

You've edited the code in the original post.

Don't EVER do that.

(It's still too big and too fast)

What values are you getting for durationI?

Steve