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);
}