Two SEN0208 returns same value independant of level

I purchased two SEN0208 from core electronics (order # 100276969) and they arrived well packed and on time, thank you.

I installed then in a small tank i purchased from Bunnings https://www.bunnings.com.au/maze-100l-rainwater-mini-tank_p3130198 to try them out.

Arduino’s pulseIn() function seemed the easiest way to get these up and running, and I used DFRobot’s suggested sketch to get started. I had quite a few timeouts where pulseIn() returned zero - which is fine - so I ended up using the sketch below to filter and average the readings.

The value returned from the sensor seems to bear no relationship to the level of water in the tank. It returns 1320 +/- 15 on every valid reading - when the tank is full, and when it is empty.

Being an enginner, I love redundancy! So I have tried each of the two sensors i bought with each of the two JSN boards that came in my order - but they all returned the same value (+/- noise).

When NOT in the tank, they seem to work better If I hold them ~500mm above my bench, the pulseIn function returns ~3031, and at about 1m above, it returns ~5690. These figures are more like the “number of cm x 58” quoted as the calibration.

Can you offer any advise on how to get these working in the tank?
Is it just the small tank size that is the issue? My real water tanks are larger, and one is concrete, the other is poly.
Do I need a ‘funnel’ to focus the ultrasonic signal in such a small tank?
Should I fiddle with the adjustable component (is it an inductor) on the circuit board?

Cheers

#define ECHOPIN 2// Pin to receive echo pulse
#define TRIGPIN 3// Pin to send trigger pulse
void setup(){
  Serial.begin(9600);
  pinMode(ECHOPIN, INPUT);
  pinMode(TRIGPIN, OUTPUT);
  digitalWrite(ECHOPIN, HIGH);
  digitalWrite(TRIGPIN, LOW); // Set the trigger pin to low for 2uS
  delayMicroseconds(100); // Ensure the loop begins with the trig pin having been low for some time.
}

const int samples = 20;
void loop(){
  int validReadings=0;
  unsigned long total = 0;
  for (int i=0; i<samples; i++) {
    digitalWrite(TRIGPIN, HIGH); // Send a 10uS high to trigger ranging
    delayMicroseconds(10);
    digitalWrite(TRIGPIN, LOW); // Send pin low again
    unsigned long raw = pulseIn(ECHOPIN, HIGH,200000); 
    if (raw == 0) {
      // pulseIn returns 0 implies a timeout occured.
      Serial.println(".");
    } else {
      validReadings ++;
      String raw_s = String(raw);
      String i_s = String(i); 
      Serial.println(i_s +   "SEN0208 returned:" + raw_s);
      delay(500);
    }
    total += raw;
  }
  Serial.println(total/validReadings);
}
/**
 * Calibration:
 * 
 * At a distance of 870mm from sensor (a) to the top of a small (100L) water tank, the device reads 1308 +/- 5
 * 
 * A second sensor (b) of identical model returned 1320 +/-11 and 870mm./
 * 
 * Full Tank (<200mm to sensor):
 * Sensor (a) 1320 also.
 * Sensor (b) 1315 / 1320 also - no discernable difference to empty tank.
 * 
 * 
 * using the provided calibration of raw value divided by 58 to get distance in cm, 1317/58 = 22.7cm, which is clearly wrong.
 * 
 */

Hi John.
Just a thought. Have you tried the example sketch provided in the product Wiki?
Cheers Bob

1 Like

Yes, Robert - I started with the sketch provided (you may notice the first two lines

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

are from that sample sketch.

I also thought the ultra sonic signal may have been bouncing around too much - so I took a 32mm electrical conduit, made a ‘plug’ of electrical tape around the sensor, drilled some pressure equalising air vent holes near the top of the sensor… and … it made zero difference!

I tried a 100mm tube also (cardboard so not in water) and it also gave a constant, erroneous reading.

I think I will need to install it in my large tank and see if it works “at scale”.

Hi John.
I manage to get by but in no way am I an Arduino programming guru so I will not comment re sketches but one thing I did notice a difference between your script and the example.
The bit ‘pulseIn(ECHOPIN, HIGH,26000)’ in the example is ‘pulseIn(ECHOPIN, HIGH,200000)’ in your sketch. I don’t know what the difference between 26000 and 200000 means but 26000 / 58 = 448cm which is very close to the maximum quoted range of this sensor at 450cm.

I think the problem is related to the readings you are getting 1320. Now 1320 / 58 = 22.75cm which is conveniently very close to the sensor MINIMUM quoted range of 25cm.

Now I am not trying to be funny here as it has happened to all of us. Is it possible that the sensor TX/RX head has been fitted with a plastic (or other material) cap for protection in transit that has to be removed for operation and is still in place.

As I said, this sort of thing has happened to all and is worth checking. I think the clue is in the fact both sensors are reading close to minimum distance and something like a cap over the sensor head would do this.
Cheers Bob

1 Like

Hi John

Sorry. I missed this in your original post. They obviously don’t have any sort of cap fitted.
I don’t know but they may not like reflecting off water, I have no idea why. If that was the case you should return maximum or empty as the article says that is what happens if no echo detected. Try it over a tray of water just to be sure.
I still think the clue is in the minimum reading. I don’t think the small tank dimensions would have anything to do with this. I may be wrong and would be interested to know if this was the case. The quoted “field of view” is 70º.
Cheers Bob

1 Like

Thanks Bob,

I had not done the maths on the minimum reading being 1320 -so that is a good tip.

The “data sheet” also mentions a 70 degree cone for the ultrasonic pulse. I think these may not work in small tanks (and work especially poorly in small tubes!) Perhaps the signal bounces around enough to scatter back to the sensor very quickly - as quickly as the device can handle, so it returns a minimum reading.

But as I say, it does seem to work “in the open”. So I now plan to install it in the roof of one of my tanks that is about 3m in diameter. That should be sometime in the next week, I will let you know how it goes.

Hey John,

That’s true, in smaller tubes you’ll get scattering off the imperfections of the material which will cause the sensor to trigger earlier than it should. Out of curiosity, have you considered adding a wave guide tube to the sensor? With some experimentation on the length and material of a tube mounted to the ultrasonic sensor to direct the cone forward (due to scattering this will reduce the maximum range of the sensor as the sound is absorbed on the tube and only partially exits laminarly) you should be able to improve the accuracy of the sensor in tight spaces.

Unfortunately, this is one of the main limitations of ultrasonic sensors, some modern distance sensors use light instead for a dramatic increase in speed and accuracy at distance although this likely won’t be suitable for your particular project. But definitely, something to consider.

Here’s an interesting discussion on waveguides on another forum.

Hi John.

That is what I meant by “field of view”.

I for one would be very interested in your findings in the larger tank. I would not have thought that the small tank would be that different but I don’t know and you could theorise for ever. There may be acoustic sensors around which will work in small tanks but at the end of the day your tank is largest it really does not matter what a small tank does. Your results and differences due to tank size would be tucked away in what is left of my grey matter database for any future problems.

We had a small tank problem some 20 years ago but solutions then would not directly apply now as sensors and controllers of today were not around and what was available was prohibitively expensive for the small operator. We had to monitor and control the level in 2 small tanks and control some heating in an epoxy potting set up. Finished up with float switches and Mitsubishi Alpha series intelligent relay unit for control. Worked pretty well and is an example of the KISS principle which I am a believer in.

Getting back to your original problem. It is quite possible that “standing waves” due to unwanted echos off the walls may still cause some problems. The only way is to try it and see.

This could be maybe likened to a small audio recording studio where echos and thus standing waves cause mayhem with microphones and people go to great length to minimise all of this. One trick worth mentioning is to have a room (only practical in a fairly small room) with no 90º angles in it. That way echos scatter and quickly dissipate. I am digressing here but mentioned for interest.
Cheers Bob

1 Like