How I built a watering system for my plants using a Raspberry Pi

Vaibhavi Pai
6 min readSep 26, 2022

Having a Green Thumb, it doesn’t help that I travel quite often, leaving my plants orphaned and un-watered for days.

Being an engineer, I knew this was something that could be taken care of by hacking together a few electronic components, and configuring them with a few lines of code (Although I had never tinkered with electronics before). Hence was born this project- I like to call it Garduino (pardon the misnomer, as it was built with an RPi, and not an arduino (: ).

I created a logo for it, too :)

When the idea occurred to me, all I wanted was an Android app that I could use to signal the RPi, which in-turn could regulate the water flow to my plants (I now realize that this can be extended to make it as complex as one can imagine).

At a high-level, I identified the following quests that I needed to conquer-

  • Figure out all the components required for the circuit and build it.
  • Write logic in the RPi to be able to control signals to the watering circuit.
  • Figure out how to expose an endpoint from the RPi that could be controlled from anywhere on the Internet.
  • Build a tiny mobile application that I could use to contact my RPi whenever I wanted to water my plants.

Part 1- The circuit

I decided to use a Raspberry Pi Zero W (It has inbuilt WiFi, and since my friend already had it, I could borrow it temporarily). Apart from this, I figured that I could do with just a relay and a water pump, with some help from jumper cables, and adapters.

A relay can be used as a leverage since the maximum amount of current that can be drawn from the RPi(16mA from any given pin) would not be quite sufficient to power the circuit with the water pump. A relay on the other hand, can be powered on with very less current(as less as 10mA), which in-turn can close the switch of a circuit (hence completing it) with a much higher load.

Here are a few resources that I went through during my research, that were super helpful for my understanding.

Here are Amazon links to some of the components I had to buy (not affiliate)-

Here is a rough circuit diagram of what my circuit looked like-

Circuit diagram with the RPi, Relay and Water pump

Once I had the circuit planned out, and all the components to build it out, I came around to finally getting my hands dirty.

Here is what the circuit looked like once I was done-

The final circuit comprising of the RPi, Relay, and water pump with my plant, and a small water source :)

A relay usually has 3 output terminals- Common, Normally Open(NO), Normally Closed(NC). Most commonly, the switch of the relay toggles between the NC and NO terminals, the NO circuit being open when the relay is powered off. I connected the water pump circuit between the Common and NO terminals, as when the relay is turned off, so should my pump.

I used a multi-meter to test individual parts of the circuit before I put them together and got it running. A multi-meter is very useful to measure the output voltage of the RPi, and also to check continuity between the output terminals of the relay. Here is a nice video to understand how to use a multi-meter-

Part 2- The code

Instead of creating and exposing a public endpoint, I decided to go with a real-time database like the one offered by Google Firebase, using which I can have one key-value pair(a boolean called toWater) that can determine the state of whether the water pump needs to be turned on or not.

The mobile app could set this key to True whenever the plants needed to be watered, and the RPi could pick up this change of state, and in-turn provide the appropriate output signal to power on the pump circuit.

The flow diagram below would make it little more clear-

Using a real-time database to keep track of state

I setup my realtime database on Google Firebase, and also configured my RPi to be able to fetch its value.

I stored my database configurations in a separate json file that is present locally, and I have not uploaded it for security reasons (and I recommend you do the same).

I referred this really useful blog-post to setup Firebase for the RPi-

The final Python script that I deployed on the RPi looked like this-

Part 3- The mobile app

To complete the entire system, I wrote a small Android app with Firebase integration which had a simple button, that fetched the toWater key from the database, and updated its state to True.

With this, all components of my watering system were complete, and I was finally able to control the water-pump with a button click, from anywhere in the world!

Extensions

Although this is a very simple system, I wanted to get my hands dirty and get around to building something, since I have been fascinated with the Raspberry Pi and its potential ever since I discovered of its existence.

I have thought of these extensions that could potentially be added to this system to automate it end-to-end and enrich it further-

  • Logs of when the plant was watered can be displayed on the mobile app for reference.
  • A mechanism for detection and alerting should be in place when water is going to run out in the tank.
  • Moisture sensors can be used to decide on watering schedules and quantity of water that needs to be provided.
  • A valve-based system can be used along with moisture sensors to include multiple pots into the system.
  • A command-control server model can be created, where the RPi can be controlled by sending commands to the DB. This would be helpful, as we would not need to SSH into the RPi every time we need to configure a small change in the RPi.

Final Note

I had a fantastic time building out this project, and I fervently hope I come around to building out atleast some of the extensions I’ve listed above, to make this system more scalable and extensible for anyone to use in their garden.

I am also grateful to my friend, Vaibhav Nayak for helping me get the ball rolling and for graciously allowing me to borrow his RPi.

Feel free to follow this project for updates in the future here-

--

--