Corrosion-resistant soil moisture sensor, suitable for dacha automation. Soil moisture sensor: principle of operation and do-it-yourself assembly Do-it-yourself soil moisture meter from a tester

The device that measures humidity levels is called a hygrometer or simply a humidity sensor. In everyday life, humidity is an important parameter, and often not only for the ordinary life, but also for various equipment, and for agriculture (soil moisture) and much more.

In particular, our well-being depends a lot on the degree of air humidity. Particularly sensitive to humidity are weather-dependent people, as well as people suffering from hypertension, bronchial asthma, diseases of the cardiovascular system.

When the air is very dry, even healthy people feel discomfort, drowsiness, itching and irritation of the skin. Dry air can often cause illness respiratory system, starting with acute respiratory infections and acute respiratory viral infections, and even ending with pneumonia.

At enterprises, air humidity can affect the safety of products and equipment, and in agriculture clearly the influence of soil moisture on fertility, etc. This is where the use of humidity sensors - hygrometers.

Some technical devices are initially calibrated to a strictly required value, and sometimes in order to fine-tune the device, it is important to have the exact humidity value in environment.

Humidity can be measured by several of the possible quantities:

    To determine the humidity of both air and other gases, measurements are carried out in grams per cubic meter when talking about the absolute value of humidity, or in RH units when talking about relative humidity.

    For measured humidity solids or in liquids, measurements as a percentage of the mass of the samples under study are suitable.

    To determine the moisture content of poorly mixed liquids, the units of measurement will be ppm (how many parts of water are in 1,000,000 parts of the weight of the sample).

According to the principle of operation, hygrometers are divided into:

    capacitive;

    resistive;

    thermistor;

    optical;

    electronic.

Capacitive hygrometers, in fact simple case, are capacitors with air as a dielectric in the gap. It is known that the dielectric constant of air is directly related to humidity, and changes in the humidity of the dielectric lead to changes in the capacitance of the air capacitor.

More difficult option capacitive sensor humidity in the air gap contains a dielectric, with a dielectric constant that can vary greatly under the influence of humidity on it. This approach makes the quality of the sensor better than simply with air between the capacitor plates.

The second option is well suited for measuring water content in solids. The object under study is placed between the plates of such a capacitor, for example, the object can be a tablet, and the capacitor itself is connected to oscillatory circuit and to an electronic generator, while the natural frequency of the resulting circuit is measured, and from the measured frequency the capacitance obtained by introducing the test sample is “calculated”.

Of course, this method also has some disadvantages, for example, if the sample humidity is below 0.5%, it will be inaccurate; in addition, the sample being measured must be cleared of particles with high dielectric constant; in addition, the shape of the sample during the measurement process is also important; it should not change during the course of the study.

The third type of capacitive humidity sensor is the capacitive thin film hygrometer. It includes a substrate on which two comb electrodes are applied. In this case, comb electrodes play the role of plates. For the purpose of temperature compensation, two additional temperature sensors are additionally introduced into the sensor.

Such a sensor includes two electrodes that are deposited on a substrate, and on top of the electrodes themselves is applied a layer of material that has a fairly low resistance, which, however, varies greatly depending on humidity.

Aluminum oxide may be a suitable material for the device. This oxide absorbs water well from the external environment, while its resistivity changes noticeably. As a result, the total resistance of the measurement circuit of such a sensor will depend significantly on humidity. Thus, the level of humidity will be indicated by the amount of current flowing. The advantage of sensors of this type is their low price.

A thermistor hygrometer consists of a pair of identical thermistors. By the way, let us recall that this is a nonlinear electronic component, the resistance of which strongly depends on its temperature.

One of the thermistors included in the circuit is placed in a sealed chamber with dry air. And the other is in a chamber with holes through which air with characteristic humidity enters it, the value of which needs to be measured. The thermistors are connected in a bridge circuit, voltage is applied to one of the diagonals of the bridge, and readings are taken from the other diagonal.

In the case when the voltage at the output terminals is zero, the temperatures of both components are equal, therefore the humidity is the same. If a non-zero voltage is obtained at the output, this indicates the presence of a humidity difference in the chambers. Thus, the humidity is determined from the value of the voltage obtained during measurements.

An inexperienced researcher may have a fair question: why does the temperature of the thermistor change when it interacts with moist air? The thing is that as humidity increases, water begins to evaporate from the thermistor body, while the temperature of the body decreases, and the higher the humidity, the more intense the evaporation occurs, and the faster the thermistor cools.

4) Optical (condensation) humidity sensor

This type of sensor is the most accurate. The operation of an optical humidity sensor is based on a phenomenon related to the concept of “dew point”. At the moment the temperature reaches the dew point, the gaseous and liquid phases are in thermodynamic equilibrium.

So, if you take glass and install it in a gaseous environment, where the temperature at the time of research is above the dew point, and then begin the process of cooling this glass, then at a specific temperature value water condensate will begin to form on the surface of the glass, this water vapor will begin to turn into the liquid phase . This temperature will be the dew point.

So, the dew point temperature is inextricably linked and depends on parameters such as humidity and pressure in the environment. As a result, having the ability to measure pressure and dew point temperature, it will be easy to determine humidity. This principle serves as the basis for the operation of optical humidity sensors.

The simplest circuit of such a sensor consists of an LED shining on a mirror surface. The mirror reflects the light, changing its direction, and directing it to the photodetector. In this case, the mirror can be heated or cooled using a special high-precision temperature control device. Often such a device is a thermoelectric pump. Of course, a sensor is installed on the mirror to measure temperature.

Before starting measurements, the mirror temperature is set to a value that is obviously higher than the dew point temperature. Next, the mirror is gradually cooled. At the moment when the temperature begins to cross the dew point, drops of water will immediately begin to condense on the surface of the mirror, and the light beam from the diode will break due to them, dissipate, and this will lead to a decrease in the current in the photodetector circuit. Through feedback, the photodetector interacts with the mirror temperature controller.

So, based on the information received in the form of signals from the photodetector, the temperature controller will keep the temperature on the surface of the mirror exactly equal to the dew point, and the temperature sensor will indicate the temperature accordingly. Thus, with known pressure and temperature, the main humidity indicators can be accurately determined.

The optical humidity sensor has the highest accuracy, unattainable by other types of sensors, plus the absence of hysteresis. The disadvantage is the highest price of all, plus high energy consumption. In addition, it is necessary to ensure that the mirror is clean.

The operating principle of an electronic air humidity sensor is based on changing the concentration of electrolyte covering any electrical insulating material. There are devices with automatic heating linked to the dew point.

Often the dew point is measured over a concentrated solution of lithium chloride, which is very sensitive to minimal changes in humidity. For maximum convenience such a hygrometer is often additionally equipped with a thermometer. This device has high accuracy and low error. It is capable of measuring humidity regardless of the ambient temperature.

Simple electronic hygrometers are also popular in the form of two electrodes, which are simply stuck into the soil, controlling its humidity according to the degree of conductivity depending on this very humidity. Such sensors are popular among fans because you can easily set up automatic watering of a garden bed or a flower in a pot, in case you don’t have time to water manually or it’s not convenient.

Before you buy a sensor, consider what you will need to measure, relative or absolute humidity, air or soil, what the expected measurement range is, whether hysteresis is important, and what accuracy is needed. The most accurate sensor is optical. Pay attention to the IP protection class, the operating temperature range, depending on the specific conditions where the sensor will be used, and whether the parameters are suitable for you.

The LED turns on when it is necessary to water the plants
Very low current consumption from 3V battery

Schematic diagram:

List of components:

Resistors 470 kOhm ¼ W

Cermet or carbon
trim resistor 47 kOhm ½ W

Resistor 100 kOhm ¼ W

Resistor 3.3 kOhm ¼ W

Resistor 15 kOhm ¼ W

Resistor 100 Ohm ¼ W

Lavsan capacitor 1 nF 63 V

Lavsan capacitor 330 nF 63 V

Electrolytic capacitors 10uF 25V

Red LED 5mm diameter

Electrodes (See notes)

