Dry wet soil detector. Corrosion-resistant soil moisture sensor, suitable for dacha automation. Materials needed to create a sensor yourself

Would you like your plants to tell you when they need to be watered? Or just kept you updated on soil moisture levels?

In this article we will look at an automated irrigation project using a soil moisture level sensor:

Soil Moisture Sensor Overview

Such sensors are quite easy to connect. Two of the three connectors are power (VCC) and ground (GND). When using the sensor, it is advisable to periodically disconnect it from the power source to avoid possible oxidation. The third output is a signal (sig), from which we will take readings. The two contacts of the sensor operate on the principle of a variable resistor - the more moisture in the soil, the better the contacts conduct electricity, the resistance drops, and the signal at the SIG contact increases. Analog values ​​may vary depending on the supply voltage and resolution of your microcontroller analog pins.

There are several options for connecting the sensor. The connector shown in the figure below:

The second option is more flexible:

And of course, you can directly solder the contacts to the sensor.

If you plan to use the sensor outside the apartment, you should additionally think about protecting the contacts from dirt and direct sunlight. It may be worth considering housing or applying a protective coating directly to the humidity sensor pins and conductors (see picture below).

Soil moisture level sensor with a protective coating applied to the contacts and insulated conductors for connection:

The problem of the fragility of the soil moisture level sensor

One of the disadvantages of sensors of this type is the fragility of their sensitive elements. For example, Sparkfun solves this problem by using additional coating (Electroless Nickel Immersion Gold). The second option for extending the life of the sensor is to supply power to it directly when readings are taken. When using Arduino, everything is limited to applying a HIGH signal to the pin to which the sensor is connected. If you want to power the sensor with more voltage than the Arduino provides, you can always use an additional transistor.

Soil moisture control - example project

The project below uses a humidity level sensor, an analogue of the Arduino board - RedBoard and an LCD display, which displays data about the soil moisture level.

SparkFun Soil Moisture Sensor:

The red wire (VCC) is connected to 5V on the Arduino, the black wire is to ground (GND), the green wire is signal to analog pin 0 (A0). If you are using a different analog pin on your Arduino, be sure to modify the microcontroller sketch below accordingly.

The LCD display is connected to 5V, ground and digital pin 2 (can also be modified and code changed) to communicate with the microcontroller via serial communication protocol.

It is worth noting that if you want to extend the life of your sensor, you can connect its power to the digital pin and power it only when reading data, and then turn it off. If you constantly power the sensor, its sensitive elements will soon begin to rust. The higher the soil moisture, the faster corrosion will occur. Another option is to apply plaster of Paris to the sensor. As a result, moisture will flow in, but corrosion will be significantly slowed down.

Program for Arduino

The sketch is quite simple. To transfer data to the LCD display, you need to connect the Software Serial library. If you don't have it, you can download it here: Arduino GitHub

Additional explanations are provided in the comments to the code:

// An example of using a soil moisture level sensor with an LCD display.

SoftwareSerial mySerial(3,2); // pin 2 = TX, pin 3 = RX (not used)

int thresholdUp = 400;

int thresholdDown = 250;

int sensorPin = A0;

String DisplayWords;

int sensorValue;

mySerial.write(254);

mySerial.write(128);

// clear the display:

mySerial.write(" ");

mySerial.write(" ");

// move the cursor to the beginning of the first line of the LCD display:

mySerial.write(254);

mySerial.write(128);

// "Dry, Water it!"

mySerial.write(254);

mySerial.write(192);

