• Worldwide Shipping

• 24/7 Customer Support

• FAQ
• Worldwide Shipping

• 24/7 Customer Support

• FAQ

# HUM: soil humidity sensor

You are a beginner with Croduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by e-radionica where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect the module with Croduino and the basic code. Everything else is left to your imagination.

## INTRODUCTION

In today's tutorial, we will see how the soil humidity sensor works, how and when we can use this sensor along with its advantages and disadvantages.
For example, they can be used in automated plant watering projects, thereby reducing human labor and time spent doing simple plant care tasks.

• Voltage : 3V - 5V
• Output: digital and analog
• Dimensions : 40mm x 20mm
LM393 comparator on the board
• Manufactured by e-radionica.com in Croatia

## HOW DOES IT WORK?

This type of soil humidity sensor can be perceived as a variable resistor that changes values with the change in soil conductivity between its conductors. When the sensor's conductor (fork) is in the air, or when there is no medium that can conduct electricity, the Croduino will read it as a value of about 1000, ie. near the upper boundary of the A/D converter. When the sensor's conductors are completely immersed in the water, Croduino will display values around 300-400. Therefore, the sensor works on the principle of measuring the conductivity of the soil in which its conductors (fork) are located, the damper the soil, the higher the conductivity of the soil.

There is a built-in comparator on the module, which provides HIGH / LOW (0V or 5V) values on the "DO" pin, depending on the threshold that is set by rotating the potentiometer on the module, and on the "AO" pin, it provides values between 0V and 5V which can be read as values between 0 and 1023 by the Croduino using its ADC converter, depending on the humidity of the soil.

LIFECYCLE
One of the main issues of such sensors is their relatively short lifecycle, due to constant exposure to external conditions, especially to humidity. Due to the flow of DC current, the sensor will slowly lose its copper layer and will eventually no longer be able to conduct electricity or measure humidity of the soil. But, there is a simple solution that can significantly extend the lifecycle of the sensor. Instead of connecting the +5V pin directly to +5V, we can connect that pin to some other Croduino digital pin and therefore control the current flowing through the sensor. In the first case, the current will flow constantly through the sensor and it will corrode faster, while in the second case, the current will flow only when we need to make a measurement, and we can do it, e.g. every half-hour.

## HOW TO CONNECT IT?

In the following example, we will use a pin on the analog sensor that will provide values between 0 and 1023 depending on the humidity of the soil. Connect GND to Croduino's GND, + 5V to the digital pin 10 and connect the analog output of the sensor to the A0 pin on the Croduino. Finally, we just need to connect the "fork" to the bottom two pins of the module according to the image below.

## ARDUINO CODE

```#define VccPin 10
unsigned int ocitanje;

void setup() {
pinMode(VccPin, OUTPUT);
//start the communication with the computer
Serial.begin(9600);
//turn the sensor off
digitalWrite(VccPin, LOW);
}

void loop() {
//turn the sensor on
digitalWrite(VccPin, HIGH);
delay(25);
//read the sensor's value
//turn the sensor off
digitalWrite(VccPin, LOW);
//convert the reading to percentage
ocitanje = map(ocitanje, 400, 1002, 100, 0);
ocitanje = constrain(ocitanje, 0, 100);
//display the percentage of soil humidity on the Serial Monitor
Serial.print("Postotak vlage = ");
Serial.print(ocitanje);
Serial.println("%");
//wait 5 seconds
delay(5000);
}

```