HC-SR04 interface issues

Thread Starter

aliyesami

Joined Sep 12, 2009
21
i am trying to use this module to sense water flow and have mounted it on the PVC pipe 1.5 inch in diameter but the reading I get is 0.4 inch .
is the signal bouncing off the top wall ?
I have seen similar industrial design where the ultrasonic sensor is mounted on the PVC pipe from outside.

The sensor if left open works fine and can detect the range if object moved closer. So that tells me that module and code is working fine.

please see the diagram attached and the code below written for eSP32.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_ADDR 0x3C
Adafruit_SSD1306 display(128, 64, &Wire, -1);
const int trigPin = 5;
const int echoPin = 18;

//define sound speed in cm/uS
#define SOUND_SPEED 0.034
#define CM_TO_INCH 0.393701

long duration;
float distanceCm;
float distanceInch;

void setup() {
Serial.begin(115200); // Starts the serial communication
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(0,0);
display.display();
}

void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH)/1000;

// Calculate the distance
distanceCm = duration * SOUND_SPEED/2;

// Convert to inches
distanceInch = distanceCm * CM_TO_INCH;

// Prints the distance in the Serial Monitor
//Serial.print("Distance (cm): ");
//Serial.println(distanceCm);
Serial.print("Distance (inch): ");
Serial.println(distanceInch);
//Serial.print("Duration (ms): ");
Serial.println(duration);
display.clearDisplay();
display.setCursor(0,0);
display.print(duration);
display.display();
delay(1000);
}
 

Attachments

sghioto

Joined Dec 31, 2017
5,110
How is this suppose to work? I've seen the HC-SR04 used to detect water levels but not flow. Are you trying to just detect water flow or measuring water flow?
If just to detect flow why is the distance reading important if there's a different reading when water is moving.
 
Last edited:

Thread Starter

aliyesami

Joined Sep 12, 2009
21
I am just trying to detect the water flow not the rate. I am thinking based on the documentation I found online that the travel time from transmitter to reciever will change with or without flow and that can indicate to me if water is flowing .
take a look at this video for example .

 
Last edited:

Thread Starter

aliyesami

Joined Sep 12, 2009
21
Is this a water pipe or a drain pipe meaning is there always water in the pipe or not?
this is storm drain pipe and when the pumps are working there is no water in the pipes.
even if there is water i want the sensor readings to be different than when the water is flowing.
 

Thread Starter

aliyesami

Joined Sep 12, 2009
21
I am being told that HC-SR04 is too weak and the waves will bounce off the top pipe wall and not penetrate the walls into water . so what type of ultrasonic sensor can be used which has powerfull enough waves that can penetrate through the pvc walls ?
 
Top