The Smart Irrigation System is designed to automate the watering process based on soil moisture levels and rain detection. It utilizes an Arduino UNO as the central processing unit, interfacing with a rain sensor, a soil moisture sensor, a DHT11 temperature and humidity sensor, a 16x2 LCD for display, a potentiometer for LCD contrast adjustment, a relay module to control a water pump, and a 9V battery as the power source.
// Include the library code:
#include <LiquidCrystal.h>
#include "DHT.h"
// Initialize the LCD and set the pins
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// Define sensor and relay pins
const int relay_Pin = 9;
const int DHT11_Sensor = 8;
const int moisture_sensor = A0;
const int rain_Sensor = A1;
// Define DHT sensor type
#define DHTTYPE DHT11
DHT dht(DHT11_Sensor, DHTTYPE);
// Variables to store sensor values
int moisture_sensor_value;
int rain_Sensor_value;
float humidity_value, temperature_value;
void setup() {
Serial.begin(9600);
pinMode(relay_Pin, OUTPUT);
lcd.begin(16, 2);
lcd.print("Smart Irrigation");
lcd.setCursor(0, 1);
lcd.print("SYSTEM");
digitalWrite(relay_Pin, LOW);
dht.begin();
delay(2000);
}
void loop() {
readDHT11_Sensor();
moisture_level_detected();
water_motor_start();
}
void readDHT11_Sensor() {
humidity_value = dht.readHumidity();
temperature_value = dht.readTemperature();
if (isnan(humidity_value) || isnan(temperature_value)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.print(humidity_value);
Serial.println("%");
lcd.clear();
lcd.print("Humidity %: ");
lcd.setCursor(0, 1);
lcd.print(humidity_value);
delay(1000);
Serial.print("Temperature: ");
Serial.print(temperature_value);
Serial.println("C");
lcd.clear();
lcd.print("Temperature C ");
lcd.setCursor(0, 1);
lcd.print(temperature_value);
delay(1000);
}
void moisture_level_detected() {
moisture_sensor_value = analogRead(moisture_sensor);
Serial.print("Moisture Level: ");
Serial.println(moisture_sensor_value);
lcd.clear();
lcd.print("Moisture Level:");
lcd.setCursor(0, 1);
lcd.print(moisture_sensor_value);
delay(2000);
}
void water_motor_start() {
rain_Sensor_value = analogRead(rain_Sensor);
Serial.print("Rain sensor value: ");
Serial.println(rain_Sensor_value);
delay(1000);
if (rain_Sensor_value > 700) {
if (moisture_sensor_value > 700) {
digitalWrite(relay_Pin, HIGH);
delay(2000);
} else {
digitalWrite(relay_Pin, LOW);
delay(2000);
}
} else {
digitalWrite(relay_Pin, LOW);
delay(2000);
}
}
This code controls the Smart Irrigation System by reading sensor data, displaying it on the LCD, and controlling the water pump via the relay module based on the moisture and rain sensor readings.