# Automatic plant watering and illumination (smallest version)

26 Jul 2020 - tsp
Last update 22 Nov 2020

Disclaimer: As usual - no guarantees are made that this stuff works, is safe or satisfies any regulations (even if it fulfills them in my area). If you don’t know how to wire devices for the electric power grid don’t do it - electicity might not be complicated but there are some basic things to know (and also some regulations) - and in case your house burns down insurances might not pay anything in case you’ve been not qualified or allowed to perform such work. The same goes for piping: Even small leakage might lead to huge damage on buildings - bringing the same liability problems if you don’t know local regulations or are not allowed to perform such work.

## Introduction

So after a few years of growing basil, capsicum and chili pepper indoor one gets some problems: One gets tired of everyday watering (sometimes necessary) because that takes at least 30 minutes a day, tired of dead plants after being on vacation and of course slow growing plants during winter. To counter these problems this little plant watering and illuminating project has emerged - in fact this is a so short project that writing this blog post took longer than the realization. Basically it tries to address these problems:

• Providing a basic structure to rest plants and tooling on.
• Illumination should be about 16 to 17 hours a day and provide enough energy density for the plants to grow.
• Irrigation should provide enough water for plants to grow optimally and should carry necessary nutrients (fertilizer).
• In the best case irrigation should be controllable in a fine grained fashion using valves because I’ve got some plants with less water demand than others.
• Since irrigation happens indoors overflow should be handled and water that doesn’t get absorbed by the earth should be cycled back into the water tank to minimize water loss.
• Because of the position indoors without (currently) available water and wastewater connection a local water tank is required that can be used as water source for at least a few weeks operation duration.
• It should require basically no to rare interaction.
• Monitoring will be added (since any automation without automated monitoring is worthless in my opinion).
• It should be cheap and use as much standardized components as possible.
• Extending should be easy.

## Structure

The basic structure has been built from cheap construction wood (note that this is wood that’s not been planed or shaped but got directly from the band-saw cutting at the lumber mill). This is a somewhat simple construction using three planks in parallel - two to reach the required depth and one to reinforce against bending. Pillars are cut at every floor so that planks can directly lay on top of them to avoid any unnecessary torque carrying connections. Screws are only used to keep the planks and pillars in place, not to carry any load or torque - like with every timber frame. Since the structure is that narrow and high it’s attached to the wall using four screws at the top end.

Yes, that’s not the most good looking structure but it’s rather cheap and since it was assumed to possibly get wet the cheapest solution has been used.

## Illumination

There are different solutions for plant illumination available:

• Using sunlight. This is the most efficient solution that should really be used if available. UV and IR blocking windows are a problem though and since this plant structure is used indoor behind highly efficient windows - and direct sunlight is also not reaching this area any time a day - artificial lighting is required. If it’s somehow possible to use sunlight it’s way better than any artificial lighting solution - in this case artificial lighting should only be used in conjunction during low light seasons.
• Using sodium vapor or mercury arc lamps. These are the most efficient lamps when growing plants and are mainly used in professional greenhouses as well as by people growing weed illegally because it maximizes yield. Since this is not a requirement for the basil / chili pepper / capsicum growing done here these rather expensive lamps are not an option. If they are used it should also be accounted for optimum usage of the illuminated area - i.e. maybe not a that narrow structure as I’ve built.
• Cheap fluorescent tubes. They are rather cheap, long living, standardized and simple to handle. Ironically they provide nearly the same quality of spectrum for plants as sodium vapor and mercury arc lamps.
• Modern LED lamps. I’ve tried these and to get necessary power density a massive investment is required. They’re the way to go for professional large scale operations since their power requirement is significantly lower than for fluorescent tubes and one is capable of controlling red vs blue wavelengths that control growth speed of leafs and plant development. Also note that it’s even more important to have lights at adjustable heights above the plants to move them as close as possible when using LEDs - even though that would be a good idea for any lighting since energy density of course is reduced according to the inverse square law $r^{-2}$. So if you reduce the distance to the plants to a half you get four times the energy density, when reducing to $\frac{1}{3}$ you get 9 times the energy density per area and so forth.

