I'm working on a project which consists of two ultrasonic, LCD and Arduino.
ultrasonic is also used for flow rate measurements. the concept behind that is to send waves by first ultrasonic to the second, calculate the time1. next, send waves from the second which will be received by the first and calculate time2.
time1 must equal time2 if there is no flow. but I'm not sure that my arduino code is correct because it is not showing me the true results.
this is the concept http://www.universalmetering.co.uk/images/mobile/ultrasonic-diagram.gif
could you please check it and if you have the code give it..
thanks..
LiquidCrystal LCD(11,10,9,2,3,4,5);
//Create Liquid Crystal Object called LCD
#define trigPin1 12 #define echoPin1 13
#define trigPin2 8
#define echoPin2 7
//Simple program just for testing the HC-SR04 Ultrasonic Sensor with LCD dispaly //URL:
void setup()
{
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
LCD.begin(16,2);
//Tell Arduino to start your 16 column 2 row LCD
LCD.setCursor(0,0); //Set LCD cursor to upper left corner, column 0, row 0
LCD.print("Difference in time:"); //Print Message on First Row
}
void loop()
{
long duration1, duration2, diff;
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin2, HIGH);
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
duration2 = pulseIn(echoPin1, HIGH);
diff = (duration2) - (duration1);
LCD.setCursor(0,1); //Set cursor to first column of second row
LCD.print(" "); //Print blanks to clear the row
LCD.setCursor(0,1); //Set Cursor again to first column of second row
LCD.print(diff); //Print measured distance
LCD.print(" sec"); //Print your units.
delay(250); //pause to let things settle
}