Summer is rapidly approaching here in
Switzerland, and with it also the problem of watering our plants. As Makers, we want to
measure the humidity to control it. Unfortunately, most humidity sensors destroy themselves after
a short while. We need a better solution.
Grüezi YouTubers. Here is the guy with the
Swiss accent. With a new episode and fresh ideas around sensors and microcontrollers.
Today we will test different sensors, and I will show you, how they work and why most sensors
from China destroy themselves. And of course, we will find a solution to the problem.
Plants need a defined humidity to prosper. This is why we want to control the watering of
plants using our Home Automation system. The controller has to measure the moisture of the soil
and to give commands to a pump or a solenoid.
If you go to our usual purchasing platforms
and enter Moisture sensor or water sensor and “Arduino” you get these proposals:
1. A two-legged sensor with a separate small controller PCB. It has two pins on the sensor PCB
and four pins to connect it to a microcontroller. It provides a digital and an analog output. The
digital output can be adjusted by a trimmer. There are conducting tracks exposed on both legs
2. A similar two-legged sensor with control logic on the same board. It only
provides an analog output
3. A sensor similar to #2. It connects every
second copper path to emulate the “legs.”
4. Sometimes the legs are of solid metal,
and the price of the sensor is much higher
5. The last sensor looks different. It does
not have any exposed copper path and more electronics at the top. It is more expensive than
the cheap ones. It also provides an analog output
Let’s start with Number 1. How does it work?
The sensor, which is pictured like a resistor, is connected to VCC via a 510k Ohms resistor.
These two resistors form a voltage divider, and the analog output signal is the voltage drop
across the sensor. Let’s check if this is true: First we use our ohm meter to check if the
water has a resistance. It fluctuates a lot, but it is not indefinite. The more water between
the legs the smaller the output voltage.
The rest of the circuit on this sensor
PCB is a comparator which compares the measured value with a constant. Usually, we
do not use this digital output because we can do that much more elegant in software.
The sensor is connected now to its PCB and to 5 volts. The analog output
voltage is close to 5 volts. As soon as the sensor touches the water, it starts
to conduct, and the voltage drops considerably. The more we dive the sensor into the water the
lower the resistance and the lower the voltage.
We all know that we do not water our plants like
that. Most plants grow in moist soil. But still, the principle is the same. The more water
between the two legs the lower the voltage. Efficient and straightforward as it seems.
We will later see that this is not true.
The next two sensors do not have a digital
output and therefore do not need the Opamp. But they have a transistor aboard. If we look
at the diagram, we see that one “leg” of these sensors is connected to Vcc. The 100-ohm resistor
is just a protection against short circuit. The other leg of the sensors is connected to the
base of the transistor. The other two pins of the transistor are connected to Vcc and, via
a resistor, to ground. Also here the analog output is the voltage across the resistor.
The purpose of the transistor is to amplify the base current by a factor
of let’s say 50. As before, if the moisture sensor senses water, it reduces
its resistance, and a current can flow into the base. A much stronger current flows through the
collector and creates a 50 times higher current. The lower the resistance of the sensor the higher
the base current, the higher the collector current and the higher the voltage. This is precisely what
we see. The amplification of the transistor leads to a much smaller current flowing through the
sensor. Which is good, as we will see later on.
Also, this sensor works.
If you talk to people who used these sensors, they tell you that, after
a while, they stop to work. I show you, why:
Because we do not have a lot of time, I
will accelerate the effect which happens in the soil. I connect the two legs to my power
supply, precisely as it is done in the sensors. The only difference: I do not limit the current.
Now I put the sensor in water. Also as intended. If you have a close look, you see strange things
happen. Bubbles in the glass. And the right leg starts to change its color. It loses the plating.
After a few minutes the current stops. The right leg is interrupted because all copper was taken
away. If you look at the sensor, it does not look healthy. And if you watch the water (this
is where your plants would live), it also does not look healthy. I am sure one of my viewers
can enlighten us about the chemical reaction and how dangerous this green stuff is. Fact is:
The sensor is dead. The same happens if you replace it again. It is not a quality issue. It
happens because of the water and the DC current.
To prevent this from happening we could isolate
the electrodes from the water. If we do that, the sensor does not work at all. So, this is not
the solution. I propose to avoid these sensors.
Let’s continue with the last sensor: This one
has no copper exposed to water, and its legs cannot be dissolved. Good. But how does it work?
When we tried to isolate the sensor legs before, it did not work. So let’s check if
this one works. Yes, it does. Cool. Also, this sensor uses a chip. This time not an
Opamp, but an NE555 timer. The diagram looks like that: The NE555 works in astable mode and creates
a square wave. This square wave goes to one leg of the sensor. The other leg is connected to ground.
What happens if we put the sensor int the water? The two isolated legs form a capacitor.
Together with the water its capacity changes. If we look at the resistance
formula of a capacitor, we see that it is reduced if the capacitance gets bigger. This
is precisely the behavior we were looking for. Very good. BTW: You see, that its resistance
is also reduced with an increasing frequency.
This resistance is not a “real” resistance.
But I will not bother you with complex numbers. The sensor also works if we
do not understand these calculations.
In the end, a diode and a capacitor are used to
smoothen the square wave, and we get an analog value which changes with the humidity. Without
contact to the water. And this sensor also does not need a lot of parts.
You do not believe me? Look at this circuitry on the breadboard.
And here to my home-made sensor. I know, it is not good looking. But this is not a channel
about good looks and Make-up. I just used an old PCB and separated two areas with the hand-drill.
Now I have to isolate it from the water. I do this with a simple plastic bag. Done. And
we need a square wave. Instead of an NE555, I use my waveform generator. Like
that, I also can change the frequency.
On channel one, you see the square wave and on
channel two the output of the sensor. And really, if I dip my sensor into the water the sensor
value changes. Now you can believe me.
Here you see the effect of frequency
on the range of the sensor. The biggest difference between no water and fully submersed
results with frequencies around 600-900kHz. The frequency used by this sensor is about
570 kHz because an NE555 cannot do much more…
We still have to solve a small issue: Because
the suppliers of these capacitive sensors use a standard PCB they leave the edges without
protection and water easily can enter here. You either put your sensor into a plastic bag, or
you use some sort of protective lacquer like this one or that one.
Summarized:
- We learned the principles of moisture sensing
- We know which sensors can be used over a more extended period
- And we know how we have to enhance them to become even more stable
The summer can start now.
I hope, this video was useful or at least interesting for you. If true,
please consider supporting the channel to secure its future existence. You find the
links in the description. Thank you! Bye