Introduction: APIS - Automated Plant Irrigation System
The HISTORY: (a next evolution of this system is available here)
There are quite a few instructables on the topic of plant watering, so I barely invented something original here. What does make this system different is amount of programming and customization that went into it, allowing better control and integration into day-to-day life.
Here is a video of a watering run: watering run
This is how APIS came into existence:
We have two red hot chili pepper plants, which have barely "survived" several of our vacations, and almost considered family members at this point. They have been through extreme drought, and over-watering, but always recovered somehow.
The idea to build Arduino-based plant watering was almost the first idea how Arduino could be applied as a home automation project. So a simple plant watering system was built.
However, Version 1 did not have any indication of soil humidity, and there was not way to tell whether it was about to water the plants, or watering was a few days away.
Curiosity, as we all know, killed the cat, and Version 2 was built with a 4 digit 7 segment module to display current humidity at all times.
That was not enough. The next question was "when was the last time it watered the plants"? (Since we were rarely home to witness it). Version 3 used the 7 segment module to also display how long ago the last watering run occurred (as a running text string).
One night, the watering kicked off at 4 am, waking everyone up. Frustrating... Finding it too much work to turn APIS off for the night, and on for the day to prevent watering in the middle of night, a real time clock was added to put the device to sleep at night as part of Version 4.
Since real time clock requires periodic adjustments (like daylight savings time switch for instance), Version 5, includes three buttons allowing setting a variety of plant watering parameters.
It did not stop there. I noticed that humidity probe tend to erode rather quickly, quite possibly due to the fact that it was (by design) under constant voltage, and therefore there was constant electrical current between the probes (eroding anode). The cheap soil probe from China survived about a week. Even a galvanized nail was "eaten up" in a month. A stainless steel probe was holding better, but I noticed that even that was giving up. Version 6 turns the probe on for only 1 minute every hour (and on all the time during watering), thus dramatically reducing erosion (~16 minutes a day vs. 24 hours a day).
Develop plant watering system with the following capabilities:
- Measure soil humidity
- Upon reaching a predefined "low" humidity mark, turn on water pump and water the plants until a "high" humidity mark is reached
- Watering should be done in several runs, separated by periods of inactivity to allow water saturation through the soil
- The system should deactivate itself at night between "sleep" and "wake up" times
- "Wake up" time should be adjusted for weekends to a later value
- The system should keep the log of pumping runs
- The system should display current reading of soil humidity
- The system should display date/time of last pump run
- Watering parameters should be adjustable without re-programming
- Stop pumping and indicate Error condition if pump run does not lead to change in humidity (out of water, or sensor problems) preventing flooding the plant and leaking water
- The system should turn humidity probe on/off to avoid metal erosion
- The system should drain water from the tubes to prevent mold from forming inside them
The following parameters should be configurable via buttons:
- Humidity "low" mark, in %, to start pump run (default = 60%)
- Humidity "high" mark, in %, to stop pump run (default = 65%)
- Duration of a single watering run, in sec (default = 60 seconds)
- Number of retries to reach target humidity (default = 4 runs)
- Military time to deactivate for the night, hours only (default = 22 or 10 pm)
- Military time to activate in the morning, hours only (default = 07 or 7 am)
- Weekend adjustment for morning activation, delta hours (default = +2 hours)
- Current date and time
APIS writes date/time of 10 last watering runs into the EEPROM memory. The log could be displayed, showing date and time of the runs.
One of many things we learned from APIS is that you don't actually need to water plants every day, which was our routine until we saw the soil humidity readings on a 7 segment display...
Step 1: PARTS and TOOLS
You will need the following parts to build APIS:
CONTROL BOX AND TUBING:
- Arduino Uno board: on Amazon.com
- 12v Peristaltic Liquid Pump with Silicone Tubing: on Adafruit.com
- 4X Numeric LED Display Digital Tube JY-MCU Module: on Fasttech.com
- DS1307 Real Time Clock breakout board kit: on Adafruit.com (optional)
- Microtivity IM206 6x6x6mm Tact Switch: on Amazon.com
- Vero board: on Amazon.com
- L293D motor driver IC: on Fasttech.com
- 3 x 10kOhm resistors
- Arduino projects plastic case: on Amazon.com
- 12v AC/DC adaptor with a 2.1 mm power jack: on Amazon.com
- Bamboo skewers
- Tread and a bit of supercement glue
- Super Soft Latex Rubber Tubing 1/8" ID, 3/16" OD, 1/32" Wall, Semi-Clear Amber, 10 ft. Length: on McMaster.com
- Durable Nylon Tight-Seal Barbed Tube Fitting, Tee for 1/8" Tube ID, White, packs of 10: on McMaster.com
- Durable Nylon Tight-Seal Barbed Tube Fitting, Wye for 1/8" Tube ID, White, packs of 10: on McMaster.com
- As usual, wires, soldering tools, etc.
Step 2: SOIL HUMIDITY PROBE V1
Soil humidity is measured based on the resistance between two metal probes inserted into the ground (about 1 inch apart). The schematics are represented on the picture.
First probe I tried was the one you can buy from a number of internet providers (like this).
The problem with those is that the foil level is relatively thin, and erodes quickly (a matter of one or two weeks), so I quickly abandoned this pre-manufactured one for the sturdier sensor, based on galvanized nail (pls. see next step).
Step 3: SOIL HUMIDITY PROBE V2
The "next generation" probe was home made from two galvanized nails, a wooden board and a couple of wires.
Since I already had a worn-out manufactured probe, I re-used the connection piece and the electronics module from it, basically just replacing the soil component.
Galvanized nails, to my surprise, also eroded (albeit slower than thin foil), but still faster than I would like.
Another probe was designed, based on a stainless steel acne removal needles. (see next step).
Step 4: SOIL HUMIDITY PROBE V3 "Katana"
The stainless steel probe (resembling samurai sword, hence the name) is the one currently use.
I believe the quick erosion could be attributed to the fact that the probe was always under electrical voltage (24x7) regardless of how often the actual measurement took place.
To mitigate this, I changed the measurement intervals to be once in 1 hour (after all, this is NOT a real time system), and connected the probe to one of the digital pins instead of permanent 5v. Currently, the probe is being powered only ~16 minutes per day instead of 24 hours, which should increase its lifespan dramatically.
Step 5: BASIC FUNCTIONALITY
APIS is based on Arduino UNO board.
APIS measures soil humidity once an hour, and if it falls below a pre-defined threshold, turns the pump on for a pre-defined time period pre-defined number of times separated by "saturation" intervals.
Once a target humidity threshold is reached, the process goes back to once-an-hour measurement mode.
If the target humidity cannot be reached, but the lower limit was reached, that is OK as well (at least some watering took place). The reason could be unfortunate probe placement, where it is too far from the moist soil.
However, if even the lower humidity limit could not be reached, an error condition is declared. (Most probably a probe issue, or supply bucket ran out of water, etc.). Under error condition, the unit will sleep for 24 hours without doing anything, and then will try again.
Step 6: 7 SEGMENT DISPLAY
TM1650 BASED 7 SEGMENT DISPLAY:
Originally, APIS did not have any display capability. It was impossible to tell current soil humidity level without connecting via USB.
To fix that I added a 4 digit 7 segment display to the system : on Fasttech.com
I could not find a library to work with this module anywhere (neither a data sheet for it), so after a few hours of I²C port probing and experimentation, I decide to write a driver library myself.
It supports displays up to 16 digits (with 4 being a default), can display basic ASCII characters (please note not all characters could be constructed with 7 segments, so letters like W, M, etc. are not implemented)., supports decimal point display on the module, running string of characters (to display more than 4 letters), and supports 16 degrees of brightness.
The library is available on arduino.cc playground here. TM1650 driver library
Sample video is available here
A bit of 7 segment animation is implemented during a water run.
- While pump is engaged, the digital dots on the display are running in a left to right pattern, symbolizing a water run: watering animation video
- During "saturation" period, the dots are running from the center of display outward, symbolizing saturation: saturation animation video
Unnecessary, but a nice touch.
Step 7: PUMP and PUMP CONTROL
I used 12v Peristaltic Liquid Pump (available here) for watering the plants. The pump provides about 100 mL/min (which is about 1/2 of a glass - good to remember when configuring the water run time to avoid overflows, and it did happen 8-) )
PUMP CONTROL - L293D
The pump is controlled via L293D motor driver chip. Since the rotation direction is pre-set, you really only need to use the chip enable pin for control. The direction pins could be wired directly to +5v and GND permanently.
If you (like me) were not sure which direction the pump will go, you can still connect all three pins to Arduino and control direction programmatically. Less re-soldering.
Step 8: CONFIGURATION and BUTTONS
I used three buttons to configure and control APIS.
All button presses are processed based on the pin interrupts (PinChangeInt library).
- Red (rightmost) is a SELECT button. It makes APIS enter configuration mode, and also confirms the values.
- Black leftmost and middle buttons (PLUS and MINUS respectively) are used to increase/decrease configurable values (in the configuration mode), or display current date/time and last watering run information (in normal mode).
Since most of the time the display is turned off, all the buttons will first "wake" APIS up, and only then, on a second press, perform their function.
Display turns off after 30 seconds of inactivity (unless a watering run is in progress).
APIS runs through the configuration parameters upon startup for review: video
APIS has four configuration modes:
- Configure watering parameters
- Setup Real Time Clock
- "Force" watering run
- Review watering log
- Low soil humidity threshold (start watering)
- High soil humidity threshold (stop watering)
- Duration of a single watering run (in seconds)
- Number of watering runs in one batch
- Duration of the soil saturation period between runs within one batch (in minutes)
- Night mode activation time (military time, hours only)
- Night mode end time (military time, hours only)
- Weekend adjustment for night mode end time (in hours)
REAL TIME CLOCK SETUP:
- Century (i.e 20 for 2015)
- Year (i.e. 15 for 2015)
The clock is adjusted with seconds set to 00 upon confirmation of minutes.
Setting have a timeout period of 15 seconds, after which all changes are canceled.
Upon save, parameters are saved to the EEPROM memory.
FORCING A WATERING RUN:
Still not sure why I implemented it, but it is there. Once activated, APIS enters the watering mode. The watering mode, however, is still subject to thresholds. This means, that if you force watering run, but the soil humidity is above the HIGH mark, the watering run will immediately end. Basically this works only if soil humidity is between LOW and HIGH thresholds.
WATERING LOG REVIEW:
APIS keeps a log of the last 10 watering runs in the EEPROM memory, which user can review. Only Date/Time of the watering run is stored. Thresholds (at the time), and number of runs it took to reach HIGH threshold is not stored (although in the next version they might be).
Step 9: RTC: REAL TIME CLOCK
Once APIS woke me up at night, an idea to implement a "night mode" came to mind.
A night mode is when no measurements take place, display is off, and no watering runs.
On a usual business day APIS "wakes up" at 7 am (configurable), and enters night mode at 10 pm (configurable).
On a weekend APIS uses a "weekend adjustment" setting to delay a wake up (to 9 am for example, if weekend adjustment is 2 hours).
RTC BREAKOUT BOARD vs. "SOFTWARE" RTC:
I used hardware RTC (available here) to keep track of the date/time and enter/exit night modes.
It is optional to use, as sketches could be compiled to use so called "software" RTC (using millis() functionality of arduino).
The drawback of using software RTC is that you have to set the time every time APIS powers up.
I modified the standard RTC library to match API exactly, and also to work around millis rollover issue. (Please see the sketches step for downloads).
Step 10: PUTTING IT ALL TOGETHER
The entire system (except for probe) including the pump fits into a small box for Arduino Uno.
- TM1650 display uses TWI interface, so the SDA and SDC wires go to Arduino pins A4 and A5 respectively. The other two wires are +5v and GND.
- RTC board uses TWI interface, so same as above. (TM1650 and RTC use different ports, so they coexist peacefully). RTC +5v pin is connected to arduino pin 12 (powered via digital pin instead of +5v). Don't remember why I did it, you don't have to.
- L293D pins are connected as follows: enable (pin 1) to D5, and direction control pins 2 and 7 to arduino pins D6 and D7 respectively.
- BUTTONS are connected to pins D2, D8 and D9 for SELECT, PLUS and MINUS respectively. (Buttons are implemented with a pull-down 10K resistors - in the "active-high" configuration).
- PROBE module's +5v power is connected to arduino pin 10 (to enable periodic measurments), and probe is connected to analog pin A1.
Step 11: SKETCHES and More
March 2015 update:
- Added functionality to drain the tubes after watering run to prevent mold forming up
(Boy! I am happy I did not hard-wired pump rotation direction on L293D!)
- More extensive logging includes date/time of the watering run start and end, beginning and ending humidity and how many times pump was engaged during the watering run
- Error routine updated: device will hard-reset after 24 hours of entering the error condition
- Recompiled with TaskScheduler 2.1.0
- Various other bug fixes
As of November 18, 2015 APIS was upgraded with the following additional features:
- Use of DirectIO library for faster and easier pin changes
- Use of the Timezone library to correctly switch between EST and EDT
- Added button de-bouncing logic using TaskScheduler only
- Added button repeat functionality (values cycle if button is pressed and held, with speed of cycle increasing after 5 cycles)
- Recompiled with IDE 1.6.6 AVR 1.6.9 against TaskScheduler 1.8.4
- Moved to Github
APIS is based on the following libraries:
- EEPROM - part of Arduino IDE
- Wire - part of Arduino IDE
- EnableInterrupt - available on Github
- Timezone - available on Github
- DirectIO - available on Github
Modified (forked) by me:
Developed by me:
Version 1.7.1 of the current APIS sketch is available on Github
Step 12: *** WE WON !!! ***
This project won Second Prize in the Home Automation contest sponsored by Dexter Industries.
Check it out! WOO-HOO!!!