Majazen ـG
Majazen ـG

Reputation: 139

flowmeter using two ultrasonic with arduino

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

    } 

Upvotes: 4

Views: 4156

Answers (1)

Ivy Growing
Ivy Growing

Reputation: 3294

SR-04 provides echo response on trigger. This happens in the same module. I.e. triggering one module with trigPin1 and reading other module with echoPin2 brings nearly random and not related results.

Read echoPin1 after triggering trigPin1.

SR-04 can register sound that returns in air by distance 20cm or more. It takes shortest time as approx. 0.6ms (588ns). Less than that is 'nothing' for the SR-04.

Sound travels in water about 5 times faster than in air. In addition, the distance between receiver and transmitter in SR-04 is quite small. As well the pipe width is narrow and not designed for SR-04.

Therefore, the expected return time in water if you even place transmitter and receiver 10 cm away, using 1 inch wide pipe is about 0.1ms (100ns). This is behind SR-04 capabilities to register.

However, you might want to build your own TOF meter, using TDC-GP22 module plus separated ultrasonic receiver and transmitter plus appropriate power management. That's quite complicated (and not cheap as SR-04) project which benefits with non-invasive liquid flow measurement.

Upvotes: 1

Related Questions