3V battery (2 x AA, N or AAA batteries,
connected in series)

Device purpose:

The circuit is designed to give a signal if the plants need watering. The LED starts flashing if the soil is in flower pot too dry, and goes out when the humidity increases. Trimmer resistor R2 allows you to adapt the sensitivity of the circuit to various types soil, flower pot sizes and types of electrodes.

Scheme development:

This little device has been a big hit with electronics enthusiasts for many years, dating back to 1999. However, having corresponded with many hams over the years, I realized that some criticisms and suggestions should be taken into account. The circuit was improved by adding four resistors, two capacitors and one transistor. As a result, the device became easier to set up and more stable in operation, and the brightness of the glow was increased without using super-bright LEDs.
Many experiments have been carried out with different flower pots and different sensors. And although, as is easy to imagine, flower pots and electrodes were very different from each other, the resistance between two electrodes immersed in the soil by 60 mm at a distance of about 50 mm was always within the range of 500...1000 Ohms for dry soil, and 3000... 5000 Ohm wet

Circuit operation:

IC1A and its associated R1 and C1 form a square wave generator with a frequency of 2 kHz. Through an adjustable divider R2/R3, pulses are supplied to the input of gate IC1B. When the resistance between the electrodes is low (i.e., if there is enough moisture in the flower pot), capacitor C2 bypasses the input of IC1B to ground, and the output of IC1B is constantly present high level voltage. Gate IC1C inverts the output of IC1B. Thus, the input of IC1D is blocked low level voltage, and the LED is accordingly turned off.
When the soil in the pot dries out, the resistance between the electrodes increases, and C2 no longer prevents the flow of pulses to the input of IC1B. After passing through IC1C, the 2 kHz pulses enter the blocking input of the oscillator assembled on the IC1D chip and its surrounding components. IC1D begins to generate short pulses that turn on the LED through transistor Q1. LED flashes indicate the need to water the plant.
Rare bursts of short negative pulses with a frequency of 2 kHz, cut from the input pulses, are supplied to the base of transistor Q1. Consequently, the LED flashes 2000 times per second, but the human eye perceives such frequent flashes as a constant glow.

