Automated Plant Watering with Arduino Nano :: Member Project

Check out this Arduino project by Programming Electronics Academy member Jeffrey Secunda.  He used an Arduino Nano and a pump to create an automated watering system for his balcony plants.

flowers and pipe with Arduino Automated Plant Watering System

The Project

I have a balcony off my bedroom that doesn’t have a source of water.  I wanted to water the plants automatically especially when I’m away for 2 weeks.

Arduino Nano, RTC, and relay on perfboard for Arduino Automated Plant Watering System

I took a 40 liter bucket and put a submersible pump at the bottom.  The pump pushes water to the plants through 8mm tubing.  The Arduino Nano gets the current time from a DS3231 Real Time Clock to turn on a relay that supplies 5 volts to the pump.

The pump operates for 60 seconds in the morning and 30 seconds in the evening. There is a button switch to trigger a manual watering. The original design had a “dry bucket” detector to prevent the pump from running when the bucket was empty.

Blue Bucket with water sensor and tubes for Arduino Automated Plant Watering System

The Biggest Challenges

  • Finding the right library for the DS3231.
  • Deciding whether to use the millis() function or the RTC for the timing interval.
  • Designing a reliable “dry bucket” sensor.Enclosure for Arduino Nano and circuit in for Arduino Automated Plant Watering System

Looking back on this project, what can you say you have learned about programming and/or electronics through the creation process?

Wow, I have learned a ton! Using libraries, program flow, testing methods, putting together the hardware.

Breadboard with wires everywhere for Arduino Automated Plant Watering System

Was the training at Programming Electronics Academy able to help you build your skill?

Absolutely! The courses are well organized, appropriate in length (especially at 1.5X) and amusing.

The Arduino Code

/* Control 5V submersible water pump for watering plants.
  DS3231 interface to set operating times and pumping interval.
  Read float switch to prevent pump from running (Hardware)when water tank is dry with Alarm (LED).
  Read manual button switch to pump maual interval using delay (no dry tank alarm)
  Future version to measure ambient temperature and add an evening watering cycle
  if temperature if over 35C at 4:00pm
*/
// Arduino Nano: ATmega328P (OldBootloader)
// ----------------------
// DS3231: SDA pin -> Arduino Analog 4 or the dedicated SDA pin
// SCL pin -> Arduino Analog 5 or the dedicated SCL pin

#include <DS3231.h> //RinkyDink

// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL);
// Init a Time-data structure
Time t;

int hoursM; // morning hours
int minutesM; // morning minutes
int hoursE; // evening hours
int minutesE; // evening minutes
int seconds;
//int DOW; // day of week

int pumpIntervalM; // morning pumping interval
int pumpIntervalE; // evening pumping interval
//int tempSensorValue; // external temp sensor value for future version

int pumpRelay = 4;
int waterAlarmPin = 3; // from float switch NO
int waterAlarmState = 0;
int waterAlarmLED = 2; // to Red LED
int pumpManualButton = 5; // from manual button
int pumpManualButtonState = 0;
//int tempSensor = A0; // external temp sensor for future version

void setup()
{
  pinMode (pumpRelay, OUTPUT);
  pinMode (waterAlarmLED, OUTPUT);
  //pinMode (tempSensor, INPUT);
  pinMode (pumpManualButton, INPUT);
  pinMode (waterAlarmPin, INPUT);

  digitalWrite (pumpRelay, HIGH); // OFF
  Serial.begin(9600); // Setup Serial connection COMMENT-OUT FOR DEPLOYMENT
  // Initialize the rtc object
  rtc.begin();

  // >>>>>>>>>>>SET TIME AND DATE<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

  // rtc.setTime (11, 00, 00); // Set the time (hh,mm,ss) (24hr format)
  // rtc.setDate (26, 07, 2019); // Set the date (dd,mm,yyyy)

  // >>>>>>>>>>>SET WATERING START TIMES (M)ORNING and (E)VENING<<<<<<<<<<<<<<<<<
  hoursM = 06; // morning ON time
  minutesM = 00; //morning ON time
  hoursE = 17; // evening ON time
  minutesE = 00; //evening ON time

  // >>>>>>>>>>>>SET PUMPING INTERVAL IN SECONDS (M)ORNING and (E)VENING<<<<<<<<<<<
  pumpIntervalM = 59; // morning pump interval in seconds
  //pumpIntervalE = 30; // evening pump interval in seconds


}

void loop()
{
  t = rtc.getTime();
  int pumpIntervalMan = (pumpIntervalE * 1000);
  digitalWrite (pumpRelay, HIGH); // OFF

  // Send date and time over serial connection
  /* Serial.print(t.date, DEC);
    Serial.print(" ");
    Serial.print(rtc.getMonthStr());
    Serial.print(" ");
    Serial.print(t.year, DEC);
    Serial.println(" ");*/

  Serial.print(t.hour, DEC);
  Serial.print(":");
  Serial.print(t.min, DEC);
  Serial.print(":");
  Serial.print(t.sec, DEC);
  Serial.println(" ");

  if (t.hour == hoursM && t.min == minutesM && waterAlarmState == LOW && t.sec <= pumpIntervalM) {
    //|| t.hour == hoursE && t.min == minutesE && waterAlarmState == LOW && t.sec <= pumpIntervalE){
    digitalWrite (pumpRelay, LOW); // ON
  } else {
    digitalWrite (pumpRelay, HIGH); //OFF
  }
  pumpManualButtonState = digitalRead(pumpManualButton);
  if (pumpManualButtonState == HIGH) {
    digitalWrite (pumpRelay, LOW); // ON
    Serial.println (pumpIntervalMan);
    delay (pumpIntervalMan); // 30 second manual pumping interval
  } else {
    //digitalWrite (pumpRelay, HIGH); //OFF
  }
  //Low water alarm deleted. Microswitch does not function well in high humidity bucket
  /*waterAlarmState = digitalRead(waterAlarmPin);
    if (waterAlarmState == HIGH) {
    digitalWrite (waterAlarmLED, HIGH);
    //Serial.println ("Water ALARM");

    } else {
    digitalWrite (waterAlarmLED, LOW);
    }*/
  // Wait one second before repeating
  delay (1000);
}

