How to use a Soil Moisture Sensor with Arduino

Posted on by
 Soil Moisture Sensor for Arduino

Soil Moisture Sensor for Arduino

If you are building a system to irrigate your plants automatically monitoring the soil moisture is more reliable than set watering cycles, so that only watering when your plants need, avoiding problems by overwatering. Here we will explain how to use one of these soil moisture sensors to Arduino.

Description

This sensor consists of two parts, the fork-shaped probe that has to be nailed to the ground, and an electronic module that will be used to connect the probe with Arduino. It operates with a 3.3V or 5V supply to be administered by the VCC and GND pins. The red LED will light when we are feeding.

Has both digital and analog functionality, the pin AO will give us an analog signal between the supply value to 0V (For Arduino UNO 5v to 0V) to higher humidity value will be higher, this is due to the operation of the probe because the higher the humidity is greater conductivity of the soil and therefore increase the value that we measure.

The DO pin will give us a digital signal is “1” when the humidity value is lower than manually establish on the potentiometer and ‘0’ when it is larger. The potentiometer is connected to a comparator LM393 as the probe signal. To use it correctly we must calibrate with different soil samples with different humidities. The green LED will help us in this task because when we have a 1 in DO will turn on.

Power supply 3.3V ~ 5V
LED Red: Power
Green: Digital output
Pinout
VCC: 3.3V-5V
GND: GND
DO: Digital output
AO: Analog output

Code

int DOpin = 2;

void setup() {
 Serial.begin(9600);
 pinMode(DOpin, INPUT);
}

void loop() {
 int DO = digitalRead(DOpin);
 int sensorValue = analogRead(A0);
 int hum = (sensorValue * 100)/1024;

 Serial.print("Digital value: ");
 Serial.println(buttonState);
 
 Serial.print("Analog value: ");
 Serial.println(sensorValue);
 
 Serial.print("Humidity: ");
 Serial.print(sensorValue);
 Serial.println("%");
 delay(1); 
}

Comments are disabled