DEV Community

Cover image for Plant Water Management System w/ BME280
James Priest
James Priest

Posted on

Plant Water Management System w/ BME280

Track the total volume of water spent and evaluate approx. evaporation rates by temperature, humidity, and pressure to prevent water overuse and Root rot.

This project intended to design a small-scale, smart irrigation system through an Arduino. A major consideration was soughing to have the fully automated system powered through an external power source & a focus on a minuscule yet cumulative problem causing water overuse.
The focus was on the concept of automation, operation and monitoring through a programmed operating environment that evaluates the approximate evaporation rates by using temperature, humidity, barometric pressure, and lets the user observe soil moisture and altitude.

To obtain temperature, humidity, barometric pressure, and approximate altitude, I used an Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor. Below, you can inspect the formulas I implemented to calculate the approximate evaporation rates by temperature and humidity.
To detect the water flow rate and the total water spent, I used a YF-S201 Hall Effect Water Flow Sensor. And, to observe the soil moisture, I used a Soil Moisture Sensor.

Although it only caters towards a limited number of plants, there is room for expansion and future experimentation, to answer the question of how to decrease manual watering/labor. ** not entirely my work, references are linked.

Using the Adafruit BME280 Temperature Humidity Pressure Sensor with Arduino

It's easy to use the Adafruit BME280 sensor with Arduino in its two different modes - I2C and SPI. However, in this project, I used the I2C connections, so the PCB (Plant Water Management System) does not include the switch-back option between I2C and SPI.

To begin reading sensor data, you will need to install the Adafruit_BME280 library (code on Adafruit github repository). Available from the Arduino library manager.

From the Arduino IDE, open up the library manager.
And type " adafruit bme280" to locate the library, then click Install.
Also, add the Adafruit Unified Sensor library.
Open up File->Examples->Adafruit_BME280->bmp280test to test the sensor's features.

Calculating the discharged volume of water w/ YF-S201 Hall Effect Water Flow Sensor

YF-S201 Hall Effect Water Flow Sensor has an embedded hall effect sensor, and it produces pulses each turn with flow. The signal generated by the sensor is a square wave, so we can easily convert the pulse to the flow rate with:

Pulse frequency (Hz) / 7.5 = flow rate (L/min)

This formula is derived from the equation below and needs calibration when executing. In my case, I did not encounter more than a discrepancy of 0.15 L.

Q (flow rate) = V (velocity) x A (area)

To pull the discharged volume by seconds, we need to divide the flow rate by 60.

water_spent = flow rate (L/min) / 60

Then, collecting the water_spent variable recursively, we can reach the total volume of water spent:

total_water_spent += water_spent

Below, you can inspect how I code these formulas in Arduino.

Evaluating approximate evaporation rates by temperature, humidity, and pressure

Of course given my attention to detail the generated variables I used are neither one hundred percent accurate nor the results of my distinct lack of math phd & complex mathematics for the dynamics of water evaporation but indicators for empirical evaporation rates.

I used variables from the Adafruit BME280 Temperature Humidity Pressure Sensor to obtain - evaporation rates - with the following formulas.

By Temperature w/ Humidity and Pressure

First, I used the ideal gas law to detect the number, per cubic meter - n / V - since we can get pressure and temperature variables for the air.

**PV = nRT

n / V = P / RT**

P => pressure (Pa)

T => temperature (K)

R => the ideal gas constant

With this, we can calculate the density of water vapor by using the molecular mass of water (18.015 g/mol).

vapor density = (n / V) x 18.015

Then, we can evaluate the saturation of the air by using the percent relative humidity and the density of water vapor we just calculated.

percent relative humidity = (vapor density / saturation vapor density) x 100

saturation vapor density = (vapor density / percent relative humidity) x 100

Lastly, we need to subtract the density of water vapor from the saturation of the air to find the approximate evaporation rate - g/m3.

The ol' "approximate" evaporation rate = saturation - density

