#include <Wire.h>
#include <LiquidCrystal.h>
#include <Servo.h>
#include <DHT.h>
Servo myServo; // Create a servo object
//LCD Connections
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
//Soil moisture sensor analog input
const int analogPin = A0; // Analog input pin
//Code for the LED
const int ledPin1 = 3; // Pin connected to the first LED
const int ledPin2 = 6;
//code for DHTT22
#define DHTPIN 13 // Pin connected to the DHT22 sensor
#define DHTTYPE DHT22 // DHT sensor type
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
//DHTT22
dht.begin(); // Initialize the DHT sensor
//LED set to output
pinMode(ledPin1, OUTPUT); // Set the LED pins as output
pinMode(ledPin2, OUTPUT);
//Servo set to pin 4
myServo.attach(4);
// Customized chip soil moisture sensor set to input mode
pinMode(analogPin, INPUT); // Set the analog pin A0 as input
//LCD Display startup
lcd.begin(16, 2);
lcd.print("Smart water!");
delay(2000);
}
void loop() {
//Setting analog pin to sensorValue variable
int sensorValue =analogRead(analogPin);
// Customize your chip's behavior based on the sensor value
if (sensorValue > 135) {
digitalWrite(ledPin1, LOW); // Turn off the RED LED
digitalWrite(ledPin2, HIGH); //Turn on the Green LED
//LCD Display when the soil is wet
lcd.clear();
lcd.print("Soil: ");
lcd.print("WET");
// Move the servo to the 90-degree position which is opening a tap to start watering
myServo.write(0);
} else {
digitalWrite(ledPin1, HIGH); // Turn ON the red LED
digitalWrite(ledPin2, LOW); //Turn off the green LED
// LCD Display when the soil is dry
lcd.clear();
lcd.print("Soil: ");
lcd.print("DRY");
//Move the servo to the 0-degree position. Which is closing the tap to stop watering
myServo.write(0);
}
delay(500);
// Display of exterior condition that affect a plant
float temperature = dht.readTemperature(); // Read temperature in Celsius
float humidity = dht.readHumidity(); // Read humidity
//Displaying temperature
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C");
//Displaying Humidity
Serial.print(" Humidity: ");
Serial.print(humidity);
Serial.println(" %");
}