Adam Redfern
Published © CC BY

Automatic Plant Hydrator

Fed up of forgetting to water your plants every day? Build this project and never worry about doing it again.

BeginnerFull instructions provided1 hour1,182
Automatic Plant Hydrator

Things used in this project

Hardware components

arduino UNO
×1
LCD
×1
potentiometer
×3
SparkFun Soil Moisture Sensor (with Screw Terminals)
SparkFun Soil Moisture Sensor (with Screw Terminals)
×1
pump
×1
PCBWay Custom PCB
PCBWay Custom PCB
×1

Story

Read more

Code

Untitled file

Arduino
// Adam Redfern    Ohmega elctronics    09/01/2019


#include <LiquidCrystal.h>  // initialize the library by associating any needed LCD interface pin

const int sensor = A0;  // connect the input from the moisture sensor.
const int pump_timing = A1;  // connect the potentiometer to set the pump timings.
const int Moisture_trigger = A2;  // connect the potentiometer to set the moisture trigger.
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;  //set the pins for the LCD
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);   //set the pins for the LCD
int pump = 7 ; // connect the positive of the pump to this pin

void setup(){  
  pinMode(pump, OUTPUT);  //set the pump as an output 
  lcd.begin(16, 2);  //set up the LCD's number of columns and rows
}