Since LEDs are rather expensive the decision was to use a combination of fluorescent tubes and LED stripes. The LED stripes alone did not provide enough energy density but are used for a longer duration in addition to fluorescent tubes. Each of the used column already contains an electronic ballast to ignite the lamps and limit current so they can be directly attached to mains voltage.

Illumination can be switched via:

• An semiconductor relays (i.e. an opto coupled thyristor) - for example an SSR-25 AA (note: Amazon affiliate link, this pages author profits from qualified purchases). This semiconductor relay can be controlled using any 5V tolerant microcontroller like an ESP32 providing ethernet connectivity, an Arduino or using an additional external MosFET like an IRF540N using any 3.3V microcontroller or microcomputer such as an RaspberryPi.
• If one’s lying around and one really requires control only using WiFi one could use an Sonoff Basic (note: Amazon affiliate link, this pages author profits from qualified purchases). These can be flashed easily with custom firmware and provide connectivity using HTTP, MQTT or some custom protocol. Since I’ve had some of them lying around I used this approach even if I’d really prefer wired solutions based on the ESP32 and Ethernet or the RaspberryPi and Ethernet over any wireless solution.

The LED stripes are powered by a 200W 12V power supply that’s also switched on the primary side using the same technique as the fluorescent lamps.

The 5V power supply seen on the right was not connected during the take of the photograph - it is used to power logic components and sensors as well as some 5V fans.

Note during wiring to use the correct cable cross sections and follow regulations for phase shifting when connecting fluorescent lamps in series - you might require power factor correction in case of too many lamps or you’d have to wire them in parallel rather than in series.

## Irrigation

Irrigation is rather simple and done using a high pressure membrane pump since the water has to be pumped at least two and a half meter above the ground - and there still has to be enough pressure to be sprayed at the spray nozzles.

The pump itself is using a main distribution hose with 8mm inner diameter and 10mm outer diameter, the branches in each level use hoses with 8mm outer diameter and 6mm inner diameter that perfectly match the spray nozzles. All components are standardized and will be easily replaceable even a few years from now. The membrane pump has two ingress filters, the coarse filter being submerged into the tank directly attached to a copper tube to stay fixed in place and a second filter included directly inside the pump.

On the egress side the 8mm hose is broken up with T shaped segments that allow attachments of 6mm hoses that distribute water to the spray nozzles.

The pump has to be noise damped though since membrane pumps are pretty loud. To accomplish this Neoprene anti vibration pads (note: Amazon affiliate link, this pages author profits from purchases) have been added in between the pump and the frame to which it has been screwed. Additionally acoustic foam has been used to enclose the pump - note that this has to be taken into consideration when planning the system since the foam of course limits cooling of the pumps. Since operation time of the pumps is below two minutes each with multiple hours in between each watering session this wasn’t a limit.

The pump itself is powered again by a 12V power supply. This supply can be switched on the primary side in case the pump is the only load that required 12V (in case no instrumentation and other pumping equipment for fertilization or solenoid valves for filling are required). Since the solenoid valves are also running of 12V and are only required during an active pump primary side switching is totally feasible in case no fertilizer mixing or aeration is required or in case they’re powered of different voltage (5V pumps) or power supplies. This of course decreases PSU lifetime but significantly lowers power consumption. In my case the first system has been switched with a Sonoff Basic (note: Amazon affiliate link, this pages author profits from qualified purchases) again since I’ve had a bunch of them lying around. The firmware used in this case offers the option to enable or disable using MQTT and an REST API as well as the local button - and allows the submissions of operation period using MQTT. The operation period excluding the constant startup time of the pump is directly proportional to the amount of water - so it’s possible to regulate the water amount in liters. This setting is available inside a Node-Red dashboard. To circumvent outages due to a failing node-red instances the Sonoff switch is programmed to perform periodic irrigation in case of missing remote commands. Running duration is also limited to avoid flooding by malformed command messages or malicious users.

