Introduction
A university popularly known as "Campus" is an important environment for providing education which is the key to transforming a community and changing a nation. For that reason, there is a need to ensure that campus environment is favorable, conducive, and provides motivation to learners who are on a mission to gain knowledge and skills that will be applied to solving challenges in the society. Such environment should have fresh air for breathing, clean environment, easy access to different resources especially for the disabled group, sufficient agricultural produce and supply, easy campus navigation, and easy access to health care system. All this is meant to ensure students don't waste time but they can concentrate on studies and seeking knowledge.
Food production is an important section that ensures the community remain energetic and healthy while carrying out their daily duties. Our institution is focused on ensuring food is available to the community. However, most of the production is done on a small scale despite our institution owning large acres of land.
For this reason, we decided to utilize our knowledge and the current Internet of Things technology and Artificial Intelligence to develop a Smart School Farm system that provide insights about weather conditions of the area, perform weather forecasting using machine learning, enable remote monitoring of farm parameters such as soil moisture content, air quality index, temperature, moisture, and light intensity to the form managers and workers. We also enabled automated irrigation when irrigation system is controlled by smart solenoid valve to reduce manual labour. Finally, we designed Arduino IoT Cloud for data display and phone app for automatic relay control.
Smart School Farm improve the life of students in campus by:
- Sustainability: Fresh and a conducive environment is vital in campus, our project monitors Air Quality Index and provides the results to students and staff. This enables action to be taken whenever air quality is low to ensure institution fraternity breath fresh air, plants and animals survive.
Secondly, we are monitoring weather patterns using our customized weather station model and perform forecasting using machine learning. This insights enable farm managers are able to plan while they are aware of the expected weather patterns. The system eases campus operation since there will less negative impact due to changes in weather patterns.
- Student Engagement: Students are able to know the expected weather patterns (i.e. whether it will rain or not) hence they are able to carry the right attires or plan wisely for the day. Therefore, campus students will not miss classes or attending to their daily duties due to impromptu changes in weather patterns. Therefore time is well utilized to ensure continues learning in campus.
Project Objectives
- Develop an IoT based system that enable monitoring of school farm parameters such as moisture amount, sunlight intensity, soil moisture content, and quality of air.
- Enable automation in the irrigation system using smart solenoid valve through the use of Capacitive Soil Moisture Sensor.
- Enable remote monitoring of farm parameters through an Arduino cloud dashboard and phone app.
- Developing a machine learning model trained on collected data from sensors to predict the patterns of rain through weather forecasting.
- Develop a smart weather station system to provide weather information to the farm managers to enable proper and timely planning.
- Enable automatic quality control of the pump.
Project Idea
- University Farm
Our university has more than 648 acres of land that harbors coffee plantations, dairy farming and vegetable production. The images below show just a few of what the university produces to feed the university fraternity and the community around at large. This agricultural section is run by Dedan Kimathi University Farm Enterprise. (https://www.facebook.com/DeKUTKenyaFarm/?paipv=0&eav=AfYTCCY-p-FbzRgkM9r5PNrroDSTLHG50GyopHYtNDfXhR6czcA8hiCU86g5IkUQK8&_rdr).
- Institution Video
The video shows different agricultural activities that are being carried out in the institution. We have coffee farming, onion farming, kales, dairy farming, pig farming, goat and sheep farming and many more. This opportunity opens up the world of technology utilization to advance farming in the institution. The use of technology such as Internet of Things, and Artificial Intelligence will enable increased production to enable the institution harvest produce that will sustain it's fraternity.
The agricultural opportunity practiced in the institution opens for the use of Internet of Things to support such farming activities. Our project taps into this opportunity by developing a smart IoT system that enable automated irrigation, remote monitoring of farm parameters through Arduino IoT Cloud. The project provides access of real time data from the farm through the use a smart phone. Farm supervisors are able to understand what is happening in the farm without having to travel to physically to the farm.
Secondly, our project provides a real time model that help farm coordinators to predict rain patterns. This is vital in ensuring water harvesting resources are well put in place and irrigation systems are well maintained to ensure crops remain irrigated.
- Problem statement
From the survey, we discovered that almost three quarters of farming is done using traditional and manual practices. Our farm does not farm automatic system of monitoring conditions of the land such as soil moisture, soil pH, light intensity, weeds, monitoring animal health so as to ensure such parameters are monitored and controlled automatically. There are no automatic irrigation systems that are driven using sensors without the involvement of human labor. Monitoring of animal health is done through manual observation of the animal behaviour to detect if it has contracted a disease or it is unwell.
These challenges are hindering maximum utilization of the land to ensure high productivity. In the current world driven by industry 4.0 technology advancements and bearing mind this is an institution with young visionary individuals, such systems are very vital to ensure increased productivity to have enough food to feed every person to ensure a healthy nation.
- Solution
Internet of Things is the advancing technology and appropriate technology to revolutionize our agricultural production. The use of sensor nodes for perception, microcontrollers for data processing, Arduino cloud for remote real time monitoring is a vital system that will enable automation of the agricultural system. The use of actuation system will enable automatic control of irrigation system in the farm hence reducing human labour and increasing production. The system operates in a closed loop control format where whenever thresholds are not met, commands are sent to the relay to activate the relay and enable automation.
Project Build
- Flowchart
- Working
We unpacked the hardware kit from DFRobot. We then unpacked the hardware kit from DFRobot.
First we tested each and every sensor
A. Connecting Fermion Multifunctional Environmental Sensor
- Locate the I2C pins on the Gravity: IO Shield. The I2C pins are labeled as SDA and SCL.
- Locate the I2C pins on the Gravity: IO Shield. The I2C pins are labeled as SDA and SCL.Connect the Fermion sensor to the Gravity: IO Shield using jumper wires. Use the following connections:
- Connect the SDA pin of the Fermion sensor to the SDA pin on the Gravity: IO Shield.
- Connect the SCL pin of the Fermion sensor to the SCL pin on the Gravity: IO Shield.
- Connect the GND (ground) pin of the Fermion sensor to the GND pin on the Gravity: IO Shield.Connect the VCC (power) pin of the Fermion sensor to the 3.3V or 5V pin on the Gravity: IO Shield, depending on the power requirements of the sensor.
- Locate the analog input pins on the Gravity: IO Shield. These pins are labeled A0, A1, A2....
- Connect the Gravity: Analog Waterproof Capacitive Soil Moisture Sensor to the Gravity: IO Shield using jumper wires. Make the following connections:
- Connect the VCC (power) pin of the sensor to the 3.3V or 5V pin on the Gravity: IO Shield, depending on the power requirements of the sensor.
- Connect the GND (ground) pin of the sensor to the GND pin on the Gravity: IO Shield.
- Connect the SIG (signal) pin of the sensor to one of the analog input pins like A0 on the Gravity: IO Shield.
Locate the I2C pins on the Gravity: IO Shield. The I2C pins are labeled as SDA and SCL.
- Connect the Gravity: SGP40 Air Quality Sensor to the Gravity: IO Shield using jumper wires. Make the following connections:
Connect the SDA pin of the SGP40 sensor to the SDA pin on the Gravity: IO Shield.
- Connect the SCL pin of the SGP40 sensor to the SCL pin on the Gravity: IO Shield.
- Connect the GND (ground) pin of the SGP40 sensor to the GND pin on the Gravity: IO Shield.
- Connect the VCC (power) pin of the SGP40 sensor to the 3.3V or 5V pin on the Gravity: IO Shield, depending on the power requirements of the sensor.
To connect the Gravity: Digital 5A Relay Module to the FireBeetle 2 ESP32-E IoT Microcontroller using the Gravity: IO Shield for FireBeetle 2 (ESP32-E/M0), you can follow these steps:
- Gather the necessary components: Gravity: Digital 5A Relay Module, FireBeetle 2 ESP32-E IoT Microcontroller, and Gravity: IO Shield for FireBeetle 2.Connect the Gravity: IO Shield to the FireBeetle 2 ESP32-E Microcontroller. Align the pins of the shield with the header on the ESP32-E and gently press them together until they are firmly connected.
- Locate the digital output pins on the Gravity: IO Shield. These pins are labeled D0, D1, D2, etc.
- Connect the Gravity: Digital 5A Relay Module to the Gravity: IO Shield using jumper wires. Make the following connections:
- Connect the VCC (power) pin of the Relay Module to the VCC pin on the Gravity: IO Shield.
- Connect the GND (ground) pin of the Relay Module to the GND pin on the Gravity: IO Shield.
- Connect the IN (control) pin of the Relay Module to one of the digital output pins (e.g., D0) on the Gravity: IO Shield.
- IoT system results
We assembled the system to have the functional device that is able to collect data from the school farm as shown.
The aim of our system is to monitor parameters of school farm remotely, enable automation in irrigation system to reduce labour and water wastage. Sensor read data which is displayed on on the app and Arduino IoT cloud. We recycled the cover which we used to house the sensors and other components. This was vital to conserve our university environment.
- Data Display
Once the sensors read the data values, we displayed them on Arduino IoT Cloud and phone web app to enable remote access as shown in the video. The images below shows the data display.
Arduino IoT Cloud provides an online platform that enable easy online access of a platform that support Internet of Things. We utilized this platform as a to showcase our results from the sensors.
Phone app enables easy and a convenient remote access of the data. We also utilized the Arduino IoT Cloud features to enable remote monitoring of the irrigation system. The interface above shows how the data can be viewed remotely by farm managers using there phone.
The video demonstrates the working of the system when deployed in the farm. We are able to control the irrigation system both manually and automatically using Gravity relay from DFRobot. The relay helps in changing the logic to switch the solenoid valve on or off depending on the amount of water in the soil.
- Tensorflow Lite model results
The provided code is used to create a weather model, save it as a Keras model, convert it to a Tensorflow Lite model, and generate a C++ header file for deployment on a FireBeetle 2 ESP32-E microcontroller using the Arduino framework.
## Data Preparation and Model Training
The code begins by importing the necessary libraries, including `pandas`, `sklearn`, and `tensorflow.keras`. It then reads a weather dataset from a CSV file using `pd.read_csv` and displays the first few rows of the dataset.
Next, the code prepares the data for training by separating the features and the target variable. It selects the columns 'humidity', 'pressure', and 'tempC' as the features (`X`) and 'precipMM' as the target variable (`y`). The first few rows of the feature data (`X`) and the target variable (`y`) are displayed.
To train the model, the code uses the `train_test_split` function from `sklearn.model_selection` to split the data into training and testing sets. The training set is used to train the model, while the testing set is used to evaluate its performance. The split is performed with a test size of 0.2 and without shuffling the data.
To ensure that the feature data is scaled properly, the code utilizes `StandardScaler` from `sklearn.preprocessing` to scale the feature data. The scaling is applied separately to the training and testing sets.
A sequential model is then created using `Sequential` from `tensorflow.keras.models`. It consists of dense layers with ReLU activation and dropout layers for regularization. The model is compiled with the Adam optimizer, binary cross-entropy loss, and accuracy as the evaluation metric. A summary of the model architecture is displayed.
The model is trained using the training data (`X_train_scaled` and `y_train`) for a specified number of epochs and a batch size of 32. After training, the model's performance is evaluated on the testing data (`X_test_scaled` and `y_test`), and the loss and accuracy are calculated.
The trained model is saved as `my_model.h5` using the `save_model` function from `tensorflow.keras.models`.
## Conversion to TensorFlow Lite and C++ Header File Generation
To convert the saved Keras model (`my_model.h5`) to a TensorFlow Lite model, the code imports `tensorflow` and loads the saved model using `load_model` from `tensorflow.keras.models`. The `TFLiteConverter` is then used to create a converter from the Keras model.
The converter converts the Keras model to a TensorFlow Lite model, which is stored in the `tflite_model` variable.
Next, the code creates a C++ header file for deployment on the FireBeetle 2 ESP32-E microcontroller using the Arduino framework. It installs the `xxd` tool using `apt-get` and imports the necessary libraries. The shell commands are executed to generate a C++ header file (`u_model.h`) that contains an array of the model's parameters in hexadecimal format.
The generated C++ header file (`u_model.h`) is automatically downloaded using `files.download`.
## Deployment on FireBeetle 2 ESP32-E with Arduino Framework
To deploy the weather model on a FireBeetle 2 ESP32-E microcontroller using the Arduino framework, follow these steps:
1. Set up the Arduino development environment for the ESP32 board.
2. Create a new Arduino sketch and include the generated `u_model.h` header file.
3. Initialize the TensorFlowLite library and load the model using the `tflite::MicroModelWrapper` class.
4. Prepare input data for inference based on the model's input requirements.
5. Perform inference using the Tensorflow Lite model on the input data.
6. Process the output of the model and use it according to your application's requirements.
By incorporating the generated C++ header file and the TensorFlowLite library into your Arduino sketch for the FireBeetle 2 ESP32-E, you can deploy the weather model for real-time inference on the microcontroller.
This code provides an example of how to create a weather model, save it as a Keras model, convert it to a TensorFlow Lite model, generate a C++ header file, and deploy it on a FireBeetle 2 ESP32-E microcontroller using the Arduino framework.
Challenges- We phased a challenge incorporating FireBeetle Microcontroller to edge impulse since the hardware is not support. We therefore opted to use TensorFlow Lite.
- We could not carryout all the monitoring actions because we did not have all the required components. We opted to customize some models to build our system.
- Some libraries of the microcontroller are not available hence we were forced to customize the existing libraries to fit the FireBeetle ESP32 Microcontroller specifications.
The system above is our first version, we intended to add more sensors enable 100% monitoring of the school farm and utilization of IoT technology.
- Incorporate AI camera to the system to monitor pests and diseases on the crops and have trained AI model that performs prediction,
- Build a mechatronic robot that will enable automatic harvesting of the produce such as coffee and mobile robot for irrigation for crops such as onions.
- Expand the system to larger sections of the farm and be able to cover different crops and even livestock.
- Expand our weather forecasting and weather station to serve the whole university fraternity.
- Redevelop and improve the selling shop of the institution by installing well conditioned and IoT powered selling facilities that will ensure the produce remains in good condition after harvest.
Comments