5.8 Soil Humidity Monitoring System
5.8.1 Soil Humidity Sensor

Pay attention:Do not overflow water from plastic pools in experiments. Spilling water on other sensors may cause not only a short circuit or modules to be out of work but also heat generation and even explosion. Do be extra careful! Especially for younger users, please operate with your parents.
Open the 5.8.1Soil-Humidity-Sensor code with Arduino IDE.
#define SoilHumidityPin 32
void setup() {
Serial.begin(9600);
pinMode(SoilHumidityPin,INPUT);
}
void loop() {
//Define a variable as the value of soil humidity sensor
int ReadValue = analogRead(SoilHumidityPin);
Serial.println(ReadValue);
delay(500);
}
Choose the ESP32 Dev Module board and COM port, and upload the code.

Test Result:
Open the serial monitor. Touch the detection area of the sensor with a wet finger and the currently detected humidity value will be printed on the monitor(range: 0~4095).

Soil humidity sensors are mainly used to measure water content in volumetric soil, monitor soil moisture,irrigate crops and protect forests.

5.8.2 Soil Humidity Monitoring System
We adopt LCD1602 to reveal the real-time value of soil humidity value. When the value is lower than the set minimum humidity,the buzzer will emit sound to prompt farmers of irrigation.
Open the 5.8.2Soil-Humidity-Testing-System code with Arduino IDE.
#include <LiquidCrystal_I2C.h>
#define BuzzerPin 16
#define SoilHumidityPin 32
LiquidCrystal_I2C lcd(0x27,16,2);
void setup() {
ledcAttachChannel(BuzzerPin,1000,8,4);
pinMode(SoilHumidityPin,INPUT);
lcd.init();
lcd.backlight();
lcd.clear();
}
void loop() {
float shvalue = analogRead(SoilHumidityPin);
lcd.setCursor(0, 0);
lcd.print("SoilHum:");
lcd.setCursor(9, 0);
lcd.print(shvalue);
//When the detected value is lower than the set threshold, the buzzer emits sound
if(200 >= shvalue)
{
ledcWriteTone(BuzzerPin,532);
delay(100);
ledcWriteTone(BuzzerPin,532);
delay(100);
ledcWriteTone(BuzzerPin,659);
delay(100);
ledcWriteTone(BuzzerPin,0); //Stop alarming
}
delay(500);
lcd.clear();
}
Choose the ESP32 Dev Module board and COM port, and upload the code.

Test Result:
The LCD1602 displays the reveal the real-time value ofsoil humidity value. When the value detected by the soil humidity sensor is lower than 200, the buzzer emits sound to alarm.

Pay attention: Do not overflow water from plastic pools in experiments. Spilling water on other sensors may cause not only a short circuit or modules to be out of work but also heat generation and even explosion. Do be extra careful! Especially for younger users, please operate with your parents.