#include <Ultrasonic.h>
#define SET_DISTANCE 50 //in cm
#define R_ULTRA_TRIG 12
#define R_ULTRA_ECHO 13
#define L_ULTRA_TRIG A1
#define L_ULTRA_ECHO A2
#define R_LED 11
#define L_LED A4
#define BUZZER 6
{
Serial.begin(9600);
pinMode(R_LED, OUTPUT);
pinMode(L_LED, OUTPUT);
pinMode(BUZZER, OUTPUT);
}
void loop()
{
short sRigh_Distance = 0;
short sLeft_Distance = 0;
sRigh_Distance = Right_ultrasonic.read();
sLeft_Distance = Left_ultrasonic.read();
Serial.print("sRigh_Distance: ");
Serial.print(sRigh_Distance);
Serial.print("cm , sLeft_Distance: ");
Serial.print(sLeft_Distance);
Serial.println("cm");
if((sRigh_Distance <= SET_DISTANCE) || (sLeft_Distance <= SET_DISTANCE))
{
tone(BUZZER, 3000);
}
else
{
noTone(BUZZER);
}
if(sRigh_Distance <= SET_DISTANCE)
{
digitalWrite(R_LED, HIGH);
}
else
{
digitalWrite(R_LED, LOW);
}
if(sLeft_Distance <= SET_DISTANCE)
{
digitalWrite(L_LED, HIGH);
}
else
{
digitalWrite(L_LED, LOW);
}
delay(100);
}