About Jeff:

Jeff is a retired biomedical engineer, who first started messing around with electronics when he was 15 by building a Tesla coil (that was 54 years ago).  In college he learned to program in assembly. He had a KIM-16, and did BASIC and a lot of database programming using RBase.

Great project Jeff!

installing Arduino libraries

Installing Arduino Libraries | Beginners Guide

IoT sewage project

Pumping poo! An IoT sewage project

ESP32 webOTA updates

How to update ESP32 firmware using web OTA [Guide + Code]

error message Brackets Thumbnail V1

expected declaration before ‘}’ token [SOLVED]

Compilation SOLVED | 1

Compilation error: expected ‘;’ before [SOLVED]

Learn how to structure your code

19 Comments

  1. Michael James on November 1, 2019 at 9:43 am

    This is awesome Jeff! Nice work! Thanks for sharing the code. I see you decided to go with the Real Time Clock.

    Was it hard to figure out the RTC library?

    • Jeff Secunda on November 2, 2019 at 1:05 pm

      Michael, Thanks for the kind words. There are a bunch of different libraries for the DS3231 with similar names but different syntax. Once I settled on the RinkyDink library the rest was easy.

  2. Les Chadwick on November 1, 2019 at 12:10 pm

    Hi James,
    Just to round off a great project, It would have been nice for Jeff to include a Fritzing curcuit diagram for those not too sure how to go about a project like this.
    Cheers

    • Michael James on November 1, 2019 at 12:12 pm

      Great point Les! I’ll see what we can come up with.

  3. Hussain Ali on November 1, 2019 at 12:14 pm

    excellent project I did it with arduino Uno but mine one had no manual option.

  4. Kevin on November 1, 2019 at 1:42 pm

    Hi Jeff,
    Thanks for the project. I am a high school teacher and just last year the kids had to build self contained growing systems. Half the class wnet hydroponics and the other half went traditional systems that required automatic watering. I have not looked at your work fully yet but plan on it as a review before I start teaching the unit in the spring.

  5. Bruce Adams on November 1, 2019 at 1:48 pm

    I had a different environment. I wanted to water plants in the backyard and not run tubing and drip tips. The system used an Arduino connected to a multi sensor board driving a simple nozzle employing two servos. An array contained the polar coordinates of each plant. A 12 volt valve controlled the flow of water. The source was regulated 35 PSI house water. No timer. The program executed when sunlight reached a certain level. The program ran again each day depending upon temperature and humidity. Since the stream of water was ballistic, a breeze would divert the stream of water. Recent power outages in California required the addition of a 12 volt battery backup and charger. The strategy was simple, cheap, and more fun than watering everything by hand.

    • Michael James on November 1, 2019 at 2:52 pm

      Very cool system Bruce!

    • Jeff Secunda on November 2, 2019 at 1:09 pm

      Bruce, This is a fantastic idea! How big an area are you covering? I originally considered using sun-rise as the start time and 12 hours later for the evening watering. I went with the RTC because I figured I could use the experience.

  6. Mauritz Botha on November 1, 2019 at 1:56 pm

    Hi Jeff,

    Nice project. I’m also busy with a similar project but a rather larger scale (16zones). Future implementation will also include the “dry bucket” option. Can you share some info and lessons learned and what you would have done differently?

    The RTC you use is a great lib. I’m also using that.

    • Jeff Secunda on November 2, 2019 at 1:20 pm

      Thanks Mauritz, I originally used a moisture sensor for the dry bucket alarm but it corroded pretty quickly. The next version was a microswitch and a float (pictured) which worked very well until the humidity in the bucket corroded the microswitch which was not spec’d for a high humidity environment. My next attempt will be either a capacitive sensor of some kind of photo electric sensor. BTW I add a couple of dropped of algacide to the bucket water to prevent algae build up which could clog the pump.

  7. Miqdad on November 4, 2019 at 2:45 pm

    This is a verry inovative idea and it is very fantastic. I have been trying to upload programs to my arduino nano but it dosen’t seems to work can you explain why?.

    • Michael James on November 6, 2019 at 8:08 am

      Are you getting any error message Miqdad?

  8. M. Rohab Saleem on November 6, 2019 at 6:36 am

    this project is cool
    i’ll try to make it by my self

  9. Amruth Kumar Sala on September 4, 2020 at 8:47 am

    This is a wonderful project. I would want to try myself for my plants at home as I am not much into any activities after retirement. It would be great if you can share the connection diagram. I will purchase the components and try to learn from the same.

  10. Nabhan on September 22, 2020 at 6:05 am

    Hi
    I’m new to all this stuff so I was wondering if you could give me the circuit diagram.
    cool project and this is exactly what I needed. 🙂

  11. David LeMaster on June 23, 2021 at 12:37 am

    Nice work, Jeff

  12. hrischo on July 20, 2021 at 6:59 pm

    Hi, thank you so much for that code, but I need help. I want to make my project today (21 July) pump start, tommorow (22 July) pump not start. Maybe that is something day interval but I don’t know how to do it. I am new in Arduino and I need help. Thanks in advance.

Leave a Comment