14 Online
2 Member And 12 Guest
Members present at the site
Today Visits : 4281
Yesterday Visits : 4063
All Visits : 513743

Welcome to Electronoobs Q&A, where you can ask questions and receive answers from other members of the community.



Categories


0 like 0 dislike

int trig_pin1 = 12;

int echo_pin1 = 13;

int trig_pin2 = 10;

int echo_pin2 = 11;

 

int trig_pin3 = 8;

int echo_pin3 = 9;

long echotime1;

long echotime2;

long echotime3;//in micro seconds

float distance1;

float distance2;

float distance3;//in cm

 

void setup() {

  Serial.begin (9600);

  pinMode(trig_pin1, OUTPUT);

  pinMode(echo_pin1, INPUT);

  digitalWrite(trig_pin1, LOW);

 

  pinMode(trig_pin2, OUTPUT);

  pinMode(echo_pin2, INPUT);

  digitalWrite(trig_pin2, LOW);

 

  pinMode(trig_pin3, OUTPUT);

  pinMode(echo_pin3, INPUT);

  digitalWrite(trig_pin3, LOW);

 

}

 

 

void loop() {

 

  digitalWrite(trig_pin1, HIGH);

  delayMicroseconds(10);

  digitalWrite(trig_pin1, LOW);

  delayMicroseconds(2);

 

  //trigger a pulse-echo measurement

  digitalWrite(trig_pin2, HIGH);

  delayMicroseconds(10);

  digitalWrite(trig_pin2, LOW);

  delayMicroseconds(2);

 

  //trigger a pulse-echo measurement

  digitalWrite(trig_pin3, HIGH);

  delayMicroseconds(10);

  digitalWrite(trig_pin3, LOW);

  delayMicroseconds(2);

 

  //get the result

  echotime1= pulseIn(echo_pin1, HIGH);

  distance1= (echotime1*0.034)/2;

 

  echotime2= pulseIn(echo_pin2, HIGH);

  distance2= (echotime2*0.034)/2;

 

   echotime3= pulseIn(echo_pin3, HIGH);

  distance3= (echotime3*0.034)/2;

 

  //send over Bluetooth

// left

  Serial.print("T"+String(echotime2)+"");

  Serial.print("D"+String(distance2,1)+"");

  if (distance2<30) Serial.print("LR255G0B0"); //Red

  if (distance2>=30&&distance2<=100) Serial.print("LR255G200B0"); //Orange

  if (distance2>100) Serial.print("LR0G255B0"); //Green

 

//right

  Serial.print("T"+String(echotime3)+"");  

  Serial.print("D"+String(distance3,1)+"");

  if (distance3<30) Serial.print("LR255G0B0"); //Red

  if (distance3>=30&&distance3<=100) Serial.print("LR255G200B0"); //Orange

  if (distance3>100) Serial.print("LR0G255B0"); //Green

 

//back

  Serial.print("T"+String(echotime1)+"");

  Serial.print("D"+String(distance1,1)+"");

  if (distance1<30) Serial.print("LR255G0B0"); //Red

  if (distance1>=30&&distance1<=100) Serial.print("LR255G200B0"); //Orange

  if (distance1>100) Serial.print("LR0G255B0"); //Green

 

  delay(1000);

}

in Arduino by (120 points)

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
...