Plant133
Posted on November 18, 2023 • 11 min read • 2,134 wordsA project to design and build a simple indoor plant watering device.
Plant133 is a simple indoor plant-watering device. Its job is to keep a houseplant happy by watering it: keeping the soil moisture level between some minimum and maximum amount.
When the moisture level drops below the minimum amount, the plant is watered using an aquarium pump. Watering stops when the level exceeds the maximum threshold.
The soil moisture level is read by a simple capacitive sensor. A microprocessor reads the soil moisture sensor and signals the water pump to turn on and off.
This figure shows an example of Plant133 watering a spider plant. The system is configured to keep the moisture level between 65% and 75%, where 0% is the reading of the sensor in dry air, and 100% is the reading of the sensor when immersed in a glass of water.
When the moisture level of the soil drops below the minimum of 65%, it performs a sequence of watering cycles. When the moisture level goes above 75%, watering stops until it falls back below 65%.
Plant133 filters the moisture level signal before using it to make decisions. The raw signal from the sensor is plotted above in yellow, and the smoother filtered signal is shown in green. The watering is done in cycles. The pump runs for a few seconds, then the system waits 15 minutes to let the water spread through the soil before deciding whether to run the pump again. These cycles lead to the stair-step pattern of the moisture level in the plot above. During watering cycles, the filter used to smooth the moisture level reading is set to use a wide “kernel”, including readings over the last 5 minutes. Between watering cycles, the filter instead smooths the moisture level over tens of seconds.
The basic procedure for watering is outlined in the figure below.
Plant133 is designed to be made using inexpensive and easily obtainable hardware. This includes a pump, sensors, microcontroller, 3D-printed components, and a custom-designed circuit board. All printed components were designed using the OpenSCAD1 CAD package.
Plant133 has three sensors. Because this is a system for watering plants, the most important is the soil moisture sensor. This capacitive moisture sensor2 is supposed to last a while, not be toxic, and work acceptably for this kind of application. See the YouTube video on the subject by Andreas Spiess3. The sensor is powered by 5V, and has an analog output that can be read with the microcontroller used for this project.
For reading temperature and humidity, the system uses a SHTC34 sensor. This sensor performs well and is simple to interface with the microcontroller.
For detecting when the reservoir level is getting low, it uses a simple float sensor5.
The system uses an aquarium pump6 to move water from the reservoir to the plant. The vertical pump configuration has the intake hole on the bottom, which allows use of almost all the water in the reservoir. Water below the level of the intake cannot be used.
A printed spike inserted into the soil spreads the pumped water. The spike is printed in two pieces, then connected together with the epoxy coating which also makes the part waterproof.
The reservoir is mainly a vessel for holding water for watering the plant. It is covered by a lid which serves as a platform for holding the Ebox. The Ebox contains the electronic components. The reservoir lid also has a hinged flap which can be opened for refilling the reservoir.
The pump shouldn’t be run when the reservoir is dry, and the reservoir must be refilled when near empty, so the system needs to sense the water level. A simple float-based level sensor detects when the reservoir is near empty. The lid has a cut-out to make room for an insert which holds the float sensor, the pump, and the water tube from the pump to the soil. There is still a usable amount of water in the reservoir when the float falls to its bottom position. The microprocessor thus allows a programmable amount of total pumping time after the float indicates that the water level is low. By default, this is 10 seconds of pump operation.
The reservoir, lid, and insert are printed with PETG filament, and coated with epoxy to make them waterproof.
Inside the Ebox is the main circuit board. This uses a ESP32 microcontroller module. The ESP32 module has:
The ESP32 module is relatively inexpensive, and can be used with a large number of open source Arduino libraries for things like sensor interfaces, flash storage, web clients, and MQTT clients.
Wifi is important because it provides a way for users to set the watering parameters such as minimum and maximum soil moisture levels and the length of time the pump runs during a watering cycle. It also makes possible some methods to notify users to refill the reservoir.
The circuit board provides connections from the microprocessor to connectors for the pump, moisture sensor, float sensor, and an OLED screen. It also has a USB micro jack for power, and an edge connector which can be used to attach an external USB serial adapter for reprogramming the CPU. The board has a MOSFET and fly-back diode for powering the pump motor, and a 3.3V voltage converter for powering the microprocessor. There is also the temperature/humidity sensor mounted near the connectors where it can be exposed to the air. LED indicator lights indicate the state of the reservoir sensor, pump power, and the watering state machine.
The circuit board is housed by a 3D-printed box which contains the board, while exposing the connectors, the OLED screen, and the USB jack.
The circuit board was designed using the open source KiCAD7 package, and printed by JLCPCB8.
The software for Plant133 is written in C++. I used the Arduino framework for developing software for the ESP32 because of the ease of finding documentation, examples, and libraries online. I used the PlatformIO9 development system because I wanted a command-line interface for building code and the ability to create libraries and projects with a number of source files.
The code has a web interface for configuring a connection to a WiFi access point. When no Wifi connection is configured, it starts as an access point with ESSID “plant133” and no password. A user can connect to it, and then press the “WiFi Configure” button to tell it how to connect to an access point.
Once the device is connected to a WiFi server, it displays its IP address using its OLED screen so one can easily connect to it via a web browser on a computer that is connected to the same network.
The web interface can also be used to connect to a MQTT broker, and to set parameters for the plant watering system.
A number of configuration parameters can be specified. The minimum and maximum soil moisture levels for the plant can be set, as well as the time to run the pump for each increment of watering. A user can also calibrate the moisture sensor by setting the ADC readings when the sensor is in the open air and when submerged in a glass of water.
The web interface can also enable or disable the watering system, and enable or disable the reservoir water check. If the reservoir level is enabled, then after the water level sensor reads low-water (e.g., the float is at the bottom of its travel), the pump will run a total of a specified number of seconds, usually 10, and then watering is suspended until the water level sensor indicates that there is water in the reservoir again.
For development and monitoring, it is useful for the system to communicate its inner state to the outside world. One useful way to do this for “Internet of Things” (IOT) devices is the MQTT protocol10. The system state is sent periodically to an MQTT broker, where other systems can subscribe to updates. An example of this state information, encoded as a JSON string, is shown below.
{"reservoir": "ON",
"soil_moisture_raw": 1919,
"soil_moisture": 68.60,
"soil_moisture_filtered": 68.66,
"temperature": 27,
"humidity": 30.76,
"pump": "OFF",
"watering_state": 3,
"pump_sec_left": 10}
I run the Home Assistant11 home automation system at my house. The Plant133 system sends special MQTT messages to the broker which tells Home Assistant about the available status information and how to use it. This is an example interface displaying some of the information from the system, along with links to the web interfaces for controlling the devices on the home network.
Home Assistant sends a notification to my phone when a reservoir needs refilling.
At my house, this data also goes to an InfluxDB12 time series database for long-term storage and analysis. The data can be displayed via InfluxDB’s built in graphing systems or using a system like Grafana13. An example Grafana plot showing the status of the system watering the spider plant is shown here. A four hour time window of the system is displayed. Each pump cycle is followed by an increase in the soil moisture level. After the second watering cycle, the float sensor measuring the reservoir level starts to read low. The 10 seconds of pump time winds down to zero over the following cycles. By the time the reservoir is completely empty however, the moisture level has risen to the point where watering is finished. I refilled the reservoir around 5:45pm.
Plant133 has gone through a huge number of iterations. So far, it is working reliably in my house, but earlier versions have not worked well in other households due to reliability and lack of usability when not connected to Home Assistant. When something wasn’t working correctly, it was very difficult to detect and diagnose the problem. If mDNS was not available, it was tricky figuring out the IP address of the device to open its web interface. Improvements in the latest version, adding an OLED screen and various hardware and software updates, may take it to the point where it could work for other people. I’m planning to write follow-up posts better documenting the software, the circuit board design, the design on the 3D-printed components, and the iterative process by which I’ve been learning how to do this kind of project. (Please see the October 2024 follow-up Plant1337: “Water 4 plants”.)
OpenSCAD is an open source program which implements a programming language for building 3D models. It is a way to build models using solid modeling primitives. ↩︎
Capacitive moisture sensor ( from Amazon ↩︎
Andreas Spiess makes YouTube videos on sensors, radios, microprocessors, and electronics. ↩︎
SHTC3 is a temperature/humidity sensor, which can talk to a microprocessor using I2C. ↩︎
Aquarium pump ( from AliExpress). The vertical pump orientation works best. ↩︎
JLCPCB is the company from which I ordered circuit-boards designed using KiCAD. ↩︎
PlatformIO is an open source framework for compiling/uploading embedded software, and managing libraries used. ↩︎
The MQTT protocol ( Wikipedia) is useful for IOT (Internet of Things) applications. ↩︎
Home Assistant is open source home automation system. ↩︎