Interface the soil moisture sensor with Arduino

What is a soil moisture sensor?

It is a type of sensor that is used to measure the moisture present in the soil. It has two parts, one that goes into the soil and another part that consists of a comparator to compare the signal value and then outputs data depending upon the moisture present in the soil. A potentiometer is also present on the module that is used to set the sensitivity of the sensor. The sensor outputs both analog and digital data. It can be used to design a system that is used to water the plants automatically.

Pin configuration of the soil moisture sensor

soil moisture sensor pin diagram

Pin Uses

  • Pin 1 is the A0 pin, you will get Analog data from this pin.
  • Pin 2 is the D0 pin, you will get Digital data from this pin.
  • Pin 3 is the GND pin used to connect the GND.
  • Pin 3 is the VCC pin used to connect the 5v. 

Features of the soil moisture sensor

  • The operating voltage of the sensor is between 3.3-5V DC.
  • The operating current of the sensor is <20mA.
  • The operating temperature of the sensor is 10°-30°C.
  • It uses LM393 comparator IC.

Components needed

  • Arduino UNO
  • Soil moisture sensor
  • Breadboard
  • Jumper wires

Pin connections of soil moisture sensor with Arduino UNO

  • Connect the VCC pin of the sensor to the 5v pin of the Arduino UNO.
  • Connect the GND pin of the sensor to the GND pin of the Arduino UNO.
  • Connect the D0 pin of the sensor to the D2 pin of the Arduino.
  • Connect the A0 pin of the sensor to the A0 pin of the Arduino.

Circuit diagram of soil moisture sensor with Arduino UNO

soil moisture sensor circuit diagram

Arduino code for the soil moisture sensor

int asensor=A0;//Define pin for A0 pin of the sensor 
int dsensor=2;//Define pin for D0 pinof the sensor
void setup() {
Serial.begin(9600);//Set baud rate for serial communication
}

void loop() {
int asensorData=analogRead(asensor);//Read analog datat from the sensor
int dsensorData=digitalRead(dsensor);//Read digital data from the sensor
Serial.print(" A Sensor Data:");
Serial.println(asensorData);//Print analog data on the serial monitor
Serial.print(" D Sensor Data:");
Serial.println(dsensorData);//Print digital data on the serial monitor
delay(1000);
}

Leave a Reply