Skip to content

Research project on automating an aeroponics box.

License

Notifications You must be signed in to change notification settings

vdrad/TpM-Agro

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

118 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TpM-Agro: IoT and Machine Learning Applied to Vertical Farms

License

Aeroponics Greenhouse

🗒️Table of Contents

🔍️ About

This was an undergraduate research project conducted at the Faculty of Electrical and Computer Engineering (FEEC) of the Universidade Estadual de Campinas - UNICAMP from 09/2023 to 08/2024.

Vertical farms can reduce environmental impact caused by conventional agriculture while also increasing productivity. For example, aeroponics systems can grow plants without soil and use up to 98% less water than traditional methods.

Aeroponics System

However, the need for a controlled environment makes urban farming solutions expensive and limited to specialists. But... what if we could develop a low-cost greenhouse and train a machine learning model to control it as an expert would? That's exactly what this project aimed to do.

🚀 Project Description

A comprehensive functional diagram can be seen below.

Functional Diagram

The process device (a Seeeduino v3.0 board) measures temperature, humidity and light intensity. Those values are assembled on a packet (process data) and sent to the prediction device (a Raspberry Pi 3B). The prediction device uses the process data to generate additional features, such as the rate of change of each variable or elapsed seconds since the process started. Those extra features are called the abstraction data. Process data and abstraction data are then merged to form the system data, which is used to feed three independent Deep Neural Networks (DNNs):

  • A binary-classification model to predict lamp activations
  • A regression model to predict the time interval between nutrition cycles
  • A regression model to predict the duration of a nutrition cycle

These models operate in real-time, generating predictions every second (configurable by the user). Those predictions are stored in a packet (control signal) and sent to the process device, which, according to those signals, controls the grow light and nutrient pump.

The user can interact with the process device by controlling if the system will run manually (i.e, a human specialist controlling the actuators during the learning stage) or automatically (by the DNNs) using physical buttons.

Buttons From left to right: enable pump, turn grow light on/off, and switch from manual to automatic control (blue LED on means automatic control).

It is also possible to interact with the prediction device through a command screen, where you can both set system parameters or visualize the predicted signals. Commands

For five days, the system was controlled by an aeroponics specialist, with data being stored each second. This resulted in more than 226 thousand samples, split into 70% for training, 15% for validation, and 15% for testing the chosen models. All models were trained on a personal computer. After the models were chosen, a tflite version was generated so it could be used on the abstraction device to perform inferences based on new data. All these features are included on a single abstraction.py file.

📂 Folder Structure

Folder names were given based on the Three-Phase Methodology for IoT Project Development.

.
├── L1_Device                           # Process Device
│   ├── ...
│   ├── include                
│   │   ├── pinout.h                    # Pinout definitions for the process device
│   │   ├── utils.h                     # Common-used libraries
│   │   └── ...
│   ├── lib                             # Internal libraries organized by functionality
│   │   ├── light                       # Grow light activation control
│   │   ├── mode                        # Manual/Automatic mode management
│   │   ├── MoT                         # Communication protocol library
│   │   ├── pump                        # Pump control
│   │   ├── WTK_TH                      # Integrated temperature and humidity sensor
│   │   └── ...
│   ├── src                             # Main source code for the device
│   └── ...

├── L3_Border                           # Interface between the process and abstraction device
│   └── border.py                       # Reads and stores process data

├── L4_Storage                          # Stores system data
│   ├── abstraction_data.txt   
│   ├── application_data.txt   
│   ├── bkp_app_data.txt                # Backup of application data
│   ├── commands.txt                    # Commands terminal
│   ├── light_model.keras               # DNN model for light control
│   ├── light_model.tflite              # Same as above, in tflite format
│   ├── pump_activating_model.keras     # DNN model to predict the duration of a nutrition cycle
│   ├── pump_activating_model.tflite    # Same as above, in tflite format
│   ├── pump_waiting_model.keras        # DNN model to predict the interval between nutrition cycles
│   ├── pump_waiting_model.tflite       # Same as above, in tflite format
│   ├── prediction_queue.txt            # New system data to generate control output
│   ├── testing_data.txt                # Data for testing the models
│   ├── training_data.txt               # Data for training the models
│   └── validation_data.txt             # Data for model validation

├── L5_Abstraction                      # Data abstraction and processing logic
│   └── abstraction.py                  # Compute abstraction data, train and run all three models

└── L6_Exibition                        # Data display 
    └── exibition.py                    # Not implemented

✨ Results

The metrics for the three DNNs are as follows:

  • Global accuracy of 98,8% for the light prediction DNN
  • Mean absolute error of 60 seconds (3,36%) for the interval between prediction cycles DNN
  • Mean absolute error of 3 seconds (10%) for the nutrition cycle duration DNN

PW Model Graph Predicted interval between nutrition cycles in minutes versus elapsed time in hours. The black curve is the reference. The green curve is the model output. The orange curve is the grow light state.

While running in automatic control mode, the system prints relevant information to the user.

Rpi output

The system was put in automatic control for five days, resulting in outstanding crop growth.

Crop growth T stands for training stage (manual control). C stands for automatic control stage.

📝 Personal Outcomes

Developing a multidisciplinary project is always challenging but comes with valuable rewards in the end. On this journey, I enhanced my programming skills in Arduino by implementing and debugging communication protocols for IoT device interaction, as well as creating code libraries for the sensors and actuators used in the project. Assembling the electronics and designing basic circuits for the manual control stage added an enjoyable, hands-on component.

My most significant achievements, however, were in Machine Learning. TpM-Agro was my first project involving ML, and I can honestly say it was an incredible experience. Tackling a practical problem turned out to be an engaging and enjoyable way to dive into the field, as it encouraged me to explore various techniques to optimize my models. At first, I thought a single multi-class DNN could handle everything, but as you can see, that wasn’t the case. The goal of achieving satisfactory performance metrics led me to dive deep into different prediction models, feature engineering, overfitting issues, how to run effective diagnostics, balancing bias and variance, and managing the trade-offs between precision and recall. Although I still have much to learn, this challenging journey taught me a lot about ML model design.

There were also unexpected outcomes along the way—like learning the optimal light cycle for lettuce growth, assembling the aeroponics setup, and troubleshooting a nutrient pump that occasionally decided not to work.

Overall, this project was a fantastic experience, and I’m grateful for the learning and growth it brought me.

🖼️ Gallery

Growth comparison Plant growth from T01 (left) to C05 (right)

Microcontrollers Process Device (Seeeduino v3.0) and abstraction device (Raspberry Pi 3B)

Early plants Plants in T01

Sensors Light Sensor (right) and temperature and humidity sensor (left)

⚖️ License

This project is licensed under the Apache License 2.0. You are free to use, modify, and distribute this code, provided that proper attribution is given, and the license terms are included in any distributions.

🤝 Feedback and Contributions

Since TpM-Agro was developed as a 1-year research project, I do not plan to make further improvements to the system or code. However, you’re welcome to explore it, experiment with it, and share any suggestions or improvements!

💬 Contact

vdrad

For questions, suggestions, collaboration opportunities, or any other topic, please feel free to reach out:

About

Research project on automating an aeroponics box.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 69.2%
  • C++ 23.4%
  • C 7.4%