//Title : Automated plant watering system.
//Author : U.Laxmi Bhargavi
//This project aims to make the lifes of farmers or people who love
//growing plants easier.
//The potentiometer here mimics the behavior of a soil moisture sensor.
//Relay serves as an electronic switch that controls the water pump.
//The LED represents the pump beign ONN/OFF.
const int moistpin=A0;
const int relaypin=8;
const int threshold=500;//acts as the threshold that says if the plant needs watering or not.
void setup() {
pinMode(relaypin, OUTPUT);
digitalWrite(relaypin, LOW);//initially setting the pump/relay to OFF.
Serial.begin(9600);
}
void loop() {
int moistlevel = analogRead(moistpin);// Checking the moisture level.
Serial.print("The moisture level is : ");
Serial.println(moistlevel);
if(moistlevel<threshold){
Serial.println("The soil is not moist enough...Needs watering!!!");
Serial.println("The pump is beign turned on!!!");
digitalWrite(relaypin, HIGH);//turns ONN the pump.
}else{
Serial.println("The soil is moist...");
Serial.println("The pump is beign turned off!!!");
digitalWrite(relaypin, LOW);//turns OFF the pump.
}
delay(5000);// Reads the moisture level every 5 seconds.
}