You are a beginner with Dasduino. 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 soldered 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 Dasduino and the basic code. Everything else is left to your imagination.


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 soldered in Croatia


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 Dasduino 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, Dasduino 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 Dasduino using its ADC converter, depending on the humidity of the soil.

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


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 Dasduino’s GND, + 5V to the digital pin 10 and connect the analog output of the sensor to the A0 pin on the Dasduino. Finally, we just need to connect the “fork” to the bottom two pins of the module according to the image below.


#define VccPin 10
unsigned int ocitanje;
void setup() {
  pinMode(VccPin, OUTPUT);
  //start the communication with the computer 
  //turn the sensor off
  digitalWrite(VccPin, LOW);
void loop() {
  //turn the sensor on
  digitalWrite(VccPin, HIGH);
  //read the sensor's value
  ocitanje = analogRead(A0);
  //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 = ");
  //wait 5 seconds