PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Detecting a signal that is very weak (water level)

Started by TimB, Jan 11, 2022, 04:54 PM

Previous topic - Next topic


I'm trying to detect a water level using a probe.

I used a 4093 to generate a square wave (to reduce corrosion) and then feed it itself through a diode cap etc. Its a standard circuit and is good at detecting the tiniest current. The issue is that the resistance of the water could be as high as 20 megohm. Before my scope died I was measuring ~ 5.6v pp on the squarewave. By the time it had traveled through some tap water the voltage (on the scope) was ~2v.

The issue is that the 4093 needs >2.9v at 5v to switch so obviously it failed.

My question is can the circuit be modified to make it work or a better system.



John Lawton


pity your 'scope died, have you tried increasing the values of R2 and R4 and possibly C6/C8?



Why not introduce a dual package opamp to make either a simple pre amplifier to give a higher impedance in for each channel, or a comparator. Either can then feed the schmitt triggers.



Try a feedback resistor from the output to the input of the NAND gates U2B and U2D, to see if they will amplify. I know standard CMOS NAND gates will, but I'm not sure of Schmitt trigger types. Resistors from approx 2.2M to 10M may work to give a bit of gain to them without causing too much feedback and start oscillating.

Also try changing D2 and D4 to Schottky diodes so they will pass lower voltages, instead of the 0.6V that Silicon diodes require. The same as why Germanium diodes or, sometimes, Schottkys are used in Crystal Set radios.

I'm not quite sure what U2B and U2D are functioning as, apart from the filter at their beginning.

Personally, I think a quad op-amp chip would be better suited for the circuit, so one of them could act as an oscillator and two of them as sensitive comparators with multiplication and hysteresis to give a logic output level. Op-Amps do not require a dual voltage anymore.


I have a different suggestion. If there is a max232 unused transmitter pin on the circuit, the output of C4 can be connected here.

Add: That's about ±10 volts change.


Thanks for the help

I think I will go with Les's idea of a quad op amp.



You could actually do it with a single PIC microcontroller Tim. Use the on-board comparators and a PWM for the oscillator (sinewave or squarewave). They work in the background, and the comparators will set SFR flags when triggered. The input of the comparator can be made quite sensitive with input resistors, and stable with the FVR.

Or if you are not comfortable with the on-board comparators, use a device with built-in Op-Amps, and operate them as you would a standard Op-Amp. The only difference with the on-board types is the frequency bandwidth, but your circuit will be using low frequencies. Everything with a single device, now that is a better option. :-)

I did the same, many years back, with a short distance ultrasonic distance detector. Instead of using external components, I used the comparators and configured them as standard Op-Amp pre-amplifiers for the receiver, and the PWM for the transmitter operating as push-pull.


Definitely PWM for the square wave generation - much more symmetrical than a 4093.
Given you are generating the clock I would be tempted to look at synchronous detection as it offers high noise immunity and allows detection down to much smaller levels than any bandgap rectifier.  Some of the older PICs used to have an open drain FET in the line up which would be ideal for gating the received signal as a simple half wave synchronous system.  A single or dual op-amp would probably suffice to do the level threshold sensing.
Is this a sequel to the camera/meniscus level sensor or a whole new odyssey?



What I'm going to try next as the PCB is made is to feed the signal that was going back into the 4093 into the pins that are on the pic. They have 12 bit ADC capabilities and can measure the voltage.

Unfortunately is the same old level sensor thing
I dropped the camera as it was too bulky. I for now just need to detect water at 2 points. The issue is that it needs to be to >=0.1ml so that restricts the dia of the tube your sensing it in. Also it needs to work with purified water that may have a resistance of 2MΩ × cm

