Most house plants require temperature, humidity, and moisture monitoring for optimal care. Temperatures exceeding the optimal range can cause stress, wilting, stunted growth, and even death, while cold temperatures can slow plant development, leading to weak growth and susceptibility to frost damage. Excessive humidity encourages fungal diseases and prevents proper transpiration, while drier air typically causes leaves to dry out and drop, impacting photosynthesis and overall plant health.
Overwatering can also lead to root rot and other diseases. It’s a delicate balance of ideal care, depending on the plant. Although different plants have different needs, general temperature preferences fall between 18° and 23° C, with humidity levels around 40% to 60%. Moisture levels can vary more vastly based on the plant species.
In this project, we’ll build an online plant health monitor using ESP8266, a moisture sensor, and the DHT11 temperature and humidity sensor. The related temperature, humidity, and moisture data will be published on a local website hosted on an ESP8266-based web server. We’ll also design a mobile app using MIT App Inventor, where we can access this data with the click of a button.
- ESP8266 x1
- DHT11 x1
- Moisture sensor x1
- Connecting wires/jumper wires
Here are the steps to build this project for your plants:
- Interface DHT11 and the moisture sensor with ESP8266.
- Connect DHT11’s VCC and GND pins with ESP8266’s 3Vout and ground pins, respectively.
- Connect DHT11’s output pin with ESP8266’s GPIO5 pin.
- Connect the 4.7K resistor between ESP8266’s GPIO5 and 3Vout.
- Connect the moisture sensor’s VCC and GND pins with ESP8266’s 3Vout and ground, respectively.
- Connect the moisture sensor’s analog output with ESP8266’s A0.
How it works
ESP8266 operates as a web server, reading the temperature and humidity from the DHT11 sensor and the moisture from the moisture sensor. ESP8266 then publishes the sensor data to a webpage: /root/read. The root URL is the URL of the WIFI network or router. The sensor data about the plant health parameters can be accessed by browsing the webpage /root/read, where the root is the IP address of the WIFI network.
Any browser that accesses the webpage acts as a web client. The sensor data is always obtained in real-time whenever there’s a request from the web client.
The mobile app also acts as a web client, built using the MIT App Inventor. It can also access the real-time values of the plant’s conditions via a smartphone by making HTTP requests to the ESP8266-based web server. Whenever an HTTP request is made through a web browser or the app, ESP8266 collects the plant’s conditions in real time and publishes them on the web URL. This is accessed by the browser or mobile application.
The MIT app
The MIT App Inventor is used to build a mobile application that can access the plant’s current conditions. The app has the following front-end design.
The app has just one screen, renamed the “Plant Health Monitor.” The app’s user interface has three components: a label, a button, and a web client. The label has the following properties.
The button has these properties:
The app is programmed based on this block diagram:
The sketch begins by importing the DHT.h and ESP8266WiFi.h libraries. The DHT.h library works with the DHT11 sensor, and the ESP8266WiFi.h library runs WIFI functionalities on ESP8266. This is followed by the DHT sensor’s pin assignments and instantiation of a DHT object. Variables are declared to store the WiFi credentials, and an object of the WiFi server is instantiated. The variables to store the moisture sensor’s analog value, moisture percentage, humidity, and temperature are declared.
In the setup() function, the baud rate for serial communication is set to 9600 BPS, and a timeout of two seconds is provided for the DHT sensor. ESP8266 is connected to WiFi, and the web server is started. The DHT sensor is initialized, and a message is printed to the serial console that the sensor is operating.
In the loop() function, ESP8266 reads values from the moisture and DHT11 sensors, storing them as global variables. ESP8266 server “looks” for any potential web clients (a computer browser or a smartphone app). If an HTTP request from a browser or the plant health app is received, the IP address of that web client is printed to the serial console. When the web client is available, a webpage containing the real-time humidity, temperature, and moisture values is sent to it.
When the plant health monitor app accesses the sensor data from the ESP8266 web server, it displays the webpage’s contents in the label of the app’s user interface.
The ESP8266-based web server connects to a WiFi router’s IP address. This address is printed to the serial console when ESP8266 connects to WiFi. However, the status of your IP address can make a difference to the app:
- If your router has a static IP, this address will remain constant, which is ideal.
- If your router has a dynamic IP address (DHCP), it often changes every time the router is reset. This means the ESP8266-based web server will host the webpage on an entirely new IP address.
If the latter occurs, you might need to alter the URL of the web component in the mobile app to access the sensor data.
This is how the project looks:
When ESP8266 is powered ON, it connects to WiFi, initializing the DHT sensor. When a web client, such as a browser or the Plant Health Monitor App, accesses the URL, the ‘/root/read’ sends an HTTP request. The he sensor data is also printed to the serial console.
The messages from the serial console are displayed below.
The plant health data is accessed through the URL ‘/root/read’ on a web browser. Its root is the WiFi network’s IP address, as shown below.
The plant health data accessed on the Plant Health Monitor App is shown below.
It’s possible that your WiFi connection may be slow or that ESP8266-based server takes time to respond. Be patient and watch for the messages printed on the serial console. When a browser or the app requests data from the ESP-based server, it prints the IP address of the connected remote client and the sensor data on the console.
You may also like:
Filed Under: Electronic Projects, ESP8266