This circuit is designed to monitor soil moisture levels and control a water pump based on the moisture readings. It utilizes an Arduino Nano microcontroller to read data from a soil moisture sensor and a DHT11 sensor for humidity and temperature measurements. A relay module is used to control the water pump, which is activated when the soil moisture level falls below a specified threshold. The circuit also includes an ESP32 microcontroller for additional functionalities, such as wireless communication.
#include <DHT.h>
#define DHTPIN 6 // DHT11 data pin connected to pin D6
#define DHTTYPE DHT11 // DHT11 sensor
#define RELAY_PIN 7 // Relay control pin
#define MOISTURE_SENSOR A0 // Soil moisture sensor analog pin
DHT dht(DHTPIN, DHTTYPE);
void setup() {
pinMode(RELAY_PIN, OUTPUT);
pinMode(MOISTURE_SENSOR, INPUT);
Serial.begin(9600);
dht.begin();
}
void loop() {
int moistureLevel = analogRead(MOISTURE_SENSOR); // Read soil moisture level
float humidity = dht.readHumidity(); // Read humidity
float temperature = dht.readTemperature(); // Read temperature
int threshold = 500; // Moisture threshold
// Print sensor data to Serial Monitor
Serial.print("Soil Moisture Level: ");
Serial.println(moistureLevel);
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println("%");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println("°C");
// Check if soil is dry, activate water pump
if (moistureLevel < threshold) {
digitalWrite(RELAY_PIN, HIGH); // Turn on water pump
Serial.println("Watering the plants...");
} else {
digitalWrite(RELAY_PIN, LOW); // Turn off water pump
Serial.println("Soil moisture is sufficient.");
}
delay(2000); // Wait before taking next reading
}
This documentation provides a comprehensive overview of the circuit, its components, wiring details, and the code used for operation.