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);
}
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
-
945.2 KB Views: 6