Hey all,
I'm struggling to get the code for the above sensors working all at once. I re-identified each Echo and Trig pin per sensor (F, L and R - Front, Left and Right) and after upload with no errors, nothing appears in the Serial Monitor.
Would anyone mind looking over the code and explaining what I have missed? Thank you.
Matt
// Code for Ultrasonic Distance Module US-015
unsigned int EchoPinF = 3;
unsigned int EchoPinL = 5;
unsigned int EchoPinR = 7;
unsigned int TrigPinF = 2;
unsigned int TrigPinL = 4;
unsigned int TrigPinR = 6;
unsigned long Time_Echo_us = 0;
//Len_mm_X100 = length*100
unsigned long Len_mm_X100 = 0;
unsigned long Len_Integer = 0; //
unsigned int Len_Fraction = 0;
void setup()
{
Serial.begin(9600);
pinMode(EchoPinF, INPUT);
pinMode(EchoPinL, INPUT);
pinMode(EchoPinR, INPUT);
pinMode(TrigPinF, OUTPUT);
pinMode(TrigPinL, OUTPUT);
pinMode(TrigPinR, OUTPUT);
}
void loop()
{
digitalWrite(TrigPinF, HIGH);
digitalWrite(TrigPinL, HIGH);
digitalWrite(TrigPinR, HIGH);
delayMicroseconds(50);
digitalWrite(TrigPinF, LOW);
digitalWrite(TrigPinL, LOW);
digitalWrite(TrigPinR, LOW);
Time_Echo_us = pulseIn(EchoPinF, HIGH);
Time_Echo_us = pulseIn(EchoPinL, HIGH);
Time_Echo_us = pulseIn(EchoPinR, HIGH);
if((Time_Echo_us < 60000) && (Time_Echo_us > 1))
{
Len_mm_X100 = (Time_Echo_us*34)/2;
Len_Integer = Len_mm_X100/100;
Len_Fraction = Len_mm_X100%100;
Serial.print("Present Length is: ");
Serial.print(Len_Integer, DEC);
Serial.print(".");
if(Len_Fraction < 10)
Serial.print("0");
Serial.print(Len_Fraction, DEC);
Serial.println("mm");
delay(1000);
}
}