This document describes an automated plant watering system designed to monitor soil moisture levels and automatically water plants when the soil becomes too dry. The system uses an Arduino Nano as the main controller, interfaced with a soil moisture sensor, a DHT11 temperature and humidity sensor, and a 5V relay module to control a water pump. The system is powered by a 9V battery and includes an ESP32 microcontroller for potential wireless communication capabilities.
#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 code is responsible for reading the soil moisture level, temperature, and humidity, and controlling the water pump based on the soil moisture threshold. It also provides serial output for monitoring the sensor values.