In 2016 I built an automatic watering system, to keep my plants alive for a couple of months. I used an oversized water tank because I was unsure how much water would be needed for two months when nobody would be in the apartment. It turned out that the water tank would have lasted for over a year, based on how much water was used during the summer.
The watering system took too much space on my living room floor, so I eventually dismantled it and rebuilt it as a much smaller system that could fit in the window sill. I changed the pump to a much smaller pump, and the water tank was replaced by a 1 liter ice cream box. The electronics still took up too much space. Here are the components the system used:
- Arduino Uno to generate the pump control signal and measure soil moisture.
- Breadboard to connect moisture sensors to the Arduino.
- Prototype board for pump power switching.
- Raspberry Pi 2B powering the Arduino, and providing remote login shell.
- Two power plugs to power the Raspberry Pi and the water pump.
The moisture sensors were fun to play with but in practice they were not that useful, so I removed them. That removed the need for analog signal input which meant I could remove the Arduino and just use the Raspberry Pi to generate the pump control signal.
I bought a cheap buck converter so I could power the Raspberry Pi with the same power source as the water pump. Now I only need a single 12V supply to power the system. I redesigned the pump control board to integrate the converter to the same board, and the 5V output for the Raspberry Pi is connected using a scrap Micro USB connector.
With the new electronics design I could fit everything into a small plastic box. The water pump is hot glued to the same box, and power is connected by an XT60 connector so that I can easily disconnect and thread the power cable through obstacles if needed.
Watering is scheduled with cron:
$ crontab -l # Water for 20 seconds each day at 17:22: 22 17 * * * /home/pi/git/water/water 20
The control software is a very simple C program that controls a GPIO pin on the Raspberry Pi.
Raspberry Pi GPIO
The control signal for the pump is output via a GPIO pin on the Raspberry Pi. In recent Raspbian versions you can access the GPIO pins via the Linux file tree, so I wrote a small C program to interface with the GPIO pins. The code is very simple, but you can make it even simpler if you use a library like wiringPi. I wrote my own GPIO code for fun. You can reuse my code freely if you want to. Here is the full source: