Project Summary

This is one of my more recent, easy projects. I've seen these done a few times before and I think they're neat and have a good deal of utility, especially because we already have a bunch of plants.

I wanted to do something with relays, and also work with sensors again since its been a while, so this was a nice return to form.

Having started this after spending my winter break making furniture, I was also excited to put everything in a pretty wooden box.

Electronics Box

I decided to conceal everything in a nice decorative wooden box so it could kept in plain site and be easily serviceable.

Instead of making the box myself I decided it was smarter to just buy one at a crafts store and finish it myself.

To accommodate and mount the electronics I devised a suspended rail system made entirely of popsicle sticks. I glued two sticks together and cut slots with a saw for the supports, then glued them to the sides of the box. Then I cut down some other sticks and zip tied on the relays and sensor boards.

Finally I stained everything, drilled a slot for the wires, and gave it a coat of polyacrylic.

Electronics & Wiring

I never got around to making a wiring diagram for this project because I was a little to excited to get it done.

Everything is driven by an Arduino Nano, or at least it was supposed to be but I bought cheap Nano clones with power regulation issues, so I eventually had to put my genuine Arduino Mega inside. I will be replacing the Mega with a Teensy soon. The controller is powered by a 9V adapter.

There are four relays, one for each moisture sensor and one for each pump. The idea here is that the sensors are only active when they're sampling every four hours, which cuts down on corrosion. The relays attached to the pumps are just acting as super cheap motor controllers. Everything is powered by 5V.

The sensors return analog data into the analog pins of the Arduino, and the relays tap into the digital pins so they know when to open and close. I have the buttons wired up to the digital pins as well.

All the wires are meant to pass underneath the rails, and any wires that have to leave the box do so through the slotted hole. I wrapped all the external wires up with the plastic wire wrap stuff that you get with 3D printers.

System Summary

As you can see, the system is fairly straight forward and operates primarily by checking two or three things.

First the system uses a given moisture sensor to sample the moisture in a given plant.

Then, if the moisture is below a certain calibrated threshold, then a status updates on that plant that sets a wait period.

Then is waits four hours through one second intervals before checking the moisture again. Each four hour period ends one loop, and at the beginning of the next loop the wait periods are updated to reflect time passed. Between each one second interval the controller checks to see if the plant specific bypass button was pressed to manually water that specific plant.

This all repeats until the moisture level is sampled again when the wait period has run out. Then, after sampling the soil a final time, the pump turns on for a few seconds to water the plant.

Algorithm Summary

On the right is a screenshot of the void loop code for the first plant. This captures pretty much all the behavior mentioned in the system summary section.

I functionalized the moisture sampling as well as the watering. I pass the appropriate pin numbers to turn on and off the relays that power the sensors and relays to the functions.

The moisture sampling function takes a certain number of values, with a slight delay for stability, and returns the averaged value, that is then used to decide on if the plant should enter the waiting period for watering.

The pumping function just turns the pump on and off for a given plant to water it.

You can see the wait period is implemented as a count that updates with every cycle. So every increment of the count is four hours. I also implemented a count called "Water Token" just to differentiate between situations where the wait period is at zero because the plant has recently been watered and situations where the wait period is at zero because the wait period has just ended and the plant needs to be watered.

Calibration & Tuning

As far as calibration goes for this system I didn't do anything fancy like I did for the sorting machine project.

I never converted the voltage readings to percentage moisture or anything like that with a calibration curve. The main reason for this was that even though I can give steps at 100% moisture (water) and 0% moisture (box of desiccant I guess?) the readings change with the density and conductivity of the soil itself. So from one plant to another, any calibration would have been meaningless.

So what I did instead was just took measurements of wet and dry soil for the same plant, and picked a sensor value somewhere on the dry end of that scale. This has worked pretty well so far and I've not had to make any changes since setting up the system.

Now what required the most tuning was surprisingly the pumps. I didn't even think to implement a valve into this system when I started, and I planned to use one big water reservoir either above or below the plants. Well the first problem was siphoning. If I turned the pump on with the reservoir above the plant on the top shelf, then the water would continue to drain even after the pump turned off because it has too much potential energy. So then I said "Okay, easy fix!" and I moved the reservoir below the plants. That made sense in my head but it turned out that my little 5V pumps couldn't actually pump water straight up more than a foot or so. So now I'm using an interim solution of having different reservoirs for each plant at the same height as the plant. Not a nightmare by any stretch of the imagination, but it was a hurdle that I wasn't expecting.

Results

Overall this system has been working great. It's been going strong for about a week or so and the only maintenance I should expect is refilling the reservoirs and occasionally maybe once every few months replacing the moisture sensors as they corrode. It's pretty cool to hear the relays clicking on and off occasionally when I'm in m room, and nothing in the system is too ugly or too big to be concealed either.

Overall this was a fun project and I recommend it to anyone. Going forward I plan on expanding the system to accommodate more plants, and obviously swapping a Teensy in as the controller. I think I would also enjoy experimenting with different electronics mounting strategies using my 3D printer to prototype different things. Oh, I also really want to put an SD card module on here so I can take some data off the sensors. I think it would be cool to have a weeks worth of moisture data printed out somewhere.