Arduino And Soil Moisture Sensor

Introduction

 
In my previous article, I explained about working with a fire sensor and in this article, I'll show you working with a soil moisture sensor to get the accurate moisture value in the soil.
 
Things you will need
  • Arduino Uno
  • Bread Board 
  • Soil Moisture Sensor 
  • Led 
Connection
  • Pin1 to the Analog
  • Pin2 to the Gnd
  • Pin3 to the 5v
 
Programming
  1. int pin=A0;      
  2. int soilmoisture=0;      
  3. int led=13;      
  4. void setup()      
  5. {      
  6.   pinMode(led,OUTPUT);      
  7.   Serial.begin(9600);      
  8. }      
  9. void loop()      
  10. {      
  11.   int soilmoisture=analogRead(pin);      
  12.        
  13.   if(soilmoisture>=100){      
  14.   digitalWrite(led,HIGH);      
  15. }      
  16. else{      
  17.   digitalWrite(led,LOW);      
  18. }      
  19.   Serial.println(soilmoisture);      
  20.   Serial.print("%");      
  21.   delay(20);      
  22. }    
Explanation
 
Declare the variable pin to the Analog and set the minimum value to the soil moisture sensor as 0 and connect the led to the digital pin 13
 
Functions
 
Void setup()
  • Set the pinMode to led as OUTPUT
  • Set the baud Rate( 9600) 
Void loop()
 
AnalogRead- Reads the analog value from the specific pin i.e soil moisture pin with the delay time
 
Condition
  1. if (soilmoisture >= 100)    
  2. {    
  3.     //led will on     
  4. }    
  5. else    
  6. {    
  7.     //led is off    
  8. }   
And then print the soil moisture sensor value in the serial monitor. 
 
Advantages
  • It reduces the human effort.
  • Based upon the irrigation the water will flow through the plant.
  • We can save our water.
Read more articles on Arduino: