Buy on Aliexpress
Capacitive soil moisture sensor module Corrosion Resistant V1.2 (price: $0.75 ) Capacitive Soil Moisture Sensor Module (price: $0.94 ) | Capacitive humidity sensor. | |
LM393 Soil Moisture Hygrometer Detection (Price: 0.41$) | Resistive humidity sensor. | |
T21D Digital Multimeter RM113D 6000 Counts (Price: 15$) | Cool multimeter, like mine. Measurement of all basic quantities + flashlight, magnet, light indication, wiring detector. |
Calculations
Capacity is calculated using the following expression:
Let the plates have dimensions w = 12 mm; l = 35 mm, then the area S = 12*35 = 420 mm², and the distance between them d = 3 mm, then the calculated electrical capacitance C = 1 pF .
The geometric dimensions (area) S, as well as the distance between the plates d, does not change. To change the capacitance, it remains to change the substance between the plates, as long as it is air ε = 1 . What do you think is the relative dielectric constant of water? Sources show ε = 81 .
Full immersion in water will increase the capacity by 81 times! The calculated capacitance C will no longer be 1 pF, but 100 pF .
Thus, by smoothly immersing this homemade condenser, the capacity will also smoothly and proportionally change, which makes it possible to effectively monitor the state of humidity.
Converting a change in capacitance into a change in voltage
By connecting a capacitor in series with a resistor, we obtain LPF ).
This results in a voltage divider where the resistance of the upper arm R1 does not change, but the capacitance of the lower arm C1 changes depending on the frequency.
But since the signal frequency will remain unchanged, we will plot the dependence of capacitance on capacitance (C = 1-100 pF):
Thus, it is clear that as the capacitance increases (immersion in water), the resistance of the lower arm will decrease, as will the voltage drop across it, and hence the output voltage (see experimental confirmation below).
But one more thing remains - to isolate only the amplitude; this is what an AM detector . His calculation was carried out, but it did not give anything useful, so the denominations were taken the same as those of the finished one. The main point is this:
you need to select the capacitance and resistance in such a way that the capacitor has time to recharge when the signal increases, and when it decreases, it is discharged during the low level, but when the signal changes, the envelope changes.
DIY Zigbee soil moisture sensor
Greetings Habr readers! I want to share with you my next project, today we will talk about a small sensor for measuring soil moisture on a CC2530 chip. The project is based on the open source development DIYRUZ Flower
, developer @anonymass. The sensor measures soil moisture using the capacitive method, runs on a CR2450 or CR2477 battery, has protection against battery reverse polarity, and is designed to work in Zigbee networks.
I have been looking towards Zigbee for a long time, a huge number of inexpensive factory-made devices that have appeared in recent years and the speed with which, after the appearance of the zigbee2mqtt project, this technology began to capture the minds of home automators, excellent DIY projects, which in many ways also became the driver of this popularity, everything these facts just screamed at you to go there.
Almost as soon as I acquired a small number of factory-made and DIY devices and launched my Zigbee network, I wanted to make something for myself. The idea to make a soil moisture sensor organically fit into my plans, since I was just finishing tests of my other project of a similar sensor on the nRF52 with an e-ink screen. Compact dimensions and appearance were all that were included in the requirements for the future project, and it turns out that I already had a blank for these requirements.
▍
After spending a couple of hours reworking the project on nRF52, the hardware part of the project on CC2530 was ready:
Based on experience (albeit modest, since I am not an agronomist) in the everyday use of such sensors on window sills and taking into account the consumption parameters of the CC2530 chips, the sensor was designed with minimal functionality, exclusively measuring soil moisture levels. The sensor board measures 137mm x 20mm; for ease of assembly, the electronic components are located on one side of the board, with the exception of the battery holder, which is soldered onto the back side of the board. The sensor has an LED, a couple of buttons, a programming port, and simple protection against reverse polarity of the transistor battery. The sensor assembly time for manual soldering is 10-15 minutes; the sensor circuit consists of only 10 elements, including the radio module.
▍
Sensor circuit:
While assembling the sensor takes 10-15 minutes, manufacturing the housing, unfortunately, cannot boast of this.
▍
There were no particular problems with the development of the housing model, since the housing from the nRF52 soil moisture sensor project with e-ink was also taken as a basis. A couple of touches in the editor and the case became a little thinner and without a cutout for the screen; with a couple more touches, the case was supplemented with a window for indicating the LED located on the board. I made two versions of the back cover for the CR2450 and CR2477 batteries. Printing all three parts of the case takes a little over an hour. This is where the easy part with the body ends, then the sad story begins: grinding, drilling, filling the indicator hole for the LED with liquid UV polymer, polishing. All this time took about one and a half to two hours. Probably, as the best and most correct option for making a case, you should consider simply printing the case on a well-configured printer; I’m sure the result will be no worse.
▍
The basis of the software part of the project is the popular DIYRUZ Flower project. I'm definitely not a programmer, my background is a couple of years of programming experience in Arduino, which basically allowed me to read the project code and understand it. Perhaps the most difficult part is setting up the development environment. But I will omit the description of the problems I encountered; in this article I will simply provide a couple of links to manuals and articles that I relied on (link 1, link 2, link 3) and will also thank the ZIGDEV chat members who are not indifferent to other people’s problems, who helped with advice. Changes I made to the original project code: increasing the reading interval of the soil moisture sensor to 1 hour, storing previous soil moisture values for comparison with new values and sending data to the network only when the values change by 1%. Added reading of the CC2530 internal temperature sensor, comparison, and sending data when the temperature changes by 1°C. Of course, the temperature accuracy from the internal temperature sensor has a large error, but in general it gives an understanding of changes in air temperature. More precisely, this parameter can be calibrated in the zigbee2mqtt converter, however, I did not see any special (and not special) need for this.
This is what the transfer of data on the level of soil moisture looks like, requesting the level of soil moisture through the Telegram module in Majordomo
The problem I encountered while testing
I decided to mention this, I’m sure it will help someone find a solution faster when faced with something similar. The question that arose when testing the sensors caused a misunderstanding in which direction to dig and gave rise to various magical theories :). The essence of the problem was that the sensors, with a weak signal (link quality<90), began to send announcements to the coordinator quite often; it was not very clear who was losing whom; accordingly, being awake for a longer period of time, the sensor more actively lost battery charge. The problem was solved after purchasing a coordinator from Jet Home (CC2652), purchased as a special offer.
Before this, the network worked on a ZigBee stick V4 coordinator (RF Star CC2652). I think this has something to do with the coordinator’s firmware, unfortunately, I don’t know what firmware is in my old one, but it’s the one that doesn’t have the LED indication on the coordinator board connected, in the future I plan to reflash the old coordinator into the router.
While these problems were observed, I even made another version of the board for a different radio module, its only plus is +5 units of karma to link quality, but the price tag of this module completely nullifies this buff :).
▍
On my
GITHUB,
for those who want to repeat, I have posted gerber project files for ordering boards, a list of components, a diagram, case models, project sources, compiled program files for flashing radio modules.
The device has already been added to the list of those supported on the zigbee2mqtt project on Github, the author of the project responds very quickly to pull requests.
A little about sad things in this direction, I use Majordomo as a smart home system at home, a wonderful z2m module was written for this system, unfortunately, my pull request has been hanging there unreviewed for a month, so for now I have written instructions on my github , where it is necessary to make changes so that the display of information about the sensor in Majordomo starts to sparkle with colors :).
The same sad story with another project - SLS gateway. I planned to deploy a Zigbee network controlled through an SLS gateway at the dacha, test it, test my sensors, and share my impressions. But I never managed to get the promised firmware with support for my sensor, they probably forgot, and external converters are not supported in this project :(.
Photo of the humidity sensor
What's in development now?
Outdoor zigbee temperature and humidity sensor with amplifier
If you, like me, want to understand what Zigbee is, try to make your first DIY Zigbee devices, then I invite you to the chat for developers of zigbee devices/firmware ZIGDEV
If you are interested in everything related to DIY, are you a DIY developer or just want start, you are interested in using DIY devices and want to be the first to know about my projects, then I invite everyone to the telegram chat - DIYDEV.I also invite readers to discuss this and any other devices in the main Telegram chat via Zigbee.
Thank you for your attention, all the best!
Testing in practice
First, the sensor itself, consisting of two pieces of foil-coated fiberglass FR-4 (70x12 mm).
*also do not forget to insulate exposed copper areas with adhesive tape
And also a miniature circuit diagram.
The signal is generated using a microcontroller (PWM, f = 1 MHz, D = 50%), of course this can be done using the same NE555 timer, but if the device already has a microcontroller, then why another MS?
Now we just connect the power (here 3.3 V), a voltmeter to the output and watch how the voltage changes when pouring water.
Very good, the readings change very smoothly and clearly.
All that remains is to digitize the readings using the ADC built into the MK and give them some semantic references, for example percentages.
How to choose a moisture detector size
First of all, it is established which of the following characteristics is required:
- Volumetric water content in soil.
- Soil water potential.
- Moisture release curves.
To select a sensor, it is important to correctly select the soil type and its texture. In addition, the accuracy of the device’s readings is limited to a certain area of the site. For example, in relation to a soil moisture sensor for indoor plants, this indicator is insignificant, but at the same time it is very important for a farmer or agronomist. Primary information about the type of soil includes the degree of its salinity (no more than 10 dS/m) and texture - the shape and size of its constituent particles, the presence of layers, cracks, etc. Accuracy increases if the device is characterized by minimal sensitivity to salts.
The detector is tested in the following sequence:
- Turn on the moisture meter.
- Set it up for the type of soil that is supposed to be tested for moisture.
- The probes are inserted into the soil to the recommended depth perpendicular to the surface until the lower plane of the body touches the soil.
- The display readings are taken and the values are compared with the reference values for the given measurement conditions.
- Repeat the measurement for soil areas located at a distance of 1.0...1.5 m. The spread of data should not exceed 0.5%. For heterogeneous soils, the distances between measurement points should be reduced.
If the soil is dry, then a wooden hammer can be used to improve the insertion of the probes into the soil, but the impacts should not be absorbed by the body of the device.
A more practical sensor made of galvanized plates
Covered with a layer of adhesive tape.
With dry ground, the output is approximately 1.5 V.
After super-abundant watering 0.75 V.
How it works?
Long-duration rectangular pulses (item 1), passing through the voltage divider formed by elements C2, R2, R3, Rsoil, R4, C3, are converted into short pulses (item 2). These pulses are fed through capacitor C4 to the input of element DD1.3. There, through resistor R6, a certain level of direct voltage (position 3) is supplied from the voltage divider R5.
When the total voltage level at input DD1.3 (item 4) reaches the comparator threshold (marked with a red dot), the one-shot monovibrator on DD1.3, DD1.4 is started. The duration of the control pulse at output DD1.4 is determined by the time constant R7, C5.
Return to top to menu.
Automatic watering system (the simplest version)
I bought a small water pump, it works well and is good for testing.
Pump control via a switch (field-effect transistor IRLML2502 ) with a 1 kHz PWM signal.
After calibration is completed, the program will turn off the pump when the voltage drops below the lower threshold (0.75V) and turn it on when it crosses the upper threshold (1.4V).
Irrigation automation actuators
The main actuator for irrigation automation is an electronic valve with and without water flow control. The latter are cheaper, easier to maintain and manage.
Valves produced by the American company Hunter have proven themselves well. Valves with bore diameters of 1, 1.5, and 2 inches with external or internal threads are used for various purposes.
There are many controlled cranes and other manufacturers.
If there are problems with water supply in your area, purchase solenoid valves with a flow sensor. This will prevent the solenoid from burning out if the water pressure drops or the water supply is cut off.
Application areas
Soil moisture
The most obvious application would be to determine soil moisture in a flower pot or just on the site.
Thus, you can integrate this sensor into an automatic plant watering system.
Presence of rain
To detect rain, you can also use a sensor of this type; simply place a sponge between the plates and collect the drops using a funnel.
Thus, during rain, the foam absorbs water, the capacity increases, and after the rain stops, the residue will go down, and after a while it will become dry again.
Water level in tank
Having a small (or large) supply of water in the tank is convenient to check its level from a distance, because usually the container is located somewhere in a hard-to-reach place at a height.
If the container is metal, then it can act as one electrode. If it is plastic, then you will have to make it, but it is not that difficult.
Touching the body
In one of the devices, the principle outlined above was used to detect touch to the human body, an example is below.
*this is an electronic thermometer; look at the upper right corner
Operating principle of the device
The original signal is transmitted through conductive probes and amplified. The potentiometer converts the voltage value into dielectric constant, and averages the resulting values over the length of the probes. Typically, detectors have an impact zone 20...40 mm long relative to the bottom surface of the housing. With increasing length, sensitivity (especially in the extreme areas) increases. To ensure the required measurement accuracy, the sensors are subjected to preliminary calibration.
The soil moisture sensor allows you to evaluate moisture loss over time due to evaporation and plant activity. The device can control the moisture content in the soil, controlling irrigation in greenhouses and other enclosed spaces (see Fig. 4).
Characteristics:
- Operating voltage: 2…5 V;
- Operating current: 20…40 mA;
- Interface type: analog or digital;
- Operating temperature of use: 10°C … 30°C.
For a digital detector to operate, it will need to be equipped with the necessary software before use.
Figure 4. Estimation of soil moisture for houseplants
Total
The advantage of a capacitive sensor over just two bare electrodes is the absence of an electrochemical reaction (electrolysis), in which substances will be restored at the contacts (from solution) and spoil the soil, and in addition they will themselves corrode. Of course, you can slow down this process very significantly (rarely poll the sensor), but still.
The copper pads are protected by a mask, but will it be durable enough in harsh conditions? The possibility of an additional coating with a layer of varnish/paint is being considered.
Manufacturing a capacitive sensor is easy using PCB manufacturing techniques, especially when the other components are located there. If it must be large, then we use scrap metal.
Since the readings obtained depend on the parameters of the sensor, it requires calibration.
Automation operating principle
In automatic watering systems, the rule is usually “water it or don’t water it.” As a rule, no one needs to regulate the water pressure. This is due to the use of expensive controlled valves and other unnecessary, technologically complex devices.
Almost all humidity sensors on the market, in addition to two electrodes, have a comparator in their design. This is the simplest analog-to-digital device that converts the incoming signal into digital form. That is, at a set humidity level, you will receive one or zero (0 or 5 volts) at its output. This signal will become the source for the subsequent actuator.
For automatic watering, the most rational option would be to use a solenoid valve as an actuator. It is included in the pipe break and can also be used in micro-drip irrigation systems. Turned on by supplying 12 V.
For simple systems operating on the principle “the sensor is triggered - the water flows”, it is sufficient to use the LM393 comparator. The microcircuit is a dual operational amplifier with the ability to receive a command signal at the output at an adjustable input level. The chip has an additional analog output that can be connected to a programmable controller or tester. An approximate Soviet analogue of the LM393 dual comparator is the 521CA3 microcircuit.
The figure shows a ready-made humidity relay along with a Chinese-made sensor for only $1.
Below is a reinforced version, with an output current of 10A at an alternating voltage of up to 250 V, for $3-4.