Green water

pascal boudalier
7 min readJul 26, 2023

Use solar to water your garden

Remotely controlled green watering system

July 2023. A heat wave is covering Europe.

What a wonderful opportunity to build a watering system for my garden! A remotely controlled one, meaning I can water when away from my house.

Of course, one can buy such a system for a couple of 100’s euros (or dollars, or pick your currency). But it is more fun to build it and it will cost a fraction of the price. And last, it will be entirely closed loop (see closing comments)

So let’s get wet.

What I had in mind:

  • To use water from a rainwater harvester. Not so much a water saving doctrine (even if every little action helps), but a safety one. I do not fancy water pouring from the public water system for days because something went wrong with my application while I am away.
  • To use drip irrigation, as well as a pump to deliver water to above ground places, such as flower boxes.
  • To be solar powered. This watering system will sit where it is the most convenient with respect to the plants, independently from the home electrical circuit.
  • To use a smartphone to control the watering.

Note: The source code for this project is on github.

Hardware

The hardware involved is quite simple:

  • An on/off valve allows the water to flow from the water tank to the drip irrigation. It works using gravity. In other words, the pressure from the tank will push the water in the drip pipe.
  • A pump raises water to reach several flower boxes. This system uses a network of aquarium-type pipes.
  • A ESP32 microcontroller controls the valve and the pump using relays.
  • A 12V battery , connected to a solar panel , provides 24x7 energy to the system
Just a apply 12V DC to the valve, and it shall open
The blue pipe distributes the water from the tank. The white piece on the right is the valve. The valve is connected to drip irrigations (on the right) and the pump (on the left)
The output of the pump goes to several flower boxes (aquarium-type pipe network)

Pump/Valve control

The valve and the pump are controlled by an application running on an ESP 32 microcontroller.

The ESP32 controls the valve and the pump using relays.

The ESP32 is my go-to microcontroller. It is powerful, cheap and has built-in Wi-Fi.

The application is written in MicroPython (a port of Python available for many microcontrollers). I stopped writing C code years ago, and never looked back.

Note: I also leveraged a PCB which I had already designed (PCB design here)

Casing

Waterproof casing is one of the headaches when installing a system in the wild. After years of experiments, I still have not found the perfect solution.

For this application, I am using Ikea plastic boxes and cable glands (the hole for the gland is elegantly pierced using a soldering iron)

The battery and its solar charge controller. The (hopefully) waterproof casing is provided courtesy of Ikea.
Ready to go into the wild. NASA would not have done any better.

Smartphone application

The system is controlled using a smartphone application, built with the excellent Blynk platform

What you get on your phone. The two big buttons control the valve and the pump.

With Blynk, no code needs to be written on the smartphone side (Android, iOS). The smartphone application is built by assembling (drag and drop) widgets. The MicroPython application running on the ESP32 interacts with those widgets.

(See another Blynk based project — award winner)

The application runs like this:

  • Just press one of the green buttons to open the valve (and the drip irrigation) or to start the pump.
  • A led (on the right of the button) will lit to confirm the ESP32 has obeyed your order.
  • The sliders allow to adjust the running time, after which the valve will automatically close and the pump will stop (to avoid draining the tank)

That’s it for non-geeky.

Energy

Energy is a typical concern for embedded/battery operated systems.

Let’s see what we have:

  • I installed a 25 W (Watt) solar panel and a 12 Volt, 8 Ah (Ampere-hour) battery. The battery energy capacity is therefore 12x8 = 96 Wh (Watt- hour) (eg a fully charged battery can deliver 96 W for an hour, or 48 W for 2 hours, etc. ..)
  • 25 W is the theoretical peak production of the panel. In reality it is more like ~20 W. But still, with 5 h of sunshine, I can fully recharge the battery in one day (20 Watt x 5 h = 100 Watt-hour) or in 2 days if there are some clouds.
  • The ESP32 is powered from 3.3V and consumes in the order of 100 to 200ma (milliamperes). Per day, this represents 3.3V x 0,2A x 24h = 16 Watt-hour (or ~ 1/5 of the battery capacity)

Therefore the combo panel/battery is more than adequate. It’s even oversized (It’s ok, I am going to use it for other applications as well)

More on Energy

