Make a Soil Moisture Detection Device Using Arduino

Abstract
 
This article shows how to create a complete prototype for detecting the level of water (or more technically, moisture level) in your table plant. And when it finds the dirt inside the pot getting dry it will turn on the Green LED as a sign of water. And the rest of the time it will show Red.
 
GREEN LED as a sign of water
 
Figure 1: Green LED as a sign of water
 
Background
 
In this prototype design, we need a basic idea of Arduino codes where we will read the analog value coming from a soil moisture sensor. And, on successful condition, it will turn on the Red or Green LED.
 
The prerequisites for this prototype are the following:
  • Arduino UNO
  • 2 LEDs (Red and Green)
  • Soil Hygrometer Moisture Sensor Module
  • A few jumper wires
  • A table plant* (additional)
Soil Hygrometer Moisture Detection Module
 
Figure 2: Soil Hygrometer Moisture Detection Module
 
Soil Moisture Sensor Modules
 
Soil Moisture Sensor Modules have metallic probes with a metallic layer over it. It is also connected to a potentiometer module with four leads. The potentiometer controls the sensitivity of the module and you can set it depending on your needs. These leads of the module are connected to the Arduino UNO. Among the 4 leads, we will work with only three. The first is the Vcc (or, +) lead, where we 5 volts for the Arduino. The next one is GND (0), where we 0 volts. The third (A0) is of no use, so better leave that lead alone and the last is the analog lead that determines the soil-moisture value.
 
Courtesy
 
Figure 3: Courtesy: eBay.in
 
Specifications
  • Working Voltage 5v
  • Working Current <20mA
  • Interface: Analog
  • Depth of Detection: 37mm
  • Working Temperature: between 10-30° C
  • Weight: 3g
  • Size: 63x20x8 mm
  • Output Voltage Signal: 0-4.2 V
How it Works
 
The Moisture Sensor can read the amount of moisture present in the soil, or judge whether there is water or not. Physically, it has two probes that we place deep inside the soil. And that probe is controlled by another module that fixes the sensitivity of the soil moisture module. It has four leads where:
 
The first one is for Vcc and we 5 Volts across it. The second one is for GND.
 
And the last lead is for analog reading (in other words the analog pin).
 
Apart from this module, we will program two LEDs that show the level of moisture in the soil.
 
Sketch
  1. // SOIL MOISTURE SENSOR  
  2.   
  3. int RED= 12; // Digital PIN 12  
  4. int GREEN= 8; // Digital PIN 8  
  5. int PROBE= 0; // Ananlog PIN 0    
  6.   
  7. int value= 0;  
  8.   
  9. void setup() {  
  10.   Serial.begin(9600);  
  11.   pinMode(RED, OUTPUT);  
  12.   pinMode(GREEN, OUTPUT);  
  13.     
  14.   Serial.println("* SOIL MOSITURE PROBE *");  
  15.   Serial.println("-----------------------------");  
  16. }  
  17.   
  18. void loop() {  
  19.     
  20.  value= analogRead(PROBE);  
  21.  value= value/100;  
  22.  Serial.println(value);  
  23.  if(value<5)  
  24.  {  
  25.      
  26.    digitalWrite(RED, HIGH);  
  27.      
  28.  }  
  29.  else  
  30.  {  
  31.    digitalWrite(GREEN,HIGH);  
  32.  }  
  33.    
  34.    
  35.  delay(1000);  
  36.  digitalWrite(GREEN,LOW);  
  37.  digitalWrite(RED, LOW);  
  38. }  
Illustration
 
First, we will declare the following four variables: two for Red and Green, the third is for the analog pin and the last one is for the value that we received from the soil moisture.
 
In the Setup() block, we just declared the OUTPUT pins. I know, we have used two LEDs, so two pinMode() are there. Apart from that, we set the Serial Initializers.
 
Then, in the loop() block, first, we will read the analog value from the analogRead() method. And, we know it returns a three-digit number. So, to put the soil-moisture value on the scale of 10 we divided that value by 100.
 
After putting that value on the Serial, we will decide whether the moisture value is suitable for the plant or not.
 
For that, we first put the probe in water and check what it returns.
 
Put the probe in water
 
Figure 4: Put the probe in water
 
And, in return, it will show 2 as the moisture value and that is quite low on the scale of 10 (in other words a very high moisture value).
 
As a threshold, we use 5 as the critical value. If the moisture value gets below 5 then it suggests that the soil is moist (in other words has water). On the contrary, if the value gets above 5 then it needs to be watered (in other words a low value of water).
 
How it will look
 
Write the code and upload it to the Arduino. After uploading, open the Serial Monitor to see the moisture data.
 
Open Serial Monitor
 
Figure 5: Open Serial Monitor
 
In my case, the pot is too humid so I can't show you a dry soil's value. Still, I have placed that probe outside just to show how it will behave when there is less water or moisture in the pot.
 
Less water or moisture in pot
 
Figure 6: Less water or moisture in the pot
 

Conclusion

 
This is a very basic prototype design where we used just one sensor, in other words, Soil Moisture Sensor. Additionally, we can add an LCD screen that constantly shows the moisture value or shows a notification-area that notifies you when it goes low/high.