Build an Automated Gardening System With the Raspberry Pi Pico W

With a green thumb and some patience, gardening is a lovely hobby regardless if you have a few exotic plants indoors or have a full-blown outdoor garden with potatoes and perennials.

With that said, there are also times when your patience may run out when plants begin to die for what seems to be no good reason at all.

4

The Raspberry Pi Pico W can help to provide a solution to ensure that plants will thrive without lifting a finger at all (well, almost).

Let’s review how a plant monitor, some code, and a tiny microcontroller will keep track of your plant’s health from anywhere in your home.

woman tending to her greenhouse garden

Required Hardware

Surprisingly, there’s not a lot of hardware required. A lot of the magic is contained within the Plant Monitor. You really only need a few items to get started.

Although this plant monitor supports the use of alligator clips, this project utilizes the pin connectors attached to the back side of the plant monitoring device.

plant monitor in soil that is connected to a microcontroller

Setting Up the Gardening Assistant

This project involves connecting the plant monitor to your Raspberry Pi Pico W, as well as creating and manipulating code to get everything working. A web server will be required to serve up a simple webpage accessible within your home internet connection.

There are different model versions of the Raspberry Pi Pico. For this project, you will need to use a Raspberry Pi Pico W. To learn about what the Pico W is capable of, check out our guide onwhat the Pico W is and what it can do.

simple html page displaying soil statistics

First, let’s ensure that the plant monitor is connected and working properly. Later in the article, you will tackle setting up a simple web server used to monitor your plant with any browser-enabled device connected to your home network.

Preparing the Plant Monitor

With many sensors available to purchase through various internet sites, you will come to learn that some soil sensors will wear down easily in soil and others stand up to the elements fairly well. The Monk Makes Plant Monitor is a nice option as it is not prone to corrode in soil. Not only does this monitor measure soil wetness, but it also measures humidity and temperature too.

Only four pins will need to be connected from the plant monitor to your Raspberry Pi Pico W:

automate-gardening

Once connected to power, your Raspberry Pi Pico W will be able to provide power to itself and the plant monitor. You’ll notice some lights on the hardware that confirm the device is in working order. As well, there’s an LED light that will shine green, yellow, or red (depending on the level of moisture detected in your soil).

Although the Monk Makes Plant Monitor comes with some great python modules, you’ll still need to create some simple code in order to monitor the health of your plant’s soil. You can grab the following python files from ourMUO GitHub repository.

You’ll needpmon.pyandtest.pyfor the soil sensing portion and the python filesmicrodot.py,mm_wlan.py, andpico_w_server.pywill be used to complete the simple web server later.

Now is a great time to pause and refresh yourself withsubtle differences between MicroPython and Pythonif you have not done so already.

The python file,pmon.py, creates a MicroPython Class for the plant monitor. UART will take care of the duplex data transmission and then some work converting analog to digital is also necessary. You’ll also notice thewetness,temp, andhumidityfunctions being defined in this file as well.

Next, you’ll need thetest.pyfile obtained from ourMUO GitHub repository.

You’ll notice that modulestime, pmon(fromPlantMonitor), andmachineare required o properly monitor your plant’s health.

As thePlantMonitormodule is imported, all that’s required to monitor soil conditions is a simple while loop. Also, theprintcommand will output the soil moisture, temperature, and humidity readouts after runningtest.pyin Thonny.

Don’t feel like watering your plant when the soil is too dry? Assign your pump relay to a pin on the Raspberry Pi Pico and utilize an if statement to watch for a wetness value (out of 100) to trigger your water pump, via a relay, to turn on and dispense water again.

You will want to do some testing in order to find that perfect balance to ensure your plant is satisfied with the amount of water it’s receiving. You can also add in another if statement to turn on a heat lamp, via a relay, if your plant is too cold.

Simple Web Server

You’ll need three python files, from ourMUO GitHub repository, in order for your Raspberry Pi Pico W to broadcast the soil statistics to your home internet connections:

Themicrodotfile handles the back-end functions to create this simple HTTP-based web server and displays the python code output as a html-based webpage that can be called using the IP address of the Raspberry Pi Pico W.

Themm_wlan.pyfile offers a simple way to connect to a wireless network. You’ll either receive an IP address of your Raspberry Pi Pico and a connected message. If the connection was not successful, you’ll receive a connection failed message instead.

Thepico_w_server.pyfile is where you enter the SSID (remember that the Raspberry Pi Pico W only connects to 2.4GHz SSIDs) and your Wi-Fi password. Within the HTML section, it’s possible to customize what your web server will display on a web browser. You can also remove the comments from the refresh section and tweak the interval should you not want the web page refreshing every second or so.

At the very bottom of this file, you may also customize the port as well. This is handy if you wish to expose this information to the internet outside your home.

When you run yourtest.pyfile, the required server python files (mm_wlanandpico_w_server) are imported for you. After you run thetest.pyfile, grab the IP address if your Pi (found in the Thonny output) and add the port you’ve used (default is 80) from any web-browser that is connected to the same 2.4GHz SSID at home. You should see something like this:

In order to reduce the dependency of your connected PC, change thetest.pyfile tomain.pyand save on your Raspberry Pi Pico W. You may also wish to consider connecting an LCD to your Pico so that you program the display to output the IP address (when you remove the dependency of your connected PC).

Bring Back That Green Thumb

With a sophisticated soil sensor and a simple web server it’s possible to now monitor your plant’s health from a web-browser anywhere in your home.

Feel free to tweak the code as you see fit. If you’re up for it, consider creating a soil sensing app that adds some polish to the simple web server you’ve just set up.

To make this project feel complete, add a pump and relay, along with a heat lamp, and you’ll have yourself a fully automated garden. Now you’ll be able to forever maintain your ‘green thumb’ status.

Gardening is often enjoyable, but always time consuming. So why not automate the more demanding gardening tasks to claw back some of that free time?

Revolutionize your driving experience with these game-changing CarPlay additions.

It saves me hours and keeps my sanity intact.

These are the best free movies I found on Tubi, but there are heaps more for you to search through.

You’re not getting the most out of what you pay for iCloud+.

Don’t let aging hardware force you into buying expensive upgrades.

Technology Explained

PC & Mobile