Moisture sensor, using PWM-signal and A0

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Ton_vN
Normal user
Posts: 300
Joined: 21 Oct 2016, 15:20
Location: Hengelo (Ov)/ NL
Contact:

Moisture sensor, using PWM-signal and A0

#1 Post by Ton_vN » 29 Dec 2020, 23:25

T&H-sensors for soil measurements with long endurance & good quality are not cheap.
The simple moisture sensors with fork or pen have no quality in data, but may be useful to generate a very rough indication and for thresholding aimed at a alert.
The downside for the very simple resistive moisture-sensors is that they use DC to sense the earth's resistance between the legs of the fork, resulting in heavy/quick corrosion of the legs. The slightly positive side is that a fork-setup survives drowning without fatal consequences.
The capacitive moisture sensors are better related to corrosion, applying an AC-signal, but drowning is fatal.

Throwing away the resistive devices is easy, but recycling of the setup would be nice,
and ;) a 'useful' passing of time during the present crisis and/or rainy days .......
2 'Usual' frontends for the WEMOS' A0-pin to interface to array (for Rain/Wetness-sensing) or to fork (for Soil-sensing).
Soil-Frontend
Soil-Frontend
humgrondprobe [320x200].jpg (13.02 KiB) Viewed 17709 times
Rain-Frontend
Rain-Frontend
regensensor [320x200].jpg (18.21 KiB) Viewed 17709 times
Triggered by the need to replace a 'fork'-sensor of a Soil-sensor lost by corrosion, came to revisit an idea suggested by a meteo-buddy.

:idea: The WEMOS/ESP8266 has an onboard AC-signal in the form of PWM.
This PWM-signal can have a max. level of 3V3 at 10mA.
Combining various infos, seems that it can be set as follows in ESPEasy
-- Basic command = PWM,<GPIO>,<state> or PWM,<GPIO>,<state>,<duration> or PWM,<GPIO>,<state>,<duration>,<frequency>
-- with <GPIO> 0...15, <state> & <duration> 0...1024, and <frequency> set between 100 and 40000 [Hz]
-- <state> = level/duty-cycle, alternating at standard 1kHz, unless <frequency> inserted
-- <duration> = causes fading expressed in ms (and 'no fading' if deleted or set to 0)
-- Example layout for command = http://<espeasyip>/control?cmd=PWM,13,500
Feeding the PWM-signal to Leg A of the Fork-sensor, if sensing on the Leg B of the fork, then the signal from Leg B must be a portion of the original signal, reduced by the resistance between the legs. For the Rain/Wetness-sensor similarly port A as input and port B as output.
Pictures from my antique oscilloscope provide evidence that the operation of the loop ESP to Sensor & back is OK, when the sensor is wet.
Signal from ESP to sensor
Signal from ESP to sensor
Output_signal_to_sensor [50%].jpg (13.93 KiB) Viewed 15441 times
Signal from wet sensor
Signal from wet sensor
Input_signal_from_sensor [50%].jpg (13.99 KiB) Viewed 15441 times
For a dry sensor the Input_signal is just noise & hum (as could be expected) collected between the wires and at the sensor.

The ADC of the Wemos/ESP8266 at pin A0 seems an available tool to measure the signal from Leg B of the fork or port B of the Rain/Wetness-sensor.

Now the question how to interface between Leg B and pin A0 at (almost) no cost:
1) apply the PCB (as shown above) normally used as frontend to A0?
[Probably not, because the PCB and A0 'behind it' will have problems to digest a PWM-signal of variable amplitude]
2) instead of the PCB some DIY-construction of diode, capacitor(s) and resistor for direct connection to A0?
[with the DIY-construction rectifying & smoothing the PWM-signal from Leg/port B into a semi-DC-signal]
3) = DIY-construction 2) as front for 1)?
[with the DIY-construction smoothing the PWM-signal for the entrance of the PCB, and the PCB amplifying/leveling that input signal]

Have fiddled with 2) and 3), but not yet a working result, suspecting that the signal from Leg B is too weak to trigger the PCB.

;) ;) Consider this just as a teaser/challenge/playground aimed at better life cycle of the setup.
Somebody with experience/ideas for best DIY-construction for the frontend?
With PWM-signal set to constant/1000Hz/symmetric
Last edited by Ton_vN on 15 Mar 2021, 15:15, edited 3 times in total.

Ton_vN
Normal user
Posts: 300
Joined: 21 Oct 2016, 15:20
Location: Hengelo (Ov)/ NL
Contact:

Re: Moisture sensor, using PWM-signal and A0

#2 Post by Ton_vN » 08 Mar 2021, 21:04

Testing results for Rain/Wetness-sensor

Pictures from experiment inserted into the previous message.
Looking at the signal coming from the Rain/Wetness-sensor, it not really has a level with proportional characteristic related to resistance:
- dry => much noise & hum, with some minimal 1000Hz squarewave 'ripple' [apparently picking up 'environmental' transmission]
- wet => almost the original 1000Hz-output [due to low resistance between the 2 legs or the 2 array-segments]
- intermediate = not really distinctive.
First conclusion: perhaps usable as 'rough-level'-indicator, but not as measuring device .......
For that application must find a very simple setup enabling ESP8266 to read the signal from the sensor.

Addidtion of some basic components yields a working setup.
PWM_Moisture_sensor
PWM_Moisture_sensor
PWM_Moistsetup [50%].jpg (11.45 KiB) Viewed 15328 times
'Simplicity' rules, while 'Sensitivity' and 'Accuracy' are terms to be forgotten.
Components empirically choosen from available supply.

Functional flow:
- GPIO13 is output of a 3V squarewavesignal to leg A of the sensor-grid/fork
- The sensor-grid/fork attenuates the signal dependent on moisture (= resistance) on the grid or between the legs of the fork
- Signal from leg B rectified and 'cleaned/smoothed' by diode + C2 + C1
- A0 reads the 'cleaned' signal.
- In ESPEasy the formula for ADC scales the data [after some testing set to %value% * 10 ]
Present result: with this simple setup the feasability has been demonstrated,
but not for a sensitive dew-detector, more for a downpour-indicator.
Rainsensor_heavyshowers
Rainsensor_heavyshowers
Rainsensor_showers.jpeg (41 KiB) Viewed 15323 times
Is also a dillemma: if increasing the sensitivity by adding linear amplification of the signal from leg B, a downpour will clip the signal at the ceiling before it arrives at A0
;-) linear amplification already luxury, logarithmic amplification seems overdone ......

;-) Because the crisis still provides plenty of time to spend on the playground, perhaps worth trying this concept also as soil-sensor.
At least one bonus: this setup does not eat the legs of the fork by electro-corrosion.

Ton_vN
Normal user
Posts: 300
Joined: 21 Oct 2016, 15:20
Location: Hengelo (Ov)/ NL
Contact:

Re: Moisture sensor, using PWM-signal and A0

#3 Post by Ton_vN » 03 Nov 2021, 16:19

Setup for soil-measurementtest realised
using GPIO13/D7 for output and A0 = ADC

Configuration of elements outside the WEMOS-PCB:
C0 = 100uF
Diode = 'general' Si-diode
C2= 220uF
R1 = 47kOhm [optional over C2 for controlled discharge]
Sensor = Fork, with leg = 5cm steel nail, diam 2mm

Operational, but with questionmarks:
2-point-'Calibration':
Contacts open = super-dry soil = 8 units
Pens in water = super-wet soil = 13 units
For translation to cbar, using range 7/14 units => 1 unit = - 28.5 cbar
Observation:
very short range => coarse resolution
Furthermore reproduction of the scale is not stable.

;-( Some more experiments required to make it practical ......
Last edited by Ton_vN on 03 Nov 2021, 17:53, edited 1 time in total.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Moisture sensor, using PWM-signal and A0

#4 Post by TD-er » 03 Nov 2021, 17:08

Just to help me grasp the kind of measurement you're trying to make here.
Does the fork act as a capacitor or as a resistor?
If it is a resistor, then I think you will soon need to replace the sensor, as it will have direct contact to water.
So I guess it will make more sense to use a PCB which is made water resistant using the traditional solder mask (the green paint over the copper traces)
this is as thin as it can get and then any water on the surface is acting as a capacitor, which is probably easier to measure.

If using it as a resistor, you will probably not see a big change in resistance when using copper traces.

What you need is something like this:

Code: Select all

A
|--------|
         R
|--------|
R
|--------|
         R
|--------|
R
|--------|
         R
|--------|
R
|--------|
         R
|--------|
B   
With A and B being both connectors of the sensor.
The traces are parallel as in my ASCII art, thus every drop of water will then short out a resistor, or at least some resistance of the trace or wire or whatever material you plan to use.
This is proportional to the amount of water.
When using copper traces shaped as 2 forks as in your sensor, you won't see a lot of change between 1 drop or many drops.

You can still use the 2 forks like you have, but then it should not be used as a variable resistor, but more like a capacitor.
Maybe you can isolate it using some paint? Or some thin plastic film?

I can also help you to design a PCB which does have lots of traces to really act as a capacitor.

Ton_vN
Normal user
Posts: 300
Joined: 21 Oct 2016, 15:20
Location: Hengelo (Ov)/ NL
Contact:

Re: Moisture sensor, using PWM-signal and A0

#5 Post by Ton_vN » 03 Nov 2021, 17:53

@TDer,

Elco C0 in the circuit already blocks any DC-flow, but pure capacitive measurement indeed is preferred:
at this moment a capacitive pen-sensor is in another trial as rain/leafwetness-indicator.

IMHO basically any setup of the kind described in this thread is not very serious, but more for low-cost experimentation to get knowledge & experience .....
Especially the aspect of learning PWM-operation seems important for run-up to a possible application of the more expensive Watermark-sensors.

Choice of fork-construction for soil-measurement is part of this experiment.
'Steel nails' used and still in use elsewhere in my setups for a fork-sensor with analogue soil measuring:
;-) those steel nails last rather long (almost 3 years, compared to 3 months for the PCB-forks) even with significant electro-corrosion:
dirt cheap & very easy to replace.
The coming setup will apply the same steel nails but with PWM as signal, because
one aim of the experiment is comparison of corrosion between analogue-fed and PWM-fed nails.
True that thickly painting the nails will force them to work as capacitors:
will try that in Phase 2 of this experiment.
As 'spares' I still have several 'original analogue' PCB-forks:
to be tested in Phase 3.

