RPi zero w with LM393 / "flying fish" sensor

Hi !
I use a raspberry pi zero w, node-red, mosquito......as smart home system. Connected per wire are some DS18B20 temperature sensors, a sonic sensor in a well, normally closed switch in sewage pipe, some wireless ESP8266 sensors, solenoid valves...….and a "flying fish" sensor with an LM393 comparator IC.

The LM393 gives both an analogue and digital output, which can be adjusted to a threshold with a potentiometer. Task of this sensor is detecting water in a drainage pipe with a conductive pad. Changing state of a rpi pin form high to low. But right at the threshold, the signal is bouncing very hard over long times, while the sensor pad is dying up. DS18B20 sensors on other pins get influenced by this. Temperature graphs on the node-red dashboard start to show many random outlier temperature values. I use the rpi-gpio-in node to detect state of pin, set pull up and debounce to high values. But no success to deal with that bouncing signal, which influences the other flows of node-red/raspberry pi. It's probably a bad way to get a clean digital signal form a conductive pad.

Experience, suggestions..... ? Did I miss here something ? Better sensor for detecting water in a drainage pipe ?

I'm no electronics expert but I don't think that the built-in pull up resistor is enough for what you need. I suspect that you need a debounce circuit.


1 Like

Just a quick note! The rain sensor is working with 5v! Hope you are using a level shifter / voltage divider.


5V could cause the influence to other sensors and finally the end of your PI

For the bounce during drying I would use a trigger node which resets as long as short bounces arrive.

I heard a lot about corrosion on these kind of sensors so I use something like this for rain


Measures the rain amount too. Mostly total overpriced for a piece of plastic and a reed switch and too small for very accurate readings but enough for my irrigation system.

Depending how much water comes down your pipe you can use something like this too


Again, the Hall effect sensor uses 5V

1 Like

that is an impeller type sensor - so Ok for nice clean water flowing out... not so good for any water that may contain usual detritus from a roof/drain - would get blocked almost instantly I would think.

Re debounce - you could use a trigger node set to extend and with a nice large time constant (say 5 mins ?) - but if it is causing interference with other sensors that implies that it is actually causing electrical noise which isn't good - so really needs to be handled offboard before it reaches the Pi - eg like Julian suggests (and indeed a 3.3V levels as Christian says).

1 Like

Wow really fast and great Infos here, thanks to all of you. Node-red and it's community is really awesome!

Well, this sensor belongs to the group of these cheap MH sensors. All with a LM393….commonly used in the Arduino world. And correct, they work with 5V ! I found that this rain sensor type "works" down to the 3.3V of a raspberry pi. And yes, corrosion is certainly a system issue of the conductive pad. Now I found someone who used an oscilloscope to check the signal output of these little LM393 based sensor boards and they bounce really a lot when they switch from low to high or from high to low. So there is definitely a signal bouncing issue.....he solved it with a capacitor to eliminate the initial and final rebounds.

I will try a capacitor of 100nF between pin D0 and pin GND. Shouldn't that work, I will try 5V and a signal level shifter. If all of that doesn't work well, I think I will change the sensing method to a Hall sensor (little moving propeller) or even better to an optical solution...sensor containing an infrared light emitting diode and a phototransistor.

Of course I will check the trigger node too !

For now....thanks to all of you ! :grinning:

1 Like

Nice Optical sensor but depending on your pipe work you could end with even more noise. These are made for water tanks. I assume that a water flow over this will make a lot of trigger impulses.
The rain sensor is totally “logic free” only a little reed switch triggered by a magnet each time a little seesaw flips after a small amount if water fills one teaspoon of water . And the little bounce (if there is any) I got rid of in software on my esp8266.
For a water tank for condensation water and reflow I use (i think capacitive) sensors you stick on the outside of a (thin) plastic container. One lower (stop pump) and one near the top to start the pump. No need to drill holes in the tank.

And there a cheap little switches with a swimmer available too

1 Like

Yes I agree totally on all of this ! "water flow over this (Led like sensors) will make a lot of trigger impulses" Switch debouncing will be still a major task.

The pipe is a drainage pipe around the house. If it rains a lot, groundwater table is rising temporarily and water starts dripping and finally more flowing from a drainage pipe into a well...from where I can pump it into the public drainage system....so my basement stays dry in these more and more wet winters. I use water out of this well, so it's water level is always below normal groundwater level. That means most time of the year nothing is going on there because it's dry. And there are times, where it's just dripping. So in general finding the best sensor for this challenging task is not easy. Well, I can see on my sonic sensor that the water level in the well is rising suddenly much faster then it does usually :joy: but why not installing a sensor to know where the water is coming from....I could go and take a look.....but hey this only happens when it's raining and then I like to stay on my sofa :rofl: :rofl:

Hi again !
To close this topic for now and deliver some final results for people stumbling over the same stone...

You can buy this "MH series" of cheap sensors often called "Flying Fish" in the Arduino world. They come in a range of configuration...LDR, NTC thermistor, resistive water/moisture detectors and more. They are all based on the comparator IC LM393. I try to use the "rain sensor" to detect some dripping water in a drainage system of my house. Sensor looks like this :
It's connected to a raspberry pi zero w with a bunch of other wired/wireless sensors and of course I use NODE-RED ! :slight_smile: They all have a small potentiometer to adjust sensitivity...wire length...adjust the point where the digital output changes state. In my setup, right at the point where this sensor changes state (high to low or low to high) I get suddenly random outlier values from my temperature sensors on other pins. Looks like this :
So there is something seriously interfering. I took a closer look on this IC LM393...found this :
At signal change people experienced similar troubles. In transition the signal is bouncing a lot in a rel. big time window. For a microcontroller or raspberry pi this looks like electrical noise / interference / defined as undesirable electrical signals and this causes the outliers on my temperature graphs (sensors on other pins). To get a clean signal transition at the pin people use ceramic capacitor 100nF/10nF to smooth out these spikes. You have to experiment a bit....if you are a pro, of course you can calculate the right value. Fix capacitor between GND and DO. Then signal flanks should look like this:
I tried 22nF because I had one laying around. The suggestion to use the trigger node on the software site, to deal with that "normal" signal bouncing while the sensor pad is drying up, is also really good !!! Works 100% in node-red.

