The ability to grow massive amounts of food in recent times has only been possible with the advent of pesticides, mechanization, and using a lot of water. However, these practices are often unsustainable, thus ruining the environment and depleting valuable resources in the process. This project is meant to tackle water usage, as being able to pinpoint exactly where water is needed along with when can prevent overwatering in areas that don’t need it.
Using a system that relies on machine learning can be far more adaptable compared to one that solely relies on hard thresholds or multiple linear regressions. Additionally, improvements can be made over time as more data is collected. By deploying models at the edge rather than on the cloud, a constant internet connection isn’t required, thus allowing each device to function independently in a decentralized manner.
This project uses an Arduino Edge Control board as its main controller, and it has the following specifications:
All of these features make the Arduino Edge Control extremely capable for smart agriculture applications. This project also makes use of an vv board for sending telemetry to a local server, although it could be stored locally on the Micro SD card for future retrieval too. There’s a DHT22 temperature/ humidity sensor attached to the MKR WiFI 1010 since an LCD screen takes up the other digital pins.
When the Arduino Edge Control first boots up, peripherals such as the LCD, watermark sensor, and MKR slot 2 are initialized. Then within the loop function, both the watermark and battery level values are read repeatedly and then sent to the MKR WiFi 1010 via I2C. Over on the MKR board there’s a handler for the I2C bus that gets called whenever new data is received. Once parsed back into a SensorValue object, this data is combined with readings from the DHT22 and formed into a serialized JSON string which is sent as a POST request to a local server. I wrote this server as a simple Python Flask application that holds a single endpoint called /gardeneEdge and accepts POST requests. After the JSON object is parsed from the incoming string, data is extracted and then stored within a CSV file for later analysis and training.
The Edge Impulse studio features a way to directly upload data from a CSV file, so I opted to go that route. My dataset consisted of 25 total samples that varied between 11 and 13 seconds in length with each one having the following headers:
With the data split almost evenly between needing water and not needing water, I moved onto designing the Impulse. The first block is a simple Time series data block that automatically split the samples into 1-second chunks. Next is the Raw data block that takes each sample’s axes and creates features from them that can be used to train the model. The Keras neural network was trained on these input features from the previous block and outputs the label it thinks corresponds with the current sensor readings- either water or no water.
I was able to achieve an accuracy of 100% in both model training and the separate model validation page. To view and download this model yourself, you can visit its public link here.
Getting the model from Edge Impulse to onboard the device was quite easy due to the ability to export it as an Arduino Library.
Once it was included in the original program, I made a couple of modifications that read in new data from the MKR 1010 WiFi, passed it to the model for inference, and then displayed the result. To further expand this project one might add a solenoid water valve and drive it from the Arduino Edge Control board using one of its solid state relays that can automatically water plants if needed.