This document describes a simple soil moisture sensing circuit that utilizes an Arduino UNO microcontroller and a Capacitive Soil Moisture Sensor V1.2. The purpose of this circuit is to measure the moisture level of the soil, which can be useful for gardening or agricultural applications. The sensor outputs an analog signal that is read by the Arduino, which then processes the signal and outputs the moisture level to the serial monitor.
#include <CapacitiveSensor.h>
const int AirValue = 520; //you need to replace this value with Value_1
const int WaterValue = 260; //you need to replace this value with Value_2
int intervals = (AirValue - WaterValue)/3;
int soilMoistureValue = 0;
void setup() {
Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
}
void loop() {
soilMoistureValue = analogRead(A0); //put Sensor insert into soil
if(soilMoistureValue > WaterValue && soilMoistureValue < (WaterValue + intervals)) {
Serial.println("Very Wet");
Serial.println(soilMoistureValue);
}
else if(soilMoistureValue > (WaterValue + intervals) && soilMoistureValue < (AirValue - intervals)) {
Serial.println("Wet");
Serial.println(soilMoistureValue);
}
else if(soilMoistureValue < AirValue && soilMoistureValue > (AirValue - intervals)) {
Serial.println("Dry");
Serial.println(soilMoistureValue);
}
delay(100);
}
AirValue
and WaterValue
to represent the sensor readings in air and water, respectively. These values should be calibrated according to the specific sensor and conditions.intervals
variable is used to divide the range between AirValue
and WaterValue
into three equal parts to classify the soil moisture level as "Very Wet," "Wet," or "Dry."analogRead(A0)
function reads the analog value from the sensor and stores it in soilMoistureValue
.Serial.println()
function is used to output the moisture level and the raw sensor value to the serial monitor for debugging and monitoring purposes.