The lower ADC-value is recognized as value from an 'open' ADC-input, probably due to noise etc.:
not strange for a very dry fork.
However wondering why the upper level ADC-value for 'pens-in-water' remains so low:
;) time to connect that old oscilloscope to check the signals around the fork and the interface-circuit.
Last edited by Ton_vN on 04 Nov 2021, 18:27, edited 5 times in total.

Ton_vN
Normal user
Posts: 300
Joined: 21 Oct 2016, 15:20
Location: Hengelo (Ov)/ NL
Contact:

Re: Moisture sensor, using PWM-signal and A0

#6 Post by Ton_vN » 04 Nov 2021, 17:51

8-) Back to Basics, in a very low power playground 'on square-cm' ......

In the interface-circuit, the elco C2 needs charging, to be seen by the ADC.
Reduced the size of C2 to 100uF for quicker (dis)charging.
The higher the input voltage to C2, the better:
- with single Si-diode hardly signal seen
- with 2 parallel Ge-diodes some signal variation [due to lower forward voltage and lower impedance]

Result from ADC (well repeatable):
Open contacts = 8 units [= no signal at reception pen, with ADC-level probably determined by background noise]
Pens-in-water = 12 units [= perfect 3Volt-squarewave at reception pen]
=> scaling-range is still very limited

Switching between open contacts and shortcut of the fork causes a very slow change of voltage on elco C2 (even for this relatively low size of elco).
(Just as 'what-if'-experiment, because PCB available) fitted the original interface-PCB of the Rain-Detector as buffer between the interface-circuit and the ADC, but only visible effect is that the output value from the ADC shifts by approx. 880 units, without expansion of the range, probably due to pull-up by the resistor in the comparator-circuit.
Conclusion seems that the square wave from the ESP8266 through the fork has 'enough voltage, but no muscle' to charge the elco C2.
Speed of change is not a real problem related to changes in soil conditions (which changes will be slow anyway), but higher magnitude of the upper ADC-level would be appreciated for better view at variations.
Contrarily, considering application in a rain-indicator speed is an essential aspect:
the observed slow rise and decay of the ADC-level may explain why the predecessor rain-indicator experiment was not very successful.
A small audio amplifier might provide the required 'muscle':
if the box with 'left-overs' has no candidate, perhaps ;) an investment required of Euro0.42/piece at AliX [see below].
Choice is now whether to fit at transmission-side or at receiver-side.
Fitting at receiver-side has (small) advantage that the capacitors of the amplifier keep out any DC-signals at receiverside:
truely AC-signalpath through fork & soil.
LM386preamp20*
LM386preamp20*
LM386preamp0 [320x200].png (38.57 KiB) Viewed 10436 times

Ton_vN
Normal user
Posts: 300
Joined: 21 Oct 2016, 15:20
Location: Hengelo (Ov)/ NL
Contact:

Re: Moisture sensor, using PWM-signal and A0

#7 Post by Ton_vN » 12 Dec 2021, 20:22

:o 'Old technology' sometimes useful for a better solution.
The setup with 1 diode (D1) did not yield sufficient signal level to the ADC.
The addition of a second diode (D2) improves/stabilizes the rectification of the incoming square wave signal so much that an amplifier is superfluous.
.
Moist_setup3
Moist_setup3
PWM_Vochtsetup3 [50%].jpg (14.38 KiB) Viewed 9584 times

Ton_vN
Normal user
Posts: 300
Joined: 21 Oct 2016, 15:20
Location: Hengelo (Ov)/ NL
Contact:

Re: Moisture sensor, using PWM-signal and A0

#8 Post by Ton_vN » 11 Jan 2022, 17:12

Observation / side-effect / learning-curve.
.
The grid-PCB of the rain-sensor is unheated.
The blue line in the graph clearly shows what happens when frost arrives in combination with fog:
- till 21:00 foggy & temperature is above 0, and the grid gets moisty => low impedance => high signal
- freezing has the effect that (due to the fog) ice sets on the grid => higher impedance => lower signal at ADC
- 12:00 next day the sun arrives = defrost => the grid detects moist & drop-off => grid dries => high & low signal.
.
Temperatures &amp; Wetness
Temperatures & Wetness
pibodem2_220111 [50%].png (47.85 KiB) Viewed 8840 times
.
;) Obvious next potential improvement: fitting a heating foil at the underside of the sensor-pcb.
Not much power required to keep PCB at T>0C:
feeding the foil with the same PWM-signal under condition of low temperature?
;) Have a surplus audio-amplfier to provide some 'muscle' for that function (if needed).
Or would that induce too much PWM-signal to the grid?

Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests