water testing

It’s not often that one gets to program with the physical world, but I must say, this project sparked a newfound appreciation for programming. For a back story, my brother has been playing around with Arduino controllers for a while now. After several projects that blew my mind, I decided to piggyback on his experience to create a project of my own; a self-sustaining watering system for plants. During the summer months in Oregon, I’ve started to enjoy growing my plants, specifically jade. The smell of a fresh jade plant in the early spring morning is something else. Creating a system that could sustainably water this plant seemed interesting, plus, there are a ton of examples online I could reference.

Research:

There were a couple of different ways to build something like this and we discussed most of them.

I knew that I wanted to run the system of a pump to be able to scale out to a full planter in the future. You could go with a solenoid activated water value to plumb into a house’s existing water fittings as seen in option 3 which, arguably could be where I take this into the future, but for now the pump will do just fine. With a pump-based system, we can actively water the plant on as-needed bases, just by pumping water into the pot.

Requirements:

  1. Arduino Uno: The flavor of microcontroller you decide to go with is ultimately a personal preference. My brother had an extra Uno laying around, so I used that.

  2. Seesaw Capacitive Soil Sensor: To know when the soil requires water, we need a sensor to quantify the moisture level of the soil. There are two types of soil sensors available 1) a capacitive moisture sensor that senses the soil’s ability to store an electrical charge and a 2) resistive moisture sensor which sends a current through the soil to view the level of resistance. After researching several projects, I’ve read that the resistive sensors are prone to corrosion, so I decided to utilize a capacitive sensor that utilizes the I2C protocol. I2C, a variant of data transfer protocol for controllers, is commonly used for microcontroller sensors and communicating with other objects. There is more info here if you would like to build this off an analog system.

  3. A 12v pump: To eventually pump water to the plant, we need some kind of pump. I decided to go with a Bayite 12v pump to allow for the capacity to add more sensors for more pots or an entire garden watering system. Alternatively, you could likely find a small pump that runs off the micro controller’s power, such as any dosing pump, but we decided to go with a more powerful option.

  4. A 5v Relay: By going with a larger pump, power systems come into play. Our pump is running off 5-volt power, whereas the watering pump has auxiliary power at 12-volts. To switch power to the pump on and off, we need a relay to turn on and off based on the moisture reading from the controller.

Code:

The structure of this code is fairly simple. The top is set up to define all variables. Our moisture level is defined based on the range provided by the sensor docs. The setup() block is meant to initialize our serial output and then confirm if the sensor is providing input. The main loop() block should be considered analogous to a main() function in C++ programming.

{{< highlight cpp >}} #include “Adafruit_seesaw.h”

Adafruit_seesaw ss;

// Defining constant variables const int pumpPin = 3; const int ledPin = 12; const int moisture_level = 750;

// Defining other variables int pumpPower = LOW; // Preset pump power to off int ledPower = LOW; // Preset LED power to off long watering_time = 5000; // amount of time pump will water (1 sec = 1000 ms)

void setup() {

Serial.begin(115200);

Serial.println(”################### Soil Sensor v.2.0 ###################”);

// Detect to see if soil sensor is available if (!ss.begin(0x36)) { Serial.println(“ERROR! seesaw not found”); while(1); } else { Serial.print(“seesaw started! version: ”); Serial.println(ss.getVersion(), HEX); }

// Initializing Output Pins pinMode(pumpPin, OUTPUT); pinMode(ledPin, OUTPUT);

}

void loop() {

// Read the capacitive soil sensor to get moisture reading (200: very dry | 2000: very wet) float tempC = ss.getTemp(); uint16_t capread = ss.touchRead(0);

// Printing out the current moisture Serial.print(“Temperature: ”); Serial.print(tempC); Serial.println(“*C”); Serial.print(“Capacitive: ”); Serial.println(capread);

// Conditional block to water the plant if the moisture level is too low if(capread <= moisture_level){ Serial.println(“Moisture below threshold”);

  digitalWrite(pumpPin, HIGH);
  digitalWrite(ledPin, LOW);

  delay(5000);

  digitalWrite(pumpPin, LOW);
  digitalWrite(ledPin, HIGH);

 } else {
  digitalWrite(pumpPin, LOW);
  digitalWrite(ledPin, HIGH);
 }

delay(300000); // 5 Mins = 300000 } {{< / highlight >}}

Pictures:

Pump in box

Bayite Pump

Board Detail

Mock Build

Soil testing

For an update, I will provide pictures in the spring once the jade plant begins to bloom. In terms of improvements towards this project, I would like to explore the use of a logging system. An SD card logging system appears to be possible, or Adafruit just released a graphical UI called Adafruit IO. AWS also provides an IoT system that allows for controller integrations, but again we would need to incorporate some GSM, Bluetooth, or WiFi shield for this system.