Connected Automatic Garden Watering System
by zetiti10 in Circuits > Electronics
2963 Views, 38 Favorites, 0 Comments
Connected Automatic Garden Watering System
I had some issues, so I will create a new version of the connected garden for 2024. I keep this instructable available, but the conception is not perfect.
I don't speak English well, so I apologize if I make any mistakes.
Watering plants in the garden can be a problem for gardeners who enjoy going on holidays, but with some electronics, we can solve this problem.
The objective is to make the system completely autonomous. To achieve that, we will install and create several systems:
- First, we need to have a water source available. For that, I have installed a water tank that collects water from the roof, along with a water pump to pressurize it.
- Next, I have installed the Gardena Micro Drip system in my greenhouse to water the plants.
- The first electronic component will be placed in the garden to measure values using sensors: temperature, humidity, and soil moisture.
- The second component will control a solenoid valve.
- I will program everything using ESPHome.
- Lastly, we will need some configuration in Home Assistant: a dashboard and automations. Everything will be connected.
All the files are available here: https://drive.google.com/drive/folders/15fiRymlIiZhA1koVKPhr2CvQsIWobn2T?usp=sharing.
Supplies
Given links are just for help. You can find other supplies.
Supplies
- Wemos D1 Mini x2 (https://amzn.eu/d/4UmJvZm).
- 5v solar panels (https://amzn.eu/d/jafF5y9).
- TP4056 battery management module (https://amzn.eu/d/fyjC78L).
- MT3608 step-up power module (https://amzn.eu/d/ehXjaog).
- 3.7V Li-ION battery (https://amzn.eu/d/2VJPoi5).
- 12v adapter (https://amzn.eu/d/5Gm1BM5).
- DHT11 temperature and humidity sensor (https://amzn.eu/d/7W3Vn16).
- Soil moisture sensor v1.2 (https://amzn.eu/d/e7DfL4u).
- 1/2" 12V Solenoid valve (https://amzn.eu/d/bMOStzO).
- Relay shield (https://amzn.eu/d/1ledDgf).
- M3*3 threaded inserts (https://amzn.eu/d/d4YVlWc).
- M3*8 screws (https://amzn.eu/d/aSTGO6K).
- Button (https://amzn.eu/d/3Bxf5Rl).
- Switch (https://amzn.eu/d/3IHusR9).
- Silicon (https://amzn.eu/d/7lfs078).
- Connectors (https://amzn.eu/d/0nBgd10).
- Gardena Micro Drip System (https://www.gardena.com/fr/outils-jardin/arrosage/goutte-a-goutte).
- 3D printing filament.
- Water tank.
- Water pump.
- Garden hoses.
WARNING: I recommend using materials that are resistant to UV rays (filament, cables, etc.).
The Water Tank
Rainwater is indeed better than tap water for watering the garden. That's why I installed a water tank to collect rainwater.
The water from the roof is collected by gutters and directed into the tank.
Next, a water pump pressurizes the water. The water output is similar to tap water. If the solenoid valve is closed, the water pump motor does not operate.
To avoid any problems during the summer, I have installed a water sensor in the tank. If the tank is empty, the water pump will not run.
Gardena Micro Drip System
To distribute water in the garden, I have installed a Gardena Micro Drip system.
The system consists of pipes along the edges of my greenhouse, as well as sprinklers positioned at the four corners. This setup ensures that every plant in the garden receives water.
Downloads
Garden Sensor (software)
Before soldering each component of the autonomous sensor, it is important to program the Wemos D1 Mini.
As mentioned earlier, everything will be connected to Home Assistant, and we will use ESPHome to program the board.
Here is my configuration:
esphome:
name: garden-sensor
esp8266:
board: d1_mini
logger:
ota:
password: PASSWORD
wifi:
ssid: SSID
password: PASSWORD
ap:
ssid: "Garden-Sensor"
password: PASSWORD
deep_sleep:
run_duration: 30s
sleep_duration: 30min
id: deep_sleep_1
mqtt:
broker: 192.168.1.1
username: USERNAME
password: PASSWORD
on_message:
- topic: garden-sensor/ota_mode
payload: 'ON'
then:
- deep_sleep.prevent: deep_sleep_1
- logger.log: "Ready for OTA update."
- topic: garden-sensor/ota_mode
payload: 'OFF'
then:
- deep_sleep.enter: deep_sleep_1
- logger.log: "Ready for deep sleep."
birth_message:
topic: garden-sensor/status
payload:
will_message:
topic: garden-sensor/status
payload:
captive_portal:
sensor:
- platform: adc
pin: A0
name: "Garden soil moisture"
update_interval: 30s
unit_of_measurement: "%"
filters:
- median:
window_size: 7
send_every: 4
send_first_at: 1
- calibrate_linear:
- 0.32 -> 100.00
- 0.66 -> 0.00
- lambda: |
if (x < 0) return 0;
else if (x > 100) return 100;
else return (x);
accuracy_decimals: 0
- platform: dht
pin: D2
temperature:
name: "Garden temperature"
humidity:
name: "Garden humidity"
update_interval: 30s
Using DeepSleep to conserve battery power is a great approach. In your case, the Wemos D1 Mini wakes up for 30 seconds to send values to the MQTT broker and then goes back to sleep for 30 minutes.
To prevent it from sleeping during an OTA update, you can send the message “ON” to the topic “garden-sensor/ota_mode” using an MQTT explorer. And to reactivate DeepSleep, you can send the message “OFF” to the same topic.
Including “Birth message” and “Will message” in the configuration helps prevent Home Assistant from displaying “UNAVAILABLE” on the dashboard when the sensor is in sleep mode.
Here is the file garden-sensor.yaml: https://drive.google.com/file/d/131--xXoS7owsuhab2ZIBCGEY19BkaZ--/view?usp=sharing.
Garden Sensor (hardware)
To ensure efficient water usage, it's important to water the garden only when necessary. This can be achieved by measuring soil moisture using autonomous sensors powered by batteries and solar panels. The system can measure the following parameters:
- Temperature
- Humidity
- Soil moisture
Here are the steps to assemble the sensor:
- Print the three parts: Garden sensor bottom, Garden sensor top, and Garden sensor hood.
- Install four threaded inserts in the bottom part: two for the soil moisture sensor and two for the closing screws.
- Trim the top part of the switch (plastic part).
- Solder the battery, battery management module, switch, and step-up power module together following the circuit diagram.
- Set the voltage: Turn on the switch and connect a voltmeter to the output of the step-up power module. Adjust the potentiometer on the module to achieve 5V. You can then turn off the switch.
- Screw the soil moisture sensor in place. Remove the connector and solder three wires.
- Place the battery management module and the step-up power module inside the box.
- Solder all the components together following the circuit diagram. Don't forget to connect a wire between the RST and D0 pins. This connection is necessary for DeepSleep mode. However, you'll need to disconnect it if you want to upload a new program using the USB port.
- Once all the components are assembled, you can test the system before closing the box.
- After testing, apply silicone to ensure a watertight seal, and then close the box using the two screws. To prevent water from entering the moisture sensor, put silicone on the edge of the PCB.
By following these steps, you should have a fully assembled garden sensor ready to be deployed.
Garden Sensor (Solar Panels)
To recharge the battery, I have installed two small solar panels that generate a 5V output. I have connected them in parallel.
I have positioned the solar panels at the optimal orientation and inclination for my location, which in France is 39° South. To adjust the orientation for your specific region, you can modify the angle in the provided FreeCAD file. Open the file, navigate to “Sketch” and make the necessary angle adjustments. You can find the appropriate installation angles for your region by conducting research online.
A cable is connected from the solar panels to the sensor, and I have soldered a USB connection to establish the connection between the cable and the sensor.
File Solar panel holder.FCStd: https://drive.google.com/file/d/1pFykgD-zCHYpg3dcMqew5fdpgk-EB40C/view?usp=sharing.
Downloads
Solenoid Valve (Software)
Before installing the system, we need to program the Wemos D1 Mini using ESPHome.
This program manages the relay that powers the solenoid valve and a button.
Here is my configuration:
esphome:
name: watering-solenoid-valve
esp8266:
board: d1_mini
# Enable logging
logger:
ota:
password: PASSWORD
wifi:
ssid: SSID
password: PASSWORD
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Watering-Solenoid-Valve"
password: PASSWORD
mqtt:
broker: 192.168.1.1
username: USERNAME
password: PASSWORD
captive_portal:
switch:
- platform: gpio
pin: D1
name: "Garden watering solenoid valve"
binary_sensor:
- platform: gpio
pin:
number: D4
mode: INPUT_PULLUP
inverted: True
name: "Physical button solenoid valve case"
filters:
- delayed_on: 10ms
- delayed_off: 10ms
I used MQTT, but you can use Home Assistant API because we do not use DeepSleep.
File watering-solenoid-valve.yaml: https://drive.google.com/file/d/1WLFhHFFiU1tWK5m_DLTLX2QG0nAxjKaa/view?usp=sharing.
Solenoid Valve (Hardware)
I used a junction box to house the electrical installation, which is installed on the hut. The purpose of the installation is to provide electricity for the water pump and the Wemos D1 Mini.
Here are the steps involved in the process:
- Solder the components that will be placed in the box, following the circuit diagram.
- Place the components inside the box. For the button, I secured it using hot glue.
- Print and install the cover for the solenoid valve.
- Solder a cable to the solenoid valve, ensuring that it has a connector on the other end.
Home Assistant (dashboard)
The final component of the automatic garden watering system is Home Assistant. Our objective is to monitor the sensors and control the automatic watering through the dashboard.
Monitoring the sensors is a straightforward process. However, controlling the solenoid valve requires the implementation of some automations.
Physical Button
In order to enable the functionality of the physical button on the box, we need to create an automation.
alias: Solenoid valve control button
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.physical_button_solenoid_valve_case
from: "off"
to: "on"
condition: []
action:
- service: switch.toggle
data: {}
target:
entity_id: switch.garden_watering_solenoid_valve
mode: single
Automatic watering
First, we need to create an input number to be able to define the watering time from the dashboard:
input_number:
automatic_watering_time:
name: Automatic watering time
min: 30
max: 1800
step: 30
mode: box
unit_of_measurement: sec
Then, we can create a script that do a watering cycle when it is triggered:
alias: Garden watering
sequence:
- service: switch.turn_on
data: {}
target:
entity_id: switch.garden_watering_solenoid_valve
- delay: >-
{{ '00:' ~ (states('input_number.automatic_watering_time') | int // 60) ~ ':' ~
(states('input_number.automatic_watering_time') | int % 60) }}
- service: switch.turn_off
data: {}
target:
entity_id: switch.garden_watering_solenoid_valve
mode: single
icon: mdi:water-pump
When the script is triggered, it will turn on the solenoid valve for a while defined by the input number
Now, we create the automation:
alias: Automatic garden watring
description: ""
trigger:
- platform: sun
event: sunset
offset: 0
condition:
- condition: numeric_state
entity_id: sensor.garden_soil_moisture
below: 30
action:
- service: script.garden_watering
data: {}
mode: single
At the sunset, we check is the soil moisture is below 30% to trigger the script we previously created.
For the dashboard, we can create a switch to disable the automation easily:
switch:
- platform: template
switches:
automatic_watering_automation:
friendly_name: 'Watering automation'
unique_id: switch.automatic_watering_automation
value_template: "{{ is_state('automation.automatic_garden_watring', 'on') }}"
turn_on:
service: automation.turn_on
target:
entity_id: automation.automatic_garden_watring
turn_off:
service: automation.turn_off
target:
entity_id: automation.automatic_garden_watring
To finish, we can create a card on the dashboard to manage the system:
type: entities
entities:
- entity: script.garden_watering
name: Start a cycle
- entity: input_number.automatic_watering_time
secondary_info: none
icon: mdi:clock-time-four
name: Watering time
- entity: automatic_watering_automation
name: Automatisation
title: Automatic watering
show_header_toggle: false
Everything is ready! You can now go on vacation and let your automatic garden watering system take care of your plants.
If you encounter any issues or have any questions, feel free to reach out to me on Discord: @zetiti10.
Enjoy your holidays!