Additionally a water volume sensor has been added for error detection. In case the counted volume doesn’t match the expected volume (at least doesn’t match it inside some given error margin) the whole system will be disabled until manually controlled maintenance.

## Water tank

The water tank used can take up to 25 liters a day (and thus can weight in theory up to 25kg). To better suite the frame it has been put horizontally and the wastewater pipe used for circulation has been attached through a hole in it’s cap. Because of this about 1/5 of the tank volume cannot be flooded without risking overflow (even though all screw couplings and pipe feeds seem to be watertight I wont risk this since there are no proper seals in place and the system runs unattended most of the time).

The feedwater pipe is attached via a copper tube - the filter is applied to the bottom. The pipe has been used to ensure the filter and ingress tube stays at the lowest possible position.

The level inside the water tank is monitored using a simple ultrasonic distance sensor. This has been chosen over a conductive probe since conductive probes as well as capacity probes only measure electric conductivity or polarizability, not water level. As plants consume nutrients or as they are washed out of the earth (depending on the state of the dirt used) the density of dissolved solids varies and as such the conductivity and polarizability. So EC can be used as a measure of available nutrients as long as one knows the water level inside the tank. Data is read out using an ESP32 development board, although this will soon be replaced using a custom ESP32 board that includes an Ethernet PHY to allow ethernet attachment instead of WiFi connectivity.

## Water circulation

Since the system operates indoors overflow handling was important. To allow excess water to overflow the plant pots standardized 32mm wastewater pipe has been used. These pipes are fitted with proper seals to avoid any leakage, are pretty easy to assemble and are cost efficient. They are connecting using T shaped elements for every story. The end of the pipe network passes through the cap of the water tank and reaches into the water tank. Don’t try to substitute these pipes with 6mm or 8mm inner diameter PVC or silicone hoses - the adhesion of water will prevent draining in case you’ve got longer horizontal or near horizontal sections. Using such hoses might only work in case they go strictly vertical - but in case they move and are bent at an narrow angle they’ll get blocked and the area would be flooded. Going with standard wastewater pipes is really easy and they don’t look that bad anyways - way better than a bunch of hoses hanging around.

For every flowerpot there is an drip mat below that got drilled through. Then there is 8mm PVC hose attached to the holes and sealed with polysiloxane (silicone). To have some kind of protection against clogging of the drains by falling leafs there are at least two drains per drip mat.

Of course water circulation also means that wastewater that might carry disease or fungi would distribute these pathogens to all plants inside the system. One might of course instead decide to drain the water into some external wastewater treatment or into the garden. This of course also heavily depends on the availability of wastewater sinks as well as the general desire to limit water loss.

As it turns out having some kind of overflow drainage is really required for an indoor watering system to prevent overflow into the room as well as not having to radically tune the volume - and possibly delivering not enough water volume

## Fertilization

Will be described soon

## Instrumentation (Sensors) and monitoring

Will be described soon

### Water level monitoring (Ultrasonic)

The water level inside the water tank is monitored using a simple ultrasonic distance sensor connected to an ESP8266/ESP32 (I’ve tried both - the main difference beeing Ethernet support on the ESP32 which i totally prefer over WiFi connectivity of the ESP8266). Since I didn’t want to do any major redesign I simply used HC-SR04 breakout boards (note: Amazon affilate link). Using these sensors I’m doing one measurement every 125 milliseconds (i.e. 4 times a second). These measurements are then published as raw data and as calculated water height using MQTT. The payload is encoded as JSON object as usual.

As one can see the raw values of the ultrasonic sensor are somewhat noise with large outliers occuring. I’ve simply solved this by applying a moving median filter to the raw calculated height as well as clamping the measured height to the valid output range. Using the moving median filter of course introduces some delay - but since the whole system is sluggish by nature - and because of the used pumps and pipe diameters - this is of course not a problem.

### Data collected and watering optimization using a closed control loop

Will be described soon