How to install an

Hi team,
I have got a Weatherproof Ultrasonic Sensor, SKU: SEN0208, and am going to use it to monitor the water level in a water tank. I am going to put the sensor in a 25cm pipe on top of the water tank as the sensor cannot detect objects closer than 25cm. I wonder if there is a know best practice to achieve this goal.

Regards,
Farhad

3 Likes

Hey Farhad,

I wouldn’t recommend putting this particular sensor in a pipe (tends to cause issues with echos on the inside of the pipe and depending on the length you may get resonance which can create all kinds of strange readings from ultrasonic sensors) You’re much better off mounting this in the open aimed at the waters surface you want to measure.

In my experience, I found these sensors to be quite noisy, although they do the trick. Below is a script I wrote a while back to run on an Arduino which filters out the noise fairly nicely:

#define ECHOPIN 2 // Pin to receive echo pulse
#define TRIGPIN 3 // Pin to send trigger pulse
#define SMOOTHING 5

int distance = 0;

void setup() {
    Serial.begin(9600);
    pinMode(ECHOPIN, INPUT);
    pinMode(TRIGPIN, OUTPUT);
    digitalWrite(ECHOPIN, HIGH);
}

int getDistanceFiltered(int previousDistance) {
    digitalWrite(TRIGPIN, LOW); // Set the trigger pin to low for 2uS
    delayMicroseconds(2);
    digitalWrite(TRIGPIN, HIGH); // Send a 10uS high to trigger ranging
    delayMicroseconds(10);
    digitalWrite(TRIGPIN, LOW);
    int distance = pulseIn(ECHOPIN, HIGH,26000)/58; // This will determine the distance in centimeters
    if (distance < 20) return previousDistance;
    return (previousDistance*(SMOOTHING-1) + distance)/SMOOTHING;
}

void loop() {
    distance = getDistanceFiltered(distance);
    Serial.println(distance);
    delay(50); // Wait 50mS before next ranging
}

Depending on how accurately you need to measure the water-level, it may be easiest to just throw in some liquid level sensors at various heights instead. Although just mounted at the top of your tank this sensor should still work within its specified range.

This is a generic Uno which tend to have worse QC than the official board, but should work for your project and being quite inexpensive by comparison to the other available boards you can replace it easily if it gets damaged by water, shock, etc.

3 Likes