Measure Soil Humidity

By Emir

Knowing if there is water around and in your surroundings can be very useful for a lot of projects. If you have an idea that has anything to do with agriculture, growing plants, watering them or anything like that, this is the right tutorial for you.

In here, you will find out how to use the soil humidity sensor and use it to read analog and digital values.

Do not let the flowers wilt any more!

Step 1

Bill of materials

  • Arduino board with USB cable (we use Arduino Uno)
  • Soil humidity sensor
  • 3 pcs male to female wires
  • 2 pcs female to female wires
Step 2

Prepare soil humidity sensor

Soil humidity sensor comes in two parts.

Connect two pins at one part with two pins at other with female to female wires.

Use picture for reference.

Step 3

Connect soil humidity sensor with Arduino board for analog read

Soil humidity sensor can be used as analog and digital sensor.

In these next few steps we will use it as an analog sensor and then we will show how to use it as a digital sensor.

On sensor board there are four pins: Vcc, GND, D0 and A0.

Connect three female side wires pins with sensor male pins (Vcc - white, GND - black and A0 - brown) as on the picture.

Connect three male side wires pins with Arduino board (5V - white, GND - black and A0 - brown) as on the picture.

Wire coloring is not important, it is used for easier referencing.

Step 4

Open Arduino IDE and write code

Write the following code in Arduino IDE:

int sensor = A0; //Sensor pin

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

void loop() {
 int x = analogRead(sensor);
 Serial.println(x);
}
show more
Step 5

Upload code to Arduino

Connect Arduino with computer using USB cable.

Select "Tools"->"Board"->[Arduino board]. In our case it is Arduino Uno.

Then select "Tools"->"Serial port"->[Your serial port used for communication with Arduino]. In our case it is /dev/tty.usbmodem1411.

Click on "File"->"Upload" to upload code to Arduino.

Step 7

Connect soil humidity sensor with Arduino board for digital read

Soil humidity sensor can be used as analog and digital sensor. Before, we have described how to use it as an analog sensor.

In next few steps we will use it as a digital sensor.

On sensor board there are four pins: Vcc, GND, D0 and A0.

Connect three female side wires pins with sensor male pins (Vcc - white, GND - black and D0 - brown) as on picture.

Connect three male side wires pins with Arduino board (5V - white, GND - black and 2 - brown) as on picture.

Wire coloring is not important, it is used for easier referencing and also you can use any other digital pin on Arduino.

Step 8

Open Arduino IDE and write code

Write following code in Arduino IDE:

int sensor = 2; //Sensor pin

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

void loop() {
 int x = digitalRead(sensor);
 Serial.println(x);
}
show more
Step 9

Upload code to Arduino and check results in Serial Monitor

We described these two steps before.

Now, the results will be "0" or "1".

You can use potentiometer on sensor board to set sensor sensitivity, when will sensor switch value fomr "1" to "0".

In our case we set potentiometer to about 770 (analog read). We will read value "1" until value drops below 770. Then, the value will be "0" and additional LED on sensor board will turn on.

show more

Tutorial Forum

There are no posts here yet. Add the first post