Nothing is ever simple  :(

I did try it before and the conductivity was a real issue


Hi Tim,
Sorry to hear the camera approach didn't work out for you - I know you put a lot of development in to it.
If you're playing with square waves in water you may want to revisit a high frequency capacitive approach.  The dielectric constant of water is around 80 so it displays a marked change compared to air and it would apply to even deionized water.  Perhaps a high frequency oscillator running at a few MHz with a capacitive probe in the water that can provide a frequency shift of several kHz per pF of change.  The nice thing about frequency is that it's already effectively in the digital domain and is easily counted by a micro.   So easy to do mental designs but as you've found the devil is in the detail. I hope you can find something that meets your needs.  Good luck.


John Lawton

Quote from: TimB on Jan 11, 2022, 10:54 PMWhat I'm going to try next as the PCB is made is to feed the signal that was going back into the 4093 into the pins that are on the pic. They have 12 bit ADC capabilities and can measure the voltage.

Hi Tim,
I've been designing water leak detection equipment for a very long time now.
Your original diode pump scheme is similar to a unit I once designed and will probably work if you tweak the component values as I have suggested to make the detection circuit higher impedance and make sure the pump works effectively. Having said that I actually used a PIC ADC to detect the diode pump output so that scheme will definitely work.



If you set the +Vref of the ADC to 1.024 Volts, you can detect very small signals. Below are a few routines for setting up the ADC and FVR on a PIC18F26K40 device that may help. Other 18F devices seem to use the same values in the FVRCON SFR aswell:

' Setup the FVR for 1.024 Volts on a PIC18F26K40 device
$define FVR_Init_1024() FVRCON = %10000001

' Setup the FVR for 2.048 Volts on a PIC18F26K40 device
$define FVR_Init_2048() FVRCON = %10000010

' Setup the FVR for 4.096 Volts on a PIC18F26K40 device
$define FVR_Init_4096() FVRCON = %10000011

' Disable the FVR on a PIC18F26K40 device
$define FVR_Disable() FVRCONbits_FVREN = 0

$define FVR_IsOutputReady() FVRCONbits_FVRRDY   ' Holds 1 if the FVR is stabilised

' Setup the ADC peripheral on a PIC18F26K40 device
' Input     : None
' Output    : None
' Notes     : Set for 10-bit operation
Proc ADC_Setup()
    ADLTHL  = %00000000
    ADLTHH  = %00000000
    ADUTHL  = %00000000
    ADUTHH  = %00000000
    ADSTPTL = %00000000
    ADSTPTH = %00000000
    ADRPT   = %00000000
    ADPCH   = %00000000
    ADCAP   = %00000000
    ADCON0  = %10000100         ' Right justify for 10-bit operation
    ADCON1  = %00000000
    ADCON2  = %00000000
    ADCON3  = %00000000
    ADSTAT  = %00000000
    ADREF   = %00000011         ' Set the ADC to use the FVR for +Vref
    ADACT   = %00000000
    ADCLK   = %00000100         ' fOSC/16
    ADACQ   = %00000000

With the ADC, you can either look for a change in its output, or sample it and look for the waves. Or look for waves once a change has been detected. This will help stop mis-readings.


I have tried several times a capacitive sensor. They drift to much.

The camera works but its not needed in this iteration. Its bulky because you have to mount the camera far enough away to view the area. It also suffers from parallax.
The probes are not a direct replacement in this case, I just need to accurately detect water touching a probe.

I will have to get some purified water to do some tests



I tried the capacitance approach in the past as well for liquid levels, but external influences always changed the default capacitance and the measured capacitance, so default measurement was constant, and not very stable over time. It worked on my bench every time, but was a bit iffy in the real world after a few months. Capacitance measurement may have improved now a bit, but capacitance has always been one of those things that changes constantly for very little reason in the open air, and especially near moisture. :-)


Logic Amplifier needs to be an unbuffered gate to ensure stability is maintained, 74xx1GU work really well to amplify and can provide a digital output given the required stimulus.. They have huge amount of open loop gain, the same as you would use for a xtal osc, they can be stabilised easily , I've used them loads of times for linear applications for FSK amplifiers and GBW is high and they are cheap
 You can optimise the input with a Simple RC to provide a HPF function and then split the feedback to increase the input impedance and provide DC stability.  Run PWM at say 20kHz and drive through logic amp with a 1k and 4n7F resistor on the input.  Should be extremely sensitive and can be cascaded so a quad unbuffered gate and a few R&C should do it.  You can also tweak the gain with the resistors if needed to adjust gain and frequency response. 

Loads on the web but here is a particularly good review to increase the input Z.


In the past I tried to detect liquids with the capacitive sensor built into the 12F1840 I had used a sensor area of 28 mm made with the copper of the printout. He could detect the level well even without contact, for example by putting the sensor outside a plastic bottle. I also tried to increase the thickness and I remember that even with a few millimeters of Plexiglass insulation it still worked.


Goodness knows why I was thinking about this post during the early hours of this morning!