#include "LiquidCrystal.h"
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
const int trigPin1 = 12;
const int echoPin1 = 13;
const int trigPin2 = 11;
const int echoPin2 = 10;
const int trigPin3 = 2;
const int echoPin3 = 1;
long duration1;
long duration2;
long duration3;
int distanceCm1, distanceInch1;
int distanceCm2, distanceInch2;
int distanceCm3, distanceInch3;
void setup() {
Serial.begin(9600);
lcd.begin(16,2);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(trigPin3, OUTPUT);
pinMode(echoPin3, INPUT);
pinMode(9,OUTPUT);
pinMode(8,OUTPUT);
pinMode(7,OUTPUT);
}
void loop()
{
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin1, HIGH);
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
duration2 = pulseIn(echoPin2, HIGH);
digitalWrite(trigPin3, LOW);
delayMicroseconds(2);
digitalWrite(trigPin3, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin3, LOW);
duration3 = pulseIn(echoPin3, HIGH);
distanceCm1= duration1*0.034/2;
distanceInch1 = duration1*0.0133/2;
distanceCm2= duration2*0.034/2;
distanceInch2 = duration2*0.0133/2;
distanceCm3= duration3*0.034/2;
distanceInch3 = duration3*0.0133/2;
Serial.print("Distance1: ");
Serial.println(distanceCm1);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Ultrasonic1 ");
lcd.setCursor(12,0);
lcd.print(distanceCm1);
//digitalWrite(9, HIGH);
//delay(500);
Serial.print("Distance2: ");
Serial.println(distanceCm2);
lcd.setCursor(0,1);
lcd.print("U2 ");
lcd.setCursor(3,1);
lcd.print(distanceCm2);
Serial.print("Distance3: ");
Serial.println(distanceCm3);
lcd.setCursor(9,1);
lcd.print("U3 ");
lcd.setCursor(12,1);
lcd.print(distanceCm3);
if(distanceCm1 <15)
{
digitalWrite(7,HIGH); // LED ON
}
if(distanceCm1 >15)
{
digitalWrite(7,LOW); // LED OFF
}
if(distanceCm2 <15)
{
digitalWrite(8,HIGH); // LED ON
}
if(distanceCm2 >15)
{
digitalWrite(8,LOW); // LED OFF
}
if(distanceCm3 <15)
{
digitalWrite(9,HIGH); // LED ON
}
if(distanceCm3 >15)
{
digitalWrite(9,LOW); // LED OFF
}
delay(100);
}