void loop() {

int pump_value = analogRead(pump_timing); // Read the value from the potentiometer 

(if (pump_value 0 && pump_value < 99)
{
if (sensor > Moisture_trigger)
  digitalWrite(pump, HIGH);  //turn the pump on
  delay(2000);  //how long to keep the pump on for 
  digitalWrite(pump, LOW);  //turn the pump on
}
else if (pump_value >= 100 && pump_value < 199)
{
if (sensor > Moisture_trigger)
  digitalWrite(pump, HIGH);  //turn the pump on
  delay(4000);  //how long to keep the pump on for 
  digitalWrite(pump, LOW);  //turn the pump on
}
else if (pump_value >= 200 && pump_value < 299)
{
if (sensor > Moisture_trigger)
  digitalWrite(pump, HIGH);  //turn the pump on
  delay(6000);  //how long to keep the pump on for 
  digitalWrite(pump, LOW);  //turn the pump on
}
else if (pump_value >= 300 && pump_value < 399)
{
if (sensor > Moisture_trigger)
  digitalWrite(pump, HIGH);  //turn the pump on
  delay(8000);  //how long to keep the pump on for 
  digitalWrite(pump, LOW);  //turn the pump on
}
else if (pump_value >= 400 && pump_value < 499)
{
if (sensor > Moisture_trigger)
  digitalWrite(pump, HIGH);  //turn the pump on
  delay(10000);  //how long to keep the pump on for 
  digitalWrite(pump, LOW);  //turn the pump on
}
else if (pump_value >= 500 && pump_value < 599)
{
if (sensor > Moisture_trigger)
  digitalWrite(pump, HIGH);  //turn the pump on
  delay(12000);  //how long to keep the pump on for 
  digitalWrite(pump, LOW);  //turn the pump on
}
else if (pump_value >= 600 && pump_value < 699)
{
if (sensor > Moisture_trigger)
  digitalWrite(pump, HIGH);  //turn the pump on
  delay(14000);  //how long to keep the pump on for 
  digitalWrite(pump, LOW);  //turn the pump on
}
else if (pump_value >= 700 && pump_value < 799)
{
if (sensor > Moisture_trigger)
  digitalWrite(pump, HIGH);  //turn the pump on
  delay(16000);  //how long to keep the pump on for 
  digitalWrite(pump, LOW);  //turn the pump on
}
else if (pump_value >= 800 && pump_value < 899)
{
if (sensor > Moisture_trigger)
  digitalWrite(pump, HIGH);  //turn the pump on
  delay(18000);  //how long to keep the pump on for 
  digitalWrite(pump, LOW);  //turn the pump on
}
else if (pump_value >= 900 && pump_value < 1023)
{
if (sensor > Moisture_trigger)
  digitalWrite(pump, HIGH);  //turn the pump on
  delay(20000);  //how long to keep the pump on for 
  digitalWrite(pump, LOW);  //turn the pump on
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//This section selects what moisture percentage will be displayed on the LCD dependent on the value of the potentiometer// 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Moisture_trigger = analogRead(Moisture_trigger); // Read the value from the potentiometer 

(if (Moisture_trigger 0 && Moisture_trigger < 99)
{
lcd.setCursor(0, 1);  //display on bottom line of LCD
lcd.print("10%");
}
else if (Moisture_trigger >= 100 && Moisture_trigger < 199)
{
lcd.setCursor(0, 1);  //display on bottom line of LCD
lcd.print("20%");
}
else if (Moisture_trigger >= 200 && Moisture_trigger < 299)
{
lcd.setCursor(0, 1);  //display on bottom line of LCD
lcd.print("30%");
}
else if (Moisture_trigger >= 300 && Moisture_trigger < 399)
{
lcd.setCursor(0, 1);  //display on bottom line of LCD
lcd.print("40%");
}
else if (Moisture_trigger >= 400 && Moisture_trigger < 499)
{
lcd.setCursor(0, 1);  //display on bottom line of LCD
lcd.print("50%");
}
else if (Moisture_trigger >= 500 && Moisture_trigger < 599)
{
lcd.setCursor(0, 1);  //display on bottom line of LCD
lcd.print("60%");
}
else if (Moisture_trigger >= 600 && Moisture_trigger < 699)
{
lcd.setCursor(0, 1);  //display on bottom line of LCD
lcd.print("70%");
}
else if (Moisture_trigger >= 700 && Moisture_trigger < 799)
{
lcd.setCursor(0, 1);  //display on bottom line of LCD
lcd.print("80%");on
}
else if (Moisture_trigger >= 800 && Moisture_trigger < 899)
{
lcd.setCursor(0, 1);  //display on bottom line of LCD
lcd.print("90%");
}
else if (Moisture_trigger >= 900 && Moisture_trigger < 1023)
{
lcd.setCursor(0, 1);  //display on bottom line of LCD
lcd.print("100%");
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//This section selects what pump timing will be displayed on the LCD dependent on the value of the potentiometer//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

{if (pump_value 0 && pump_value < 99)
{
lcd.setCursor(0, 0);  //display on top line of LCD
lcd.print("2 seconds");  //display the value 
}
else if (pump_value >= 100 && pump_value < 199)
{
lcd.setCursor(0, 0);  //display on top line of LCD
lcd.print("4 seconds");  //display the value 
}
else if (pump_value >= 200 && pump_value < 299)
{
lcd.setCursor(0, 0);  //display on top line of LCD
lcd.print("6 seconds");  //display the value 
}
else if (pump_value >= 300 && pump_value < 399)
{
lcd.setCursor(0, 0);  //display on top line of LCD
lcd.print("8 seconds");  //display the value 
}
else if (pump_value >= 400 && pump_value < 499)
{
lcd.setCursor(0, 0);  //display on top line of LCD
lcd.print("10 seconds");  //display the value 
}
else if (pump_value >= 500 && pump_value < 599)
{
lcd.setCursor(0, 0);  //display on top line of LCD
lcd.print("12 seconds");  //display the value 
}
else if (pump_value >= 600 && pump_value < 699)
{
lcd.setCursor(0, 0);  //display on top line of LCD
lcd.print("14 seconds");  //display the value 
}
else if (pump_value >= 700 && pump_value < 799)
{
lcd.setCursor(0, 0);  //display on top line of LCD
lcd.print("16 seconds");  //display the value 
}
else if (pump_value >= 800 && pump_value < 899)
{
lcd.setCursor(0, 0);  //display on top line of LCD
lcd.print("18 seconds");  //display the value 
}
else if (pump_value >= 900 && pump_value < 1023)
{
lcd.setCursor(0, 0);  //display on top line of LCD
lcd.print("20 seconds");  //display the value 
}
  
}

Credits

Adam Redfern
45 projects • 30 followers
Electronics enthusiast/hobbyist. Twitter: @AdamRedfern Website: http://ohmega-electronics.co.uk/

Comments