Notes:

  • To prevent oxidation of the electrodes, they are powered by rectangular pulses.
  • The electrodes are made from two pieces of stripped single-core wire, 1 mm in diameter and 60 mm in length. You can use the wire used for laying electrical wiring.
  • The electrodes must be completely immersed in the ground at a distance of 30...50 mm from each other. The material of the electrodes, dimensions and distance between them, in general, do not matter much.
  • Current consumption of about 150 µA when the LED is turned off, and 3 mA when the LED is turned on for 0.1 second every 2 seconds, allows the device to operate for years on one set of batteries.
  • With such a small current consumption, there is simply no need for a power switch. If, nevertheless, there is a desire to turn off the circuit, it is enough to short-circuit the electrodes.
  • The 2 kHz output from the first oscillator can be checked without a probe or oscilloscope. You can simply hear them if you connect the P2 electrode to the input of a low-frequency amplifier with a speaker, and if you have an ancient high-impedance TON-2 earphone, then you can do without an amplifier.
  • The circuit was assembled clearly according to the manual and is 100% working!!! ...so if it suddenly "doesn't work" then it's just an incorrect assembly or parts. To be honest, until recently I didn’t believe that it was “working”.
  • Question for the experts!!! How can you install a 12V DC pump with a consumption of 0.6A and a starting device of 1.4A as an actuator?!
  • Sobos WHERE to fit? What to manage?....Formulate the question CLEARLY.
  • In this scheme ( full description http://www..html?di=59789) the indicator of its operation is the LED, which lights up when the ground is “dry”. There is a great desire to automatically turn on the irrigation pump (12V constant with a consumption of 0.6A and a starting 1.4A) along with the inclusion of this LED, how to change or “complete” the circuit to realize this.
  • ...maybe anyone has any thoughts?!
  • Install an optorelay or optosimistor instead of the LED. The water dose can be adjusted by a timer or by the location of the sensor/watering point.
  • It’s strange, I assembled the circuit and it works great, but only the LED “when watering is necessary” fully flickers with a frequency of approximately 2 kHz, and is not constantly on, as some forum users say. Which in turn provides savings when using batteries. It is also important that with such a low power supply, the electrodes in the ground are subject to little corrosion, especially the anode. And one more thing: at a certain level of humidity, the LED begins to barely glow and this can continue long time, which did not allow me to use this circuit to turn on the pump. I think that to reliably turn on the pump, you need some kind of detector of pulses of the specified frequency coming from this circuit and giving a “command” to control the load. I ask SPECIALISTS to suggest a scheme for implementing such a device. Based on this scheme, I would like to implement automatic watering at my dacha.
  • A very promising scheme in terms of its “economics” that needs to be finalized and used in garden plots or for example at work, which is very important when there are weekends or vacations, as well as at home for automatic watering flowers.
  • was always within the range of 500...1000 Ohms for dry soil, and 3000...5000 Ohms for wet soil - in the sense - vice versa!!??
  • I think this is bullshit. Over time, salts are deposited on the electrodes and the system does not operate on time. A couple of years ago I did this, but I did it with two transistors according to the circuit from the MK magazine. It was enough for a week, and then it shifted. The pump worked and did not turn off, flooding the flower. I've seen alternating current circuits online, so I think I should try them.
  • Good day!!! As for me, any idea to create something is already good. - As for installing the system at the dacha, I would advise turning on the pump via a time relay (costs pennies in many electrical equipment stores) and setting it to turn off after a time from turning on. Thus, when your system jams (well, anything can happen), the pump will turn off after a guaranteed time sufficient for watering (you can choose it empirically). - http://tuxgraphics.org/electronics/201006/automatic-flower-watering-II.shtml This is a good thing, I didn’t assemble this particular circuit, I only used the connection to the Internet. A little glitchy (not the fact that my hands are very straight), but everything works.
  • I have collected diagrams for watering, but not for this one, which is discussed in this topic. The assembled ones work, one as mentioned above in terms of the time the pump is turned on, the other, which is very promising, in terms of the level in the pan where water is pumped directly into the pan. For plants this is the most best option. But the essence of the question is to adapt the specified scheme. The only reason is that the anode in the ground is almost not destroyed as in the implementation of other schemes. So, please tell me how to track the pulse frequency in order to turn on the actuator. The problem is further aggravated by the fact that the LED can barely glow certain time, and then just switch on to pulse mode.
  • The answer to the previously asked question regarding improving the soil moisture control scheme was received on another forum and verified to be 100% efficient :) If anyone is interested, write in a personal message.
  • Why such confidentiality and not immediately provide a link to the forum. For example, on this forum http://forum.homecitrus.ru/index.php?showtopic=8535&st=100 the problem was practically solved using MK, but it was solved using logic and tested by me. Only in order to understand it is necessary to read from the beginning of the “book”, and not from the end. I am writing this in advance for those who read a piece of text and begin to bombard with questions. :eek:
  • The link http://radiokot.ru/forum/viewtopic.php?f=1&t=63260 was not immediately given due to the fact that it would not be considered an advertisement.
  • for [B]Vell65
  • http://oldoctober.com/ru/automatic_watering/#5
  • This stage has already been passed. The problem was solved using another scheme. As information. The lower improved circuit has errors and the resistances are burning. Typing on the same site was completed without errors. When testing the circuit, the following shortcomings were identified: 1. It turns on only once a day, when the tomatoes have already wilted, and it’s better to keep silent about cucumbers. And just when the sun was shining, they needed [B]drip watering at the root because plants evaporate in extreme heat large number moisture especially cucumbers. 2. There is no protection against false activation when, for example, at night the photocell is illuminated by headlights or lightning and the pump is activated when the plants are sleeping and do not need watering, and turning on the pump at night does not contribute to healthy sleep for household members.
  • We remove the photosensor, see the first version of the circuit where it is missing, we select the elements of the timing circuit of the pulse generator as convenient for you. I have R1=3.9 Mohm. R8 which is 22m no. R7=5.1 Mohm. Then the pump turns on when the soil is dry, until the sensor gets wet. I took the device as an example of an automatic watering machine. Many thanks to the author.

