Let’s make soil moisture detector…

In this article, we will provide you with the source code of soil moisture detector which can be made using ARDUINO. You can find hardwaring part on many different websites like circuitstoday.com or many more.

Digital Mode – Interfacing Arduino and Soil Moisture Sensor

To connect the soil moisture sensor FC-28 in the digital mode, we will connect the digital output of the sensor to the digital pin of the Arduino. The Sensor module contains a potentiometer with it, which is used to set the threshold value. This threshold value is then compared with the sensor output value using the LM393 comparator which is placed on the sensor module.

The LM393 comparator will compare the sensor output value and the threshold value and then gives us the output through the digital pin. When the sensor value will be greater than the threshold value, then the digital pin will give us 5V and the LED on the sensor will light up and when the sensor value will be less than this threshold value, then the digital pin will give us 0V and the light will go down.

Circuit Diagram

The connections for connecting the soil moisture sensor FC-28 to the Arduino in digital mode are as follows.

  • VCC of FC-28 to 5V of Arduino
  • GND of FC-28 to GND of Arduino
  • D0 of FC-28 to pin 12 of Arduino
  • LED positive to pin 13 of Arduino
  • LED negative to GND of Arduino

Code is given here:

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);
int sensor = A0;
int output_value;

void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
Serial.begin(9600);
delay(2000);
lcd.begin (16,2); // for 16 x 2 LCD module
lcd.setBacklightPin(3,POSITIVE);
lcd.setBacklight(HIGH);
}

void loop() {
// put your main code here, to run repeatedly:
output_value=analogRead(sensor);
output_value=map(output_value, 0, 1023, 0, 100);
if (output_value>=50){
digitalWrite(13, LOW);

}
else {
digitalWrite(13, HIGH);

}
lcd.home (); // set cursor to 0,0
lcd.print(” tronixlabs.com”);
lcd.setCursor (0,1); // go to start of 2nd line
lcd.print(millis());
delay(1000);
lcd.setBacklight(LOW); // Backlight off
delay(250);
lcd.setBacklight(HIGH); // Backlight on
delay(1000);
Serial.print(“Moisture content: “);
Serial.print(output_value);
Serial.println(“%”);
delay(1000);
}

One thought on “Let’s make soil moisture detector…

Leave a Reply

Your email address will not be published. Required fields are marked *