mySerial.print(DisplayWords);

) else if (sensorValue >= thresholdUp)(

// move the cursor to the beginning of the second line of the display:

mySerial.write(254);

mySerial.write(192);

mySerial.print(DisplayWords);

// move the cursor to the beginning of the second line of the display:

mySerial.write(254);

mySerial.write(192);

mySerial.print(DisplayWords);

The program uses different minimum and maximum values. As a result, the average value can characterize the moisture content depending on whether the soil is wet or dry. If you do not want to use this average, the maximum and minimum values ​​can be assumed to be the same. However, experiments show that the proposed approach makes it possible to more accurately characterize the processes that occur in the soil. There is no specific exact average value under real-world conditions. So you can play around with range sampling. If you are interested in the processes that occur in soil when interacting with water, read here, for example: Wiki. The processes are quite complex and interesting.

In any case, you need to adjust the variables to your own conditions: soil type, required level of moisture. So test and experiment until you decide on the appropriate values.

After organizing the reading of data from the humidity level sensor and displaying it, the project can be developed further by organizing an automatic watering system.

Humidity level sensor as part of an automatic irrigation system based on Arduino:

To automate irrigation, we will need additional parts: perhaps pulleys, gears, a motor, a coupling, transistors, resistors. The list depends on your project. Well, everything that can come to hand in everyday life. One example is shown in more detail below:

This is one of many options for installing a motor for an automatic irrigation system. The wheel can be installed directly in the water. In this case, when it rotates quickly, water will be supplied to the plant. In general, you can show your imagination.

The connection diagram for a DC motor () using an example of a copy of Arduino from SparkFun is shown below:

Below is an Arduino sketch (essentially the same as the one above with a small addition for motor control):

// The sketch reads data from the sensor and displays the soil moisture level

// if the soil is dry, the engine starts running

// To work with the display, the softwareserial library is used

#include <SoftwareSerial.h>

//Connect the LCD serial RX pin to digital pin 2 of the Arduino

SoftwareSerial mySerial(3,2); // pin 2 = TX, pin 3 = RX (unused)

// Control the motor using pin 9.

// This pin must support PWM modulation.

const int motorPin = 9;

// Here we set up some constants.

// Setting the constants depends on the environmental conditions in which the sensor is used

int thresholdUp = 400;

int thresholdDown = 250;

// Configure pin A0 on Arduino to work with the sensor:

int sensorPin = A0;

pinMode(motorPin, OUTPUT); // set the pin to which the motor is connected as an output

mySerial.begin(9600); // set the data exchange rate to 9600 baud

delay(500); // wait until the display loads

// Here we declare a string that stores the data to be displayed

// on the liquid crystal display. Values ​​will change

// depending on soil moisture level

String DisplayWords;

// The sensorValue variable stores the analog value of the sensor from pin A0

int sensorValue;

sensorValue = analogRead(sensorPin);

mySerial.write(128);

// clear the display:

mySerial.write(" ");

mySerial.write(" ");

// move the cursor to the beginning of the first line of the LCD display: mySerial.write(254);

mySerial.write(128);

// recording the necessary information on the display:

mySerial.write("Water Level: ");

mySerial.print(sensorValue); //Use .print instead of .write for values

// Now we will check the humidity level against the numeric constants we pre-specified.

// If the value is less than thresholdDown, display the words:

// "Dry, Water it!"

// move the cursor to the beginning of the second line of the display:

mySerial.write(254);

mySerial.write(192);

DisplayWords = "Dry, Water it!";

mySerial.print(DisplayWords);

// starting the engine at low speed (0 – stop, 255 – maximum speed):

analogWrite(motorPin, 75);

// If the value is not lower than thresholdDown it is necessary to check, it will not

// is it greater than our thresholdUp and, if, is greater than

// display "Wet, Leave it!":

) else if (sensorValue >= thresholdUp)(

// move the cursor to the beginning of the second line of the display:

mySerial.write(254);

mySerial.write(192);

DisplayWords = "Wet, Leave it!";

mySerial.print(DisplayWords);

// turning off the engine (0 – stop, 255 – maximum speed):

analogWrite(motorPin, 0);

// If the received value is in the range between the minimum and maximum

// and the soil was wet before, but is now drying out,

// display the inscription "Dry, Water it!" (that is, when we

// approaching thresholdDown). If the soil was dry and now

//quickly moisturizes, displays the words "Wet, Leave it!" (that is, when we

// approaching thresholdUp):

// move the cursor to the beginning of the second line of the display:

mySerial.write(254);

mySerial.write(192);

mySerial.print(DisplayWords);

delay(500); //Half a second delay between readings

Good luck with implementing automatic watering for your plants!

This simple homemade device is used for water or other liquid, in various rooms or containers. For example, these sensors are very often used to detect possible flooding of the basement or cellar with melt water or in the kitchen under the sink, etc.


The role of the humidity sensor is performed by a piece of foil fiberglass with grooves cut into it, and as soon as water gets into them, the machine will disconnect the load from the network. Or if we use the rear contacts, the automatic relay will turn on the pump or the device we need.

We manufacture the sensor itself in exactly the same way as in the previous diagram. If liquid gets on the contacts of the F1 sensor, the sound alarm will begin to emit a constant sound signal, and the HL1 LED will also light up.

Using the SA1 toggle switch, you can change the order of the HL1 indication to a continuous LED glow in standby mode.

This humidity sensor circuit can be used as a rain detector, overflow of a liquid container, water leakage, etc. The circuit can be powered from any five-volt DC power source.

The source of the sound signal is a sound emitter with a built-in sound generator. The humidity sensor is made from a strip of foil PCB with a thin track in the foil. If the sensor is dry, the sound signal does not signal. If the sensor gets wet, we will immediately hear an intermittent alarm signal.

The design is powered by a Krona battery and will last for two years, because during standby mode, the circuit consumes almost zero current. Another bonus of the circuit is the fact that almost any number of sensors can be connected parallel to the input and thus cover the entire controlled area at a time. The detector circuit is built on two 2N2222 type transistors connected in a Darlington manner."

List of radio components

R1, R3 - 470K
SW1 - button
R2 - 15k
SW2 - switch
R4 - 22K
B1 - crown type battery
C1 - capacitor with a capacity of 0.022 µF
T1, T2 - input terminals
PB1 - (RS273-059) piezo buzzer
Q1, Q2 - 2N2222 type transistors

When the first transistor opens, it immediately unlocks the second, which turns on the piezo buzzer. In the absence of liquid, both transistors are securely off and very low current is consumed from the battery. When the buzzer is turned on, the current consumption increases to 5 mA. Sound emitters of type RS273-059 have a built-in generator. If a more powerful alarm is needed, connect several buzzers in parallel or use two batteries.

We manufacture printed circuit boards with dimensions of 3*5 cm.

The test toggle switch connects a 470 kOhm resistance to the input, simulating the action of a liquid, thereby checking the functionality of the circuit. Transistors can be replaced with domestic ones, such as KT315 or KT3102.

An automatic humidity sensor is designed to turn on forced ventilation of a room at high air humidity; it can be installed in the kitchen, bathroom, cellar, basement, garage. Its purpose is to turn on the fans for forced ventilation of the room when the humidity in it approaches 95... 100%.

The device is highly economical, reliable, and its simplicity of design makes it easy to modify its components to suit specific operating conditions. The diagram of the humidity sensor is shown in the figure below.

The scheme works as follows. When the air humidity in the room is normal, the resistance of the dew sensor - gas resistor B1 does not exceed 3 kOhm, transistor VT2 is open, the powerful high-voltage field-effect transistor VT1 is closed, the primary winding of transformer T1 is de-energized. The load connected to the XP1 connector will also be de-energized.

As soon as the air humidity approaches the point of dew, for example, a boil left unattended, the bathroom is filled with hot water, the cellar is flooded with melted water, groundwater, the thermostat of the water heater has failed, the resistance of the gas resistor B1, the sharp alternating current is removed from the secondary winding T1 and supplied to the bridge diode rectifier VD2. Rectified voltage ripples are smoothed out by a high-capacity oxide capacitor C2. The parametric DC voltage stabilizer is built on a composite transistor VT3 with a high base current transfer coefficient of the KT829B type, a zener diode VD5 and a ballast resistor R6.

Capacitors SZ, C4 reduce output voltage ripple. Fans with an operating voltage of 12...15V, for example, “computer” fans, can be connected to the output of the voltage stabilizer. Fans with a total power of up to 100 W, designed for a supply voltage of 220 VAC, can be connected to the XP1 socket. A bridge rectifier VD1 is installed in the open supply circuit of the step-down transformer T1 and the high-voltage load. A pulsating DC voltage is supplied to the drain of the field-effect transistor. The cascade on transistors VT1, VT2 is powered by a stabilized voltage of +11 V, set by the zener diode VD7. The voltage is supplied to this zener diode through the chain R2, R3, VD4, HL2. This circuit design allows the field-effect transistor to be opened completely, which significantly reduces the power dissipated on it.

Transistors VT1, VT2 are included as a Schmitt trigger, which prevents the field-effect transistor from being in an intermediate state, thereby preventing its overheating. The sensitivity of the humidity sensor is set by trimming resistor R8, and, if necessary, by selecting the resistance of resistor R7. Varistors RU1 and RU2 protect device elements from damage by network voltage surges. The green LED HL2 indicates the presence of supply voltage, and the red LED HL1 signals high humidity and the device is switched to forced ventilation mode.

You can connect up to 8 low-voltage fans with a current consumption of up to 0.25 A each to the device and, or several fans with a supply voltage of 220 V. If using this device it is necessary to control a more powerful load with a supply voltage of 220 V, then to the output voltage stabilizer, you can connect electromagnetic relays, for example, type G2R-14-130, the contacts of which are designed for switching alternating current up to 10 A at a voltage of 250 V. In parallel with resistor R8, you can install a thermistor with negative TCR, resistance 3.3...4, 7 kOhm at 25°C, placed, for example, above a gas or electric stove, which will allow you to turn on the ventilation also when the air temperature rises above 45...50 °C, when the stove burners are operating at full power.

In place of transformer T1, you can install any step-down transformer with an overall power of at least 40 W, the secondary winding of which is designed for a current value not less than the current of the low-voltage load. Without rewinding the secondary winding “Yunost”, “Sapphire”. Unified transformers TPP40 or TN46-127/220-50 are also suitable. When making a transformer yourself, you can use an W-shaped magnetic core with a cross-section of 8.6 cm2. The primary winding contains 1330 turns of wire with a diameter of 0.27 mm.

Secondary winding 110 turns of winding wire with a diameter of 0.9 mm. Instead of the KT829B transistor, any of the KT829, KT827, BDW93C, 2SD1889, 2SD1414 series will do. This transistor is installed on a heat sink, the size of which will depend on the load current and the magnitude of the collector-emitter voltage drop VT3. It is advisable to choose a heat sink with which the temperature of the VT3 transistor body would not exceed 60°C.

If the voltage on the plates of capacitor C2 with a load connected to the output of the stabilizer is more than 20 V, then to reduce the power dissipated by VT3, you can unwind several turns from the secondary winding of the transformer. The field effect transistor IRF830 can be replaced with KP707V2, IRF422, IRF430, BUZ90A, BUZ216. When installing this transistor, it must be protected from breakdown by static electricity. Instead of SS9014, you can use any of the KT315, KT342, KT3102, KT645, 2SC1815 series. When replacing bipolar transistors, take into account the differences in pinouts.

KBU diode bridges can be replaced with similar ones KVR08, BR36, RS405, KBL06. Instead of 1N4006, you can use 1N4004 - 1N4007, KD243G, KD247V, KD105V. Zener diodes: 1N5352 - KS508B, KS515A, KS215Zh; 1N4737A - KS175A, KS175Zh, 2S483B; 1 N4741A - D814G, D814G1, 2S211ZH, KS221V.

LEDs can be of any general use, for example, AL307, KIPD40, L-63 series. Oxide capacitors are imported analogs of K50-35, K50-68. Varistors - any low or medium power for a classified operating voltage of 430 V, 470 V, for example, FNR-14K431, FNR-10K471. The gas resistor GZR-2B, sensitive to air humidity, was taken from an old domestic video recorder “Electronics VM-12”. A similar gas resistor can be found in other faulty domestic and imported VCRs or in old cassette video cameras. This gas resistor is usually bolted to the metal chassis of the tape drive. Its purpose is to block the operation of the device when the tape mechanism fogs up, which prevents the magnetic tape from wrapping and damaging. The device can be mounted on a printed circuit board measuring 105x60 mm. It is preferable to place the gas resistor in a separate box made of insulating material with holes, installed in a cooler place. It is also recommended to screw it to a small metal plate, perhaps through a thin mica insulating spacer. To protect the mounted board from moisture, the mounting and printed conductors are coated with several layers of FL-98, ML-92 varnish or tsaponlac.

There is no need to paint over the gas resistor. To check the device’s functionality, you can simply exhale air from your lungs onto the gas resistor or bring a container of boiling water closer. After a few seconds, the HL1 LED will flash and the fans connected as loads will begin to fight the increased humidity. In standby mode, the device consumes current from the network about 3 mA, which is very little. Since the device consumes less than 1 W of power in standby mode, it can be operated around the clock without worrying about power consumption. Since the device is partially galvanically connected to the 220 V AC mains voltage, appropriate precautions should be taken when setting up and operating the device.

As a result of numerous experiments, this soil sensor circuit appeared on one single chip. Any of the microcircuits will do: K176LE5, K561LE5 or CD4001A.

The air humidity sensor, the diagram and drawings of which are attached, makes it possible to fully automate the process of monitoring and managing the relative humidity of the air in any room. This humidity sensor circuit makes it possible to measure relative humidity in the range from 0–100%. With very high accuracy and stability of parameters

Light and sound alarm for water boiling. - Radio, 2004, No. 12, pp. 42, 43.
. - Circuitry, 2004, No. 4, pp. 30-31.
Constant" in the cellar. - CAM, 2005, No. 5, pp. 30, 31.

I have written a lot of reviews about dacha automation, and since we are talking about a dacha, automatic watering is one of the priority areas of automation. At the same time, you always want to take precipitation into account, so as not to needlessly run pumps and flood the beds. Many copies have been broken on the way to seamlessly obtaining soil moisture data. We review another option that is resistant to external influences.


A pair of sensors arrived in 20 days in individual antistatic bags:




Characteristics on the seller's website:):
Brand: ZHIPU
Type: Vibration Sensor
Material: Blend
Output: Switching sensor

Unpacking:


The wire has a length of about 1 meter:


In addition to the sensor itself, the kit includes a control board:




The length of the sensor sensors is about 4 cm:


The tips of the sensor look like graphite - they get dirty black.
We solder the contacts to the scarf and try to connect the sensor:




The most common soil moisture sensor in Chinese stores is this:


Many people know that after a short time it is eaten up by the external environment. The effect of corrosion can be slightly reduced by turning on the power immediately before the measurement and turning it off when there are no measurements. But this doesn’t change much, this is what mine looked like after a couple of months of use:




Someone tries to use thick copper wire or stainless steel rods; an alternative designed specifically for an aggressive external environment serves as the subject of a review.

Let's put the board from the kit aside and let's move on to the sensor itself. The sensor is a resistive type, changing its resistance depending on the humidity of the environment. It is logical that without a humid environment the sensor resistance is enormous:


Let's lower the sensor into a glass of water and see that its resistance will be about 160 kOhm:


If you take it out, everything will return to its original state:


Let's move on to tests on the ground. In dry soil we see the following:


Add some water:


More (about a liter):


Almost completely poured out one and a half liters:


I added another liter and waited 5 minutes:

The board has 4 pins:
1 + power
2 earth
3 digital output
4 analog output
After testing, it turned out that the analog output and ground are directly connected to the sensor, so if you plan to use this sensor connected to the analog input, the board does not make much sense. If you don’t want to use a controller, you can use a digital output; the response threshold is adjusted by a potentiometer on the board. Connection diagram recommended by the seller when using a digital output:


When using digital input:


Let's put together a small layout:


I used Arduino Nano here as a power source without downloading the program. The digital output is connected to the LED. It’s funny that the red and green LEDs on the board light up at any position of the potentiometer and the humidity of the sensor environment, the only thing is that when the threshold is triggered, the green light shines a little weaker:


Having set the threshold, we find that when the specified humidity is reached at the digital output 0, if there is a lack of humidity, the supply voltage is:




Well, since we have a controller in our hands, we’ll write a program to check the operation of the analog output. We connect the analog output of the sensor to pin A1, and the LED to pin D9 of the Arduino Nano.
const int analogInPin = A1; // sensor const int analogOutPin = 9; // Output to LED int sensorValue = 0; // read value from the sensor int outputValue = 0; // value output on the PWM pin with LED void setup() ( Serial.begin(9600); ) void loop() ( // read the sensor value sensorValue = analogRead(analogInPin); // translate the range of possible sensor values ​​(400-1023 - set experimentally) // in the PWM output range 0-255 outputValue = map(sensorValue, 400, 1023, 0, 255); // turn on the LED at the specified brightness analogWrite(analogOutPin, outputValue); // output our numbers Serial.print; ("sensor = "); Serial.print(sensorValue);
I commented out the entire code, the brightness of the LED is inversely proportional to the humidity detected by the sensor. If you need to control something, then it is enough to compare the obtained value with a certain experimentally determined threshold and, for example, turn on the relay. The only thing I recommend is to process several values ​​and use the average for comparison with the threshold, as random spikes or drops are possible.
We immerse the sensor and see:


Controller output:

If you remove it, the controller output will change:

Video of this test assembly working:

In general, I liked the sensor; it seems resistant to the external environment; time will tell whether this is true.
This sensor cannot be used as an accurate indicator of humidity (like all similar ones); its main application is determining the threshold and analyzing dynamics.

If there is interest, I will continue to write about my country crafts.
Thanks to everyone who read this review to the end, I hope someone finds this information useful. Full control over soil moisture and goodness to everyone!

I'm planning to buy +74 Add to favorites I liked the review +55 +99

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.

How does the FC-28 soil sensor work?

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 hold 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.

Arduino Soil Moisture Sensor designed to determine the moisture content of the soil in which it is immersed. It lets you know if your home or garden plants are under- or over-watered. Connecting 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 a soil moisture level indicator for a houseplant (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:
  • Arduino Uno board
  • Soil moisture sensor
  • 8 LEDs
  • Development board
  • Connecting wires.
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 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 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 a probe in the ground.