The poet Andrei Voznesensky once said: “laziness is the engine of progress.” It is perhaps difficult to disagree with this phrase, because the majority electronic devices are created precisely for the purpose of facilitating our daily life, full of worries and all sorts of vain affairs.

If you are reading this article now, then you are probably very tired of the process of watering flowers. After all, flowers are delicate creatures, you overwater them a little, you’re unhappy, you forget to water them for a day, that’s it, they’re about to fade. And how many flowers in the world have died just because their owners went on vacation for a week, leaving the poor green creatures to wither in a dry pot! It's scary to imagine.

It is to prevent such terrible situations that automatic watering systems were invented. A sensor is installed on the pot that measures soil moisture - it is a metal rods from stainless steel, stuck into the ground at a distance of a centimeter from each other.

They are connected via wires to a circuit whose task is to open the relay only when the humidity drops below the set value and close the relay at the moment when the soil is saturated with moisture again. The relay, in turn, controls the pump, which pumps water from the reservoir directly to the root of the plant.

Sensor circuit

As is known, the electrical conductivity of dry and wet soil differs quite significantly; it is this fact that underlies the operation of the sensor. A 10 kOhm resistor and a section of soil between the rods form a voltage divider; their midpoint is connected directly to the input of the op-amp. The voltage is supplied to the other input of the op-amp from the midpoint of the variable resistor, i.e. it can be adjusted from zero to supply voltage. With its help, the switching threshold of the comparator, in the role of which the op-amp operates, is set. As soon as the voltage at one of its inputs exceeds the voltage at the other, the output will be logical “1”, the LED will light up, the transistor will open and turn on the relay. You can use any transistor, PNP structure, suitable for current and voltage, for example, KT3107 or KT814. Operational amplifier TL072 or any similar one, for example RC4558. A low-power diode, for example, 1n4148, should be placed in parallel with the relay winding. The supply voltage of the circuit is 12 volts.

Due to the long wires from the pot to the board itself, a situation may arise that the relay does not switch clearly, but begins to click with frequency AC on the network, and only after some time is installed in open position. To eliminate this bad phenomenon, you should place an electrolytic capacitor with a capacity of 10-100 μF in parallel with the sensor. Archive with the board. Happy building! Author - Dmitry S.

Discuss the article SOIL MOISTURE SENSOR DIAGRAM

Arduino Soil Moisture Sensor designed to determine the moisture content of the soil in which it is immersed. It allows you to find out about insufficient or excessive watering of your household or garden plants. Connection of this module to the controller allows you to automate the process of watering your plants, garden or plantation (a kind of “smart watering”).

The module consists of two parts: a YL-69 contact probe and a YL-38 sensor, wires for connection are included. A small voltage is created between the two electrodes of the YL-69 probe. If the soil is dry, the resistance is high and the current will be less. If the ground is wet, the resistance is less, the current is a little more. Based on the final analog signal, you can judge the degree of humidity. The YL-69 probe is connected to the YL-38 sensor via two wires. In addition to the contacts for connecting to the probe, the YL-38 sensor has four contacts for connecting to the controller.

  • Vcc – sensor power supply;
  • GND – ground;
  • A0 - analog value;
  • D0 – digital value of the humidity level.
The YL-38 sensor is built on the basis of the LM393 comparator, which outputs voltage to output D0 according to the principle: wet soil - low logical level, dry soil - high logical level. The level is determined by a threshold value that can be adjusted using a potentiometer. Pin A0 supplies an analog value that can be transferred to the controller for further processing, analysis and decision making. The YL-38 sensor has two LEDs that indicate the presence of power supplied to the sensor and the level of digital signals at output D0. The presence of a digital output D0 and a D0 level LED allows the module to be used autonomously, without connecting to a controller.

Module Specifications

  • Supply voltage: 3.3-5 V;
  • Current consumption 35 mA;
  • Output: digital and analog;
  • Module size: 16×30 mm;
  • Probe size: 20×60 mm;
  • Total weight: 7.5 g.

Usage example