But in extrem testing I could still force the system to produce an outlier value from temperature sensors on other pins. Difficult environmental conditions for a sensor.....I think I will try a contactless sensing method to avoid all that trouble and getting right out of the box a better signal to the rpi pin. Thanks to Christian-Me for suggesting XKC-Y25-NPN.

Your temperature sensor problem could be due to this:

Ohhh I wonder if this might be good to monitor a sump pump hole. Stick it in a PCV tube with the bottom capped (so water won't rise up the inside of the tube) and set it in the sump hole....

Well I am 1000% sure, wiring, DS18B20, temp flow in node-red...and all other components of the system.....all this works perfect for month without any issues.

It starts when I connect this MH sensor board. I can replicate these problems now at any time, with that potentiometer on the sensor board. Right at the switch point of the LM393, I can get the LED (indicating a high or low output of the LM393) flickering. If that goes on for a time....it causes trouble on my rpi…..the temperature graphs are just an indicator that the rpi is getting some electrical noise on one of his pins. This little board has no further logic components to create a clean, not swinging or oscillating digital signal when it changes state. It's not the best sensor for what I try to achieve. I think I am far better of with that non-contact water probe XKC-Y25-NPN.

:slight_smile: of course, on the kitchen table.....you lick your finger and stamp it on the sensor pad.....THEN !! THEN it works awesome !!! :rofl: But when it's mounted at the end of that drainage pipe....in a well....on a long CAT5 cable......it works somehow......but not reeeeaally so good anymore for the rest of the system.

Are the outlier values 85C? If so then are you sure the power supply is up to the job? 85 is an indication that the DS18B20 has suffered a reset.

This may be of interest to people interested in water sensors:

Perhaps put a wireless micro near to the sensor (esp8266) instead a long cable.

If the mountain will not come to Mohammed, Mohammed will go to the mountain.

Depending on your cable length the resistance is an issue. Perhaps you have to measure if your signal meets the requirements of the data sheet (if you meet the logic voltage levels ceep an eye on signal to noise ratio)
I assume you drive the DS18B20 and your moisture sensor on the same cable ... look if the bounce is inducted on the other wires. Noisy signals love to do that and as said before digital sensors hate this.

I could not see the timeframe on your dashboard sapshot (low res) but I didn’t new that you can use the dashboard as an oscilloscope- nice new feature :wink:
It looks like the timebase is not related to the bounces... perhaps the reset on the right side.

Hi and no.
It's not that typical 85C reset or wiring connection problem of an DS18b20. And all sensor groups have a dedecated pin. As soon as I connect the MH sensor breakout board and set the potentiometer right at the switch point….were the indicator LED should show a clean switch from high to low or low to high....LED starts to flicker...indicating that there is no clean digital transition of the signal. If I leave this going on for a time....besides the DS18b20….also the sonic sensor will start to show random outliers. Unfortunately I have no Oszilloskop to investigate further what the signal looks like in that moment. But other people have and they discovered that the signal flanks are not clean. They use a capacitor to smooth the signal flanks....that didn't really work for me. And as soon as I disconnect the LM393….all problems are gone.

A conductive sensor is not the best choice for me. Water/moisture drying of the sensor pad will take time....so resistance of the sensor pad will increase slowly over a long time. For my rpi this prolonged signal oscillation, frequency switching, bouncing is just electrical noise on the pin.....causing problems, which can't be handled on the software site.

I will change form a conductive sensor to a more sophisticated inductive sensor method. Getting clean "klicks" form a Hall sensor propeller/wheel. To avoid issues with dirt....an inductive sensor like this XKC Y25V without moving parts is the best solution for me. There are some videos on YouTube...

Dashboard snapshot....yeah :wink: there you see my gas heater system breathing. Temperatures of my radiator system, hot water flow and colder return flow. Hey this microphone idea sound really quirky....but actually I thought about this too :slight_smile: When I step over that concrete well cover and the drainage system is dripping, I can hear that very well !! So this would be a non conductive method too. The LM393 works with a simple little micro and I guess the signal is better produced....bouncing can be handled completely with a trigger node in node-red. But I will order this inductive sensor. The GPS helmet of my dog.....will change that to a smaller LoRa radio :rofl: :joy: aaaaa love that nice new digital I/O world tinkering. Could use of the node-red-contrib-lorawan…. :thinking:

1 Like

I still have that (dirt cheap) gps / gsm + stm32 board lying around bought for my neighbors dog who is able to jump over fences after I found out that all these of the shelf dog gps collars are getting there money by a ridicules expensive subscription service to their services. But what I really need for my dog (who is big, heavy and not wishing to escape or hunt) is a “dog is digging up the garden soil” sensor.
Any thoughts on this? :wink:
Thing there have to be AI involved :thinking:

Well there are plenty of scholarly articles on using accelerometers for activity classification... eg

Not sure about ones for dogs but same principles must apply...

1 Like

Too easy. An array of IP camera's connected to a Pi supercomputer cluster doing image processing. Easily trained to recognise dog digging episodes.

I recommend coupling with a spade-equipped robot to go fill in the holes. Though you might need a second pair of robots to fight off the dog while the other one does its stuff.

I recon only 256 4GB Pi4's should do it. :grinning:


This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.