#define PIN_TRIG1 3
#define PIN_ECHO1 2
#define PIN_TRIG2 9
#define PIN_ECHO2 8
#define PIN_TRIG3 10
#define PIN_ECHO3 11
#define ledm 4
#define ledh 5
#define ledk 6
#define buzzer 7
int sensor;
void setup()
{
Serial.begin(115200);
pinMode(PIN_TRIG1, OUTPUT);
pinMode(PIN_ECHO1, INPUT);
pinMode(PIN_TRIG2, OUTPUT);
pinMode(PIN_ECHO2, INPUT);
pinMode(PIN_TRIG3, OUTPUT);
pinMode(PIN_ECHO3, INPUT);
pinMode(ledm, OUTPUT);
pinMode(ledh, OUTPUT);
pinMode(ledk, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(A0, INPUT);
// tone(buzzer, 1000);
// delay(500);
// noTone(buzzer);
}
void loop()
{
sensor = analogRead(A0);
// Start a new measurement:
digitalWrite(PIN_TRIG1, HIGH);
delayMicroseconds(10);
digitalWrite(PIN_TRIG1, LOW);
// Read the result:
int duration1 = pulseIn(PIN_ECHO1, HIGH);
Serial.print("Distance1 in CM: ");
Serial.println(duration1 / 58);
duration1 = duration1 / 58;
// Start a new measurement:
digitalWrite(PIN_TRIG2, HIGH);
delayMicroseconds(10);
digitalWrite(PIN_TRIG2, LOW);
// Read the result:
int duration2 = pulseIn(PIN_ECHO2, HIGH);
Serial.print("Distance2 in CM: ");
Serial.println(duration2 / 58);
duration2 = duration2 / 58;
// Start a new measurement:
digitalWrite(PIN_TRIG3, HIGH);
delayMicroseconds(10);
digitalWrite(PIN_TRIG3, LOW);
// Read the result:
int duration3 = pulseIn(PIN_ECHO3, HIGH);
Serial.print("Distance3 in CM: ");
Serial.println(duration3 / 58);
duration3 = duration3 / 58;
if(duration1 <= 100)
{
tone(buzzer, sensor);
digitalWrite(ledm,1);
}
if(duration1 >= 100)
{
noTone(buzzer);
digitalWrite(ledm,0);
}
if(duration2 <= 100)
{
digitalWrite(ledh,1);
}
if(duration2 >= 100)
{
digitalWrite(ledh,0);
}
if(duration3 <= 100)
{
digitalWrite(ledk,1);
}
if(duration3 >= 100)
{
digitalWrite(ledk,0);
}
delay(500);
}