// defines pins numbers
const int trigPin1 = 9;
const int echoPin1 = 10;
const int trigPin2 = 9;
const int echoPin2 = 10;
const int trigPin3 = 9;
const int echoPin3 = 10;
const int buzzer = 11;
const int motor = 13;
// defines variables
void setup() {
Serial.begin (9600);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(trigPin3, OUTPUT);
pinMode(echoPin3, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(motor, OUTPUT);
}
void loop() {
int duration, distance;
digitalWrite (trigPin1, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin1, LOW);
duration = pulseIn (echoPin1, HIGH);
distance = (duration/2) / 29.1;
Serial.print(distance);
Serial.print("cm");
Serial.println();
if (distance < 30) { // Change the number for long or short distances.
digitalWrite (buzzer, HIGH);
} else {
digitalWrite (buzzer, LOW);
}
int duration2, distance2;
digitalWrite (trigPin2, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin2, LOW);
duration = pulseIn (echoPin2, HIGH);
distance2 = (duration/2) / 29.1;
Serial.print(distance2);
Serial.print("cm");
Serial.println();
if (distance2 < 20) { // Change the number for long or short distances.
digitalWrite (buzzer, HIGH);
}
else {
digitalWrite (buzzer, LOW);
}
int duration3, distance3;
digitalWrite (trigPin3, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin3, LOW);
duration = pulseIn (echoPin3, HIGH);
distance3 = (duration/2) / 29.1;
Serial.print(distance3);
Serial.print("cm");
Serial.println();
if (distance3 < 10) { // Change the number for long or short distances.
digitalWrite (buzzer, HIGH);
}
else {
digitalWrite (buzzer, LOW);
}
}
// Code ends here.