Let's consider connecting a soil moisture sensor to Arduino. Let's create a project for soil moisture level indicator for indoor plant(your favorite flower that you sometimes forget to water). To indicate the level of soil moisture we will use 8 LEDs. For the project we will need the following parts: Let's assemble the circuit shown in the figure below


Let's launch the Arduino IDE. Let's create a new sketch and add the following lines to it: // Soil moisture sensor // http://site // contact for connecting the analog output of the sensor int aPin=A0; // contacts for connecting indication LEDs int ledPins=(4,5,6,7,8,9,10,11); // variable to save the sensor value int avalue=0; // variable for the number of glowing LEDs int counted=8; // value of full watering int minvalue=220; // critical dryness value int maxvalue=600; void setup() ( // initializing the serial port Serial.begin(9600); // setting up the LED indication pins // to OUTPUT mode for(int i=0;i<8;i++) { pinMode(ledPins[i],OUTPUT); } } void loop() { // получение значения с аналогового вывода датчика avalue=analogRead(aPin); // вывод значения в монитор последовательного порта Arduino Serial.print("avalue=";Serial.println(avalue); // scale the value by 8 LEDs counted=map(avalue,maxvalue,minvalue,0.7); // indication of the humidity level for(int i=0;i<8;i++) ( if(i<=countled) digitalWrite(ledPins[i],HIGH); //light the LED else digitalWrite(ledPins[i],LOW) ; // turn off the LED ) // pause before the next value is received 1000 ms delay(1000); ) The analog output of the sensor is connected to the analog input of the Arduino, which is an analog-to-digital converter (ADC) with a resolution of 10 bits, which allows the output to obtain values ​​from 0 to 1023. The value of the variables for complete watering (minvalue) and severe dry soil (maxvalue ) we obtain experimentally. Greater soil dryness corresponds to a larger analog signal value. Using the map function, we scale the analog value of the sensor to the value of our LED indicator. The higher the soil moisture, the higher the LED indicator value (number of lit LEDs). By connecting this indicator to a flower, we can see the degree of humidity on the indicator from a distance and determine the need for watering.

Frequently asked questions FAQ

1. Power LED does not light up
  • Check the presence and polarity of the power supplied to the YL-38 sensor (3.3 - 5 V).
2. When watering the soil, the soil moisture indicator LED does not light up
  • Adjust the response threshold using the potentiometer. Check the connection of the YL-38 sensor with the YL-69 probe.
3. When watering the soil, the value of the analogue output signal does not change
  • Check the connection of the YL-38 sensor with the YL-69 probe.
  • Check for the presence of a probe in the ground.

Connect an Arduino with an FC-28 Soil Moisture Sensor to detect when your soil under your plants needs water.

In this article we are going to use FC-28 Soil Moisture Sensor with Arduino. This sensor measures the volumetric water content of the soil and gives us the moisture level. The sensor gives us analog and digital data as output. We're going to connect it in both modes.

The soil moisture sensor consists of two sensors that are used to measure the volumetric water content. Two probes allow a current to pass through the soil, which gives a resistance value that ultimately measures the moisture value.

When there is water, the soil will conduct more electricity, which means there will be less resistance. Dry soil is a poor conductor of electricity, so when there is less water, the soil conducts less electricity, which means there will be more resistance.

The FC-28 sensor can be connected in analog and digital modes. First we will connect it in analog mode and then in digital mode.

Specification

FC-28 Soil Moisture Sensor Specifications:

  • input voltage: 3.3–5V
  • output voltage: 0–4.2V
  • input current: 35mA
  • output signal: analog and digital

Pinout

The FC-28 soil moisture sensor has four contacts:

  • VCC: power
  • A0: analog output
  • D0: digital output
  • GND: ground

The module also contains a potentiometer that will set the threshold value. This threshold value will be compared on the comparator LM393. The LED will signal us a value above or below the threshold.

Analogue mode

To connect the sensor in analog mode, we will need to use the analog output of the sensor. The FC-28 soil moisture sensor accepts analog output values ​​from 0 to 1023.