Even if I have enough energy to power this project, it is still a good idea to minimize the energy consumption as much as possible (if only to leverage the battery for other applications)

The ESP32 can be put in “deep sleep mode”. In this mode it will stop most of its circuitry to minimize power consumption, and wake up at regular and programmable intervals to check if it has any job to do.

Theoretically, deep sleep power consumption can go as low as a few micro amperes. That’s more than a factor of 1000 compared to “normal” mode.

Caveat: Micro amperes is for the ESP32 chip itself. The ESP32 board I used has several circuits which are not controlled by the deep sleep mode, and which will keep draining the battery 100% of the time. I even experienced a led constantly draining a few milliamps, the absolute horror of low power design. I knew this, but I had already the PCB for this very ESP32 board, so it is OK to waste a few milliamperes while sleeping. This other ESP32 board is a better choice for energy constraint, deep sleep applications

Note that sleep mode is optional. The application can either runs in normal mode (the ESP32 is always on, ready to process commands sent from the smartphone), or use deep sleep mode (in that case it will only process commands the next time it wakes up).

Choosing one versus the other is just an energy versus response time tradeoff. Pick up your side.

Different wakeup interval can be set for night, day and “late afternoon”, i.e. the typical watering period. The idea is that the system should be more responsive in the afternoon, at the expense of a slightly increased power consumption.

On the right screen capture is the configuration of the sleep timers (e.g. 5mn during late afternoon and 50mn at night). On the left screen capture the sleep mode is set ON (the ESP32 will immediately go to sleep for the configured period — see sleep status)

Nothing prevents configuring the system with very short sleep interval at night, or even no sleep at all, for those of us fancying watering in the middle of the night.

Of course, while sleeping, the ESP32 is irresponsive. However the valve/pump can be turned on in the app during that time, so the next time the ESP32 wakes up, it will immediately starts watering. The valve/pump button status is stored in the Blynk server (running on a Linux system — more on that later)

The ESP32 is currently sleeping, and the pump is set to be started. The led is not lit, indicating the ESP32 has not processed the request yet (it will, as soon as it wakes up).

Over The Air

The ESP32 MicroPython program need to be “flashed” into the chip’s flash memory. This is typically done with a USB cable connecting a laptop to the ESP32.

Of course, moving the laptop to the garden, or moving the ESP32 back in home is a no go. Such a pain. OTA (over the air) update is what we need.

Push the “update” button on the smartphone app to allow download, use any browser to access the ESP32 IP address, and you will be greeted with the screen below:

From there, you can enter a password and transfer a new version of the MicroPython app. Then push the reboot button on the smartphone.. et voila!

More on Blynk

I have been using Blynk for years. It is a fine way to get quickly a nice looking smartphone application to control microcontroller projects.

Blynk is comprised of 3 components:

  • The client program, user written, running in the ESP32.
  • The smartphone app, assembled by dragging and dropping widgets.
  • The Blynk server, acting as the middle man between the ESP32 and the smartphone.

The Blynk company provides an industrial grade, feature-rich server in the cloud. You can try using it for free. However, for this watering application, I decided to stick with an earlier version of Blynk, allowing to run my own server locally (see closing comments).

The server runs as a docker container on a Raspberry PI (solar powered as well), sitting on my desk. All you need is to download a ready-made docker image for the server and start it with a single command.

see the start blynk server script

# start the Blynk server as docker container
docker create -p 8089:8080 -p 9444:9443 -p7443:7443 --name=Blynk_private_server --restart=always -v /home/pi/APP/Blynk/config:/config -v /home/pi/APP/Blynk/data:/data maxbanton/blynk-server:latest

echo 'start container'
docker start Blynk_private_server

Closed loop

Besides the functional requirements listed earlier, this application was also designed to be “closed loop”:

  • water comes from my roof
  • energy for the server, the ESP 32 and the Wi-Fi comes from solar panels
  • no dependencies on any server in the “cloud”

no survivalism there .. just resilience

--

--

pascal boudalier

Tinkering with Raspberry PI, ESP32, RiscV, Solar, LifePo4, IoT, Zigbee, energy harvesting, Python, MicroPython, Keras, Tensorflow, tflite, TPU. Ex Intel and HP