Sprinkler System Water Conservation

This project uses weather API's to determine if significant rain has fallen, or is forecast, and if so disables the sprinkler system.

Similar projects worth following
This MicroPython project on an ESP32 uses weather API's to determine if significant rain has fallen in the last day, or is forecast today, and if so disables the garden watering system to conserve water. It reports the rainfall and system status to ThingSpeak. As the hardware is battery operated the deep sleep mode of the ESP32 is used to extend the battery life.

This controller is suitable for use with automatic watering systems which expose the ability to disable the system by making a connection open circuit. Normally a rain gauge would be connect and the system would be disabled if more than a certain amount of rain had fallen. This really only solves half the problem, since it could start to rain heavily immediately after the garden has been watered.

My solution to this problem is use the Wunderground HTTP API to obtain both the rain that has fallen in the last day and the rain that is forecast to fall, to determine if the system should be enabled.

As my watering system controller is battery operated, this project too must operate with a battery. To avoid inconvenience the battery should last the 6 months during spring, summer and autumn when the system is required. This is achieved by minimizing current consumption in the circuit and using the deep sleep mode of the ESP32. The system is woken once per day by an interrupt from a real time (RTC) clock module.

The Loboris fork of Micropython for ESP32 is used as I found this was significantly more reliable establishing a connection to my WiFi router.

I used a poly-carbonate box with an O-ring seal and fitted a PTFE breathable vent (allows air, but not moisture through), so that pressure variations due to temperature changes do not cause seal failures resulting in moisture ingress. The electric connection to the water system is via two brass rods sealed with epoxy and protected by heat shrink tubing with internal adhesive.


Circuit schematic for watering system controller.

Portable Network Graphics (PNG) - 126.92 kB - 03/20/2018 at 06:17


  • 1 × ESP-WROOM32
  • 2 × bs170g Discrete Semiconductors / Transistors, MOSFETs, FETs, IGBTs
  • 1 × Latching Surface-Mounting DPDT Relay Omron G6SK-2-H DC3
  • 2 × 1N4001 Discrete Semiconductors / Diodes and Rectifiers
  • 1 × 10k Resistor

View all 17 components

  • Demise of Wunderground and reliability improvements

    Chris04/21/2019 at 01:16 0 comments

    With the demise of the Wunderground API as a free service I have converted my program to use other services for the current and forecast rainfall. This functionality has been broken out into separate modules, so it should be fairly easy to replace these with services of your choice.

    Another key improvement has been the addition of retry with back-off functionality to HTTP requests to deal with the un-reliability of HTTP requests and servers, this maximises the chance of getting valid readings.

    Connecting to WiFi has also been a problem occasionally and this is now handled by retry functionality, with the device going into deep sleep between tries to conserve  the battery.

    The system has performed well over this summer with very few missing readings due to errors and should be even better next summer with WiFi retry in place.

  • Errors from Wunderground API?

    Chris04/06/2018 at 07:23 0 comments

    Currently the program has very simplistic error handling which makes sure the system is left in an 'on' state and goes back to sleep if any error occurs. 

    I am suspicious that the Wunderground API might be the source of some errors and have written a Python test program on my Raspberry Pi to call the API and record any errors that occur. Results from this can then be used to improve error handling, perhaps by querying an alternate PWS if the primary returns an error.

View all 2 project logs

  • 1
    Install Loboris Micropython for ESP32

    The code depends my personal fork of Loboris Micropython for ESP32 which contains some improvements to the requests library. You will need to build and flash this as described in Build Micropython for ESP32Build Micropython for ESP32, substituting the clone URL with that for my repository.

  • 2
    Configure Thingspeak

    Configure a ThingSpeak channel something like:

  • 3
    Obtain RTC Library

    Download urtc real time clock (RTC) library.

View all 7 instructions

Enjoy this project?



Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates