Connecting More than One Ultrasonic Sensor?

Im Trying to figure out how to input multiple(4) HC_SR04 Sensors with one Arduino. Im made 2 sketches and tried to combine them with unique variables, but cant seem to make the sketch work. Bellow is my code: THANKS,

//Defining pins
#define trigPinL 7
#define echoPinL 8

#define trigPinR 9
#define echoPinR 10

//Setup Serial communication Setting Pins up
void setup(){

//Serial Communication
Serial.begin (9600);

//Setting pinsUp

//LEFT SENSOR
pinMode(trigPinL, OUTPUT);
pinMode(echoPinL, INPUT);

//RIGHT SENSOR
pinMode(trigPinR, OUTPUT);
pinMode(echoPinR, INPUT);

}

void loop() {
//Variables

//LEFT SENSOR
int durationL, distanceL;

//RIGHT SENSOR
int durationR, distanceR;

//LEFT SENSOR
digitalWrite(trigPinL, HIGH);
delayMicroseconds(500);
digitalWrite(trigPinL, LOW);

//RIGHT SENSOR
digitalWrite(trigPinR, HIGH);
delayMicroseconds(500);
digitalWrite(trigPinR, LOW);

//LEFT SENSOR
durationL = pulseIn(echoPinL, HIGH);
distanceL = (durationL/2) / 29.1;

//RIGHT SENSOR
durationR = pulseIn(echoPinR, HIGH);
distanceR = (durationR/2) / 29.1;

Serial.print(distanceL);
Serial.print(distanceR);

delay(500);

}

but cant seem to make the sketch work

I am not surprised.

  1. Please read how to use the forum, these is a sticky post at the start of each section it will tell you how to post code.
  2. Do one ping and read followed by the second ping and read. Interleaving them like this will not work because the first pulse gets lost generating the second one, and the same with reading back.