Humidity is measured as a percentage, so we will compare these values ​​from 0 to 100 and then display them on the serial monitor. You can set different moisture values ​​and turn the water pump on/off according to those values.

Electrical diagram

Connect the FC-28 soil moisture sensor to Arduino as follows:

  • VCC FC-28 → 5V Arduino
  • GND FC-28 → GND Arduino
  • A0 FC-28 → A0 Arduino

Code for analog output

For the analog output we write the following code:

Int sensor_pin = A0; int output_value ; void setup() ( Serial.begin(9600); Serial.println("Reading From the Sensor ..."); delay(2000); ) void loop() ( output_value= analogRead(sensor_pin); output_value = map(output_value ,550,0,0,100); Serial.print("Mositure: "); Serial.print(output_value); delay(1000);

Code Explanation

First of all, we defined two variables: one to hold the contact of the soil moisture sensor and another to store the output of the sensor.

Int sensor_pin = A0; int output_value ;

In the setup function, the command Serial.begin(9600) will help in communication between Arduino and serial monitor. After this, we will print “Reading From the Sensor...” on the normal display.

Void setup() ( Serial.begin(9600); Serial.println("Reading From the Sensor ..."); delay(2000); )

In the loop function, we will read the value from the analog output of the sensor and store the value in a variable output_value. We will then compare the output values ​​from 0-100 because humidity is measured as a percentage. When we took readings from dry soil, the sensor value was 550, and in wet soil, the sensor value was 10. We correlated these values ​​to get the moisture value. After that we printed these values ​​on the serial monitor.

void loop() ( output_value= analogRead(sensor_pin); output_value = map(output_value,550,10,0,100); Serial.print("Mositure: "); Serial.print(output_value); Serial.println("%") ; delay(1000);

Digital mode

To connect the FC-28 soil moisture sensor in digital mode, we will connect the digital output of the sensor to the digital pin of the Arduino.

The sensor module contains a potentiometer, which is used to set the threshold value. The threshold value is then compared with the sensor output value using the LM393 comparator, which is placed on the FC-28 sensor module. The LM393 comparator compares the sensor output value and the threshold value and then gives us the output value through a digital pin.

When the sensor value is greater than the threshold value, the digital output will give us 5V and the sensor LED will light up. Otherwise, when the sensor value is less than this threshold value, 0V will be transmitted to the digital pin and the LED will not light up.

Electrical diagram

The connections for the FC-28 soil moisture sensor and Arduino in digital mode are as follows:

  • VCC FC-28 → 5V Arduino
  • GND FC-28 → GND Arduino
  • D0 FC-28 → Pin 12 Arduino
  • LED positive → Pin 13 Arduino
  • LED minus → GND Arduino

Code for digital mode

The code for digital mode is below:

Int led_pin =13; int sensor_pin =8; void setup() ( pinMode(led_pin, OUTPUT); pinMode(sensor_pin, INPUT); ) void loop() ( if(digitalRead(sensor_pin) == HIGH)( digitalWrite(led_pin, HIGH); ) else ( digitalWrite(led_pin, LOW); delay(1000);

Code Explanation

First of all, we have initialized 2 variables to connect the LED pin and the digital pin of the sensor.

Int led_pin = 13; int sensor_pin = 8;

In the setup function we declare the LED pin as an output pin because we will turn on the LED through it. We declared the sensor pin as an input pin because the Arduino will receive values ​​from the sensor through this pin.

Void setup() ( pinMode(led_pin, OUTPUT); pinMode(sensor_pin, INPUT); )

In the loop function, we read from the sensor output. If the value is higher than the threshold value, the LED will turn on. If the sensor value is below the threshold value, the indicator will go off.

Void loop() ( if(digitalRead(sensor_pin) == HIGH)( digitalWrite(led_pin, HIGH); ) else ( digitalWrite(led_pin, LOW); delay(1000); ) )

This concludes the introductory lesson on working with the FC-28 sensor for Arduino. Successful projects to you.



CATEGORIES

POPULAR ARTICLES

2024 “mobi-up.ru” - Garden plants. Interesting things about flowers. Perennial flowers and shrubs