Networked Plant Auto-Waterer With Water-Source Emptiness Detection Using Arduino WiFi Rev4
by dylanclements in Circuits > Arduino
25 Views, 0 Favorites, 0 Comments
Networked Plant Auto-Waterer With Water-Source Emptiness Detection Using Arduino WiFi Rev4
I designed and built a networked plant auto-waterer with water-source emptiness detection. My system monitors soil moisture, delivering water with a pump if the soil is dry, and also monitors the water level of whatever reservoir the user is using, if it gets too low to water it will use a LED to alert the user to fill it. Users can check the soil moisture and water level at any time on an app/website.
Safety & Responsibility Notice
This project is provided for educational and experimental purposes. You are responsible for assembling, powering, and running the system safely.
Always follow basic electrical safety practices, especially when working with water, pumps, or external power supplies. Run network services only on trusted local networks.
The author is not responsible for damage, data loss, or injury resulting from use or modification of this project.
Supplies
Parts list:
- Arduino rev 4 WiFi
- Bread board
- 3-5v DC water pump
- Keyestudio water sensor
- Keyestudio soil humidity sensor
- LED
- 14 jumper wires (2 for power and ground to bread board, 3 per each of 2 sensors and 1 of the actuators plus 2 for LED and plus one for 12v power adapter to relay)
- 1 Resistor
- 5v power adapter
- DC Power jack
- 5v Relay
- Vinyl tubing
- Any water container (ideally height of your water sensor)
- Duct tape for securing pieces to container
I used parts from the 48 in 1 keyestudio sensor starter kit, which I highly recommend to anyone to tinker with:
I purchased this kit, it came with the pump, relay, vinyl tubing, and a soil moisture sensor I did not use (I used the soil moiture sensor from the 48 in 1 kit):
https://www.amazon.com/dp/B097BGSG6T?ref_=ppx_hzsearch_conn_dt_b_fed_asin_title_3
I also purchased a 5v power supply with a DC terminal connector adapter:
https://www.amazon.com/dp/B09W8X9VGK?ref_=ppx_hzsearch_conn_dt_b_fed_asin_title_1
Hardware
Now you have all your parts together, follow these steps to wire up the sensors and actuators to the Aruduino. Take extra care with the wiring of the water pump.
The water level sensor is waterproof, when it is called to read it returns an integer 0-1023, with 0 being no water detected and 1023 fully submerged. To wire them in this circuit, connect the positive to the power on the breadboard and the negative to the ground on the breadboard. Connect the output to an analog pin on the Arduino.
The soil humidity sensor can be inserted into soil, it returns an integer 0-950 when it is called to read, 0-300 is dry soil, 300-700 is humid soil, and 700-950 is in water. To wire them in this circuit, connect the positive to the power on the breadboard and the negative to the ground on the breadboard. Connect the output to a different analog pin on the Arduino.
The 3-5v DC water pump is not in the keyestudio 48-in 1 kit, but there are many readily available and affordable. I purchased a submersible model from Adafruit. It must use a relay with the Arduino and have a separate power supply that is connected using an adapter to the relay because the Arduino cannot power it safely with 5v and must be protected from the higher voltage. The pump can either be turned on or off with digital write low and high respectively (note that Low is on), when on it sucks water through the input and pushes it through the output. It came with vinyl tubing that can be cut to the desired length. To wire this plug the ground into the 5v power supply using the DC adapter, and plugged the positive into the COM port on the relay. Plug the 5v power adapter positive into the NO slot on the relay. On the other side of the relay, connect the positive to the power on the breadboard and the negative to the ground on the breadboard. Connect the output to a different digital pin on the Arduino. It is important to note that given more time and when willing to spend more I would get a more powerful reliable motor that does not need to be submersed, usually around 12v. To use this I would get a 12v power supply and then follow the same process with these parts switched.
The LED can be turned on and off with digital write high and low respectively. To wire it in this circuit, connect the positive to the power on the breadboard using a resistor and the negative to the ground on the breadboard. Power the side of the breadboard with LED using a digital pin for the LED only.
Finally, attach the water sensor to the inside of your water container (whatever you want, just at least as tall as your water sensor) with duct tape, same with the pump, put the soil moisture sensor in the soil of a plant, and duct tape the vinyl tubing to the pot after attaching the other end to the pump output.
Some helpful resources I utilized:
https://docs.keyestudio.com/projects/KS0349/en/latest/KS0349.html#project-23-water-level
https://docs.keyestudio.com/projects/KS0349/en/latest/KS0349.html#project-24-soil-moisture
https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-controls-pump
https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-relay
Software
Now the hardware is all set up, it's time to set up the software. There is going to be two files, one an ino to handle plant care and serve a client in the form of a Python file that will save the data in a csv and serve the information to a web client with an html file.
INO File
FSM for Plant Care System non-networked
Sense: Read from soil humidity and water sensors.
Think: Check to see if soil humidity is below dryThreshold, set true or false. Check to see if water is below waterLowThreshold, set true or false.
Act: If water is low, turn on the LED and go back to Sense. If soil humidity is below dryThreshold, water the plant for wateringTime seconds. Otherwise, do nothing.
Final FSM will have 8 states using the same logic as the earlier plant care one but with networking:
- INIT (largely administrative, reads and measures sensor values, goes to GET_REQUEST)
- GET_REQUEST (checks for a client, if there is it reads registration line. If no client go to SENSE, if there is, go to PARSE_REQUEST)
- PARSE_REQUEST (takes registration line and parses into usable pieces like IP, port, measurement, and timing parameters. Then goes to SENSE)
- SENSE (Reads and updated soil moisture and water level, goes to THINK)
- THINK (Checks timing from registration to decide to respond or not, updates isSoilDry and isWaterLow, if there is a clientRequest go to ACT, otherwise GET_REQUEST)
- ACT (if water is low LED on, else if soil is dry water, if it is time to send a notification as decided in THINK, builds message with BOTH sensor readings, if should send goes to SEND_RESPONSE, otherwise SENSE)
- SEND_RESPONSE (connects to client and sends sensor values, goes to SENSE)
- DONE (exit point, administrative as GET_REQUEST is base state)
I have attached my ino file for reference, but it was fun to program and I recommend giving it a go yourself.
Python File
The Python file reads in command lines from a "registrations.csv" in this format:
DELAY_MS,"register,RECEIVER_IP,RECEIVER_PORT,MEASUREMENT,EVENT,START_MS,DELTA_MS,DURATION_MS"
an example would look like:
0,"register,0.0.0.0,1025,soilmoisture,any,5000,5000,60000"
replace 0.0.0.0 with the ip address of your own machine running the python server.
For my code, to run the file put
python filename.py --database ./database.csv --serverName X.Y.Z.W --serverPort 80 --registrations ./registrations.csv
with your info replacing the filename, database file name, ip of the Arduino, and registrations file name with your own in the terminal in the directory containing the file.
Make sure there are two csv files in the directory, one as a database and the other as registration lines in the correct format.
I have attached my python file, but again I would recommend giving it a go yourself.