With a green thumb and a little patience, gardening is a great hobby, whether it's a few exotic plants at home or an adult garden of potatoes and perennials.
But there are also times when your patience runs out when plants start dying for no apparent reason.
The Raspberry Pi Pico W helps provide a solution for plants to flower (well, almost) without lifting a finger.
Let's take a look at how plant control, code and a small microcontroller can monitor the health of your plants from anywhere in your home.
A tool is required
Surprisingly, it doesn't require much hardware. Most of the magic is in the Plant Monitor. You really only need a few products to get started.
Although this plant controller supports the use of alligator clips, this design uses pin fasteners that attach to the back.
Building a garden assistant
This project involves connecting the factory controller to the Raspberry Pi Pico W and creating and configuring the code to get everything working. A web server is required to provide the main web page that can be accessed using your home internet connection.
There are several models of the Raspberry Pi Pico. You will need a Raspberry Pi Pico W for this project. To see what Pico W can do, check out our guide to what Pico W is and what it can do.
First, make sure your active display is connected to the network and working properly. Later in this article, you'll walk through a simple web server setup that allows you to monitor your system using any browser-enabled device connected to your home network.
Setting up the system controller
With the many sensors available at various sites, some ground sensors simply penetrate the ground, while others capture the elements well. The monk is a good choice of plant monitor because it does not tend to rot in the soil. This monitor not only measures soil moisture but also humidity and temperature.
Raspberry Pi Pico W only needs to connect four pins of the system controller;
- GND goes to GND
- 3V is connected to the 3V3 output.
- RX_IN gets the path of GP0
- TX_OUT meets GP1.
Raspberry Pi Pico W can power itself and the system tracker when connected to power. You will see some lights on the device to confirm that the device is working. There is also an LED light that glows green, amber or red (depending on the amount of moisture in the soil).
Although Monk Makes Plant Monitor comes with some great Python modules, you still need to create some simple code to monitor the soil health of your plants. The following Python files are available in our MUO GitHub repository.
Location tracking requires pmon.py and test.py , then the python files microdot.py , mm_wlan.py and pico_w_server.py are used to complete a simple web server.
Now is a good time to relax and learn about the subtle differences between Micro Python and Python.
The Python file pmon.py creates a Micro Python class for resource monitoring. UART performs binary data transfer and also requires some analog-to-digital conversion. You will also see that the age , temperature and humidity functions are defined in this file.
Moisture Protection (Self)
return int( self . request_property( "w" ));
def get_temp ( self );
return float ( self . request_property( "t" ));
Moisture protection (self)
return float ( self . query_property( "h" ))
Lead_Off ( Automatic ) :
self .uart.write( "l" )
def led_on ( self ) :
self .uart.write( "L" )
Next, you'll need the test.py file that you got from the MUO GitHub repository.
You know how much time, pmon (from PlantMonitor ) and machine modules are needed to monitor the health of your plants.
The Plant Monitor module is imported so only a short time is required to monitor soil conditions. Also, the print command prints the humidity, temperature, and soil moisture readings after running test.py in Thonny.
time.sleep ( 2 ) # During PlantMonitor startup
pm = PlantMonitor()
As long as it is true .
w = pm.get_humidity()
t = pm.get_temp()
h = pm.humidity_find()
print ( "Humidity: {0} Temperature: {1} Humidity: {2}" . format ( w , t , h ) );
sleep time (1)
Don't want to water the plant when the soil is too dry? Put the pump relay on the Raspberry Pi Pico pin and use an "if" statement to look for the moisture content (in 100) to turn on the water pump and trigger the relay to start the water supply.
relay1 = pin( 15 , pin
If w = 24 # specify the age value 24/100
relay1.value( 1 ) # Enable the relay
relay1 ( 0 ) # turn off the relay
To find the right balance, you'll need to do some testing to make sure your plant is happy with the amount of water it's getting. You can add an additional statement to use the relay to turn on the heat lamp when your plant is too cold.
A simple web server
To send location statistics to your home internet connections, you need three Python files from the Raspberry Pi Pico W MUO GitHub repository:
- microdot.py:
- mm_wlan.py:
- pico_w_server.py:
The microdot file contains the backend for building this simple HTTP-based web server, and the Python code can access the output as an HTML-based web page via the Raspberry Pi Pico W IP address.
The mm_wlan.py file provides an easy way to connect to a wireless network. You will receive the Raspberry Pi Pico's IP address and a corresponding message. If the connection fails, you will get the message "Connection failed" instead.
In the pico_w_server.py file, enter the SSID (remember that the Raspberry Pi Pico W only connects to 2.4GHz SSIDs) and enter your WiFi password. The HTML class allows you to customize what your web server displays in a web browser. You can also leave the refresh field unchecked and set the interval if you don't want the website to refresh every second.
You can also set the port under this file. This is useful when you want to post information on the web outside of your home.
Running your test.py file will import the server python files you need ( mm_wlan and pico_w_server ). After running the test.py file, find the Pi's IP address from any web browser running the same 2.4GHz SSID at home (found in Thonny's output) and add the port you're using (default is 80.) You should see something like this.
Rename the test.py file to main.py and place it on the Raspberry Pi Pico W to reduce the dependency on your connected computer. You might consider connecting the LCD to a pico to use to program the display. Remove the IP address (if you remove the dependency on your connected computer).
Give back the green thumb
With a sophisticated soil sensor and a simple web server, you can now monitor plant health from the comfort of your home via a web browser.
Feel free to change the code as you like. Once you're ready, you'll need to create a location tracker that will add some flair to the simple web server you just created.
Add a pump, transmitter and heat bulb to complete this project and you have a fully automated garden. Now you can keep your "green thumb" forever.
Post a Comment
Post a Comment