Next to convert the evaporation rate from g/m3 to kg/m3:

"approximate" evaporation rate = (saturation - density) / 1000

Evaporation of water from a surface depends on water temperature, air temperature, air humidity, and air velocity above the water surface. I used the following formula to calculate the amount of evaporated water "approximately" by humidity.

gh = Θ A (xs - x)

gh => amount of evaporated water per hour (kg/h)

Θ => (25 + 19v) => evaporation coefficient (kg/m2h)

v => velocity of air above the water surface (m/s)

A => surface area (m2)

xs => maximum humidity ratio of saturated air by temperature (kg/kg)

x => approximate humidity ratio air (kg/kg)

Since we need to find answers to empirical questions, I used the average variables for sensor readings where any given houseplant is. So, these will change these depending on your readings. I cant help but note my readings were not empirically accurate, i thought given the lack of empirical evinidens for empirical evidence, that i would be safe.

v = 0.30

A = 0.25 x 0.25 (surface area of my one given pot)

xs = 0.019826 (for 25 °C)

Getting the humidity ratio air (kg/kg) from the percent relative humidity "approximately", multiply the volume (near to the percent relative humidity) by the ratio of the weights of (water and air) - 0.62198.

humidity ratio air (x) = (percent relative humidity / 100) x 0.62198

Programming Arduino Nano

Required libraries to be able to control the modules:

Nokia 5110 Screen | Library

Adafruit BME280 | Library

  1. Include the required libraries.Define the Nokia 5110 screen settings.

  2. Define the graphics for related screen modes - tem, hum, and usage.
    To create different graphics (monochrome images), go to Monochrome Image Converter.

  3. Define the Adafruit BME280 Temperature Humidity Pressure Sensor settings - I2C.

  4. Define menu options and modes using volatile booleans - A. Tem. Eva., B. Hum. Eva., C. Moisture, and D. Usage.

  5. Define the control buttons and LED pins.

  6. Define the YF-S201 Hall Effect Water Flow Sensor settings.

  7. Initiate the Nokia 5110 Screen and the Adafruit BME280 Temperature Humidity Pressure Sensor.

  8. In the read_buttons() function, read the control buttons.

  9. In the change_menu_options() function, increase or decrease the option number using the Right and Left buttons.

  10. In the interface() function, print the interface (menu).

  11. If the Tem. Eva. mode is selected, obtain the current temperature, and evaluate the approximate evaporation rate by temperature.

  12. In the calculate_approx_evaporation("tem") function, calculate the approximate evaporation rate by using temperature, humidity, and pressure variables generated by the Adafruit BME280 sensor.

  13. Define the threshold (1.50) to activate control LEDs - Green and Red.

  14. If the Hum. Eva. mode is selected, obtain the current humidity, and evaluate the approximate evaporation rate by humidity.

  15. In the calculate_approx_evaporation("hum") function, calculate the approximate evaporation rate by using the humidity variable generated by the Adafruit BME280 sensor.

  16. In the calculate_approx_evaporation("hum") function, calculate the approximate evaporation rate by using the humidity variable generated by the Adafruit BME280 sensor.

  17. Define the threshold (1.30) to activate control LEDs - Green and Red.

  18. If the Moisture mode is selected, print the variables - moisture (%), barometric pressure (hPa), and approximate altitude (m) - generated by the soil moisture sensor and the Adafruit BME280 sensor.

  19. Define the threshold (35) to activate control LEDs - Green and Red.

  20. If the Usage mode is selected, print the flow rate by seconds (water_spent) and the total water usage (total_water_spent).
    In the read_water_flow_sensor() function, calculate the flow rate by detecting the pulse time with the pulseIn() function to extrapolate the frequency by dividing 1000000 (1 second into microseconds) with the pulse time. Then, by using the flow rate, calculate the total volume of water spent.

  21. Define the threshold (100.0) to activate control LEDs - Green and Red.

Top comments (0)