The Soil Moisture Monitoring System is designed to measure the moisture level of the soil using a DFRobot Capacitive Soil Moisture Sensor and an Arduino UNO microcontroller. The system reads the analog value from the moisture sensor and outputs a qualitative status of the soil's moisture level to the serial monitor. The status can be "too wet," "perfect," or "too dry," depending on the sensor's reading compared to predefined threshold values.
/* Soil Moisture Monitoring System
* This code is designed to work with an Arduino UNO and a DFRobot Capacitive Soil Moisture Sensor.
* It reads the moisture level from the sensor and prints out the status of the soil moisture.
* The status can be "too wet", "perfect", or "too dry" based on predefined threshold values.
*/
// Threshold values for soil moisture levels
#define wetSoil 277 // Define max value we consider soil 'wet'
#define drySoil 380 // Define min value we consider soil 'dry'
// Define analog input pin connected to the soil moisture sensor
#define sensorPin A0
void setup() {
// Initialize serial communication at 9600 bits per second
Serial.begin(9600);
}
void loop() {
// Read the value from the soil moisture sensor
int moisture = analogRead(sensorPin);
Serial.print("Analog output: ");
Serial.println(moisture);
// Determine the status of the soil based on the moisture level
if (moisture < wetSoil) {
Serial.println("Status: Soil is too wet");
} else if (moisture >= wetSoil && moisture < drySoil) {
Serial.println("Status: Soil moisture is perfect");
} else {
Serial.println("Status: Soil is too dry - time to water!");
}
Serial.println();
// Wait for 1 second before taking the next reading
delay(1000);
}
This code is saved as sketch.ino
and is intended to be uploaded to the Arduino UNO microcontroller. It includes a setup routine that initializes serial communication and a loop that continuously reads the moisture level, evaluates it against the threshold values, and prints the status to the serial monitor. The system pauses for one second between readings to allow for a stable measurement.