Smart Farming has many aspects, and among these is the agricultural side. In this project article, Andrei discusses SmartAgro, a device that combines field autonomy with ease of use, allowing farmers to give their plants a “voice.” It lets horticulturists visualize the temperature, soil humidity, UV radiation and more wherever they are, in real time and take action when it is most needed—whether that means turning on an irrigation system or preparing for cultivation.
Horticulture has been around for millennia. From the time the first seeds were planted to today, our agriculture has faced many changes. Over time, we humans have learned techniques that allowed us to master farming—from selective breeding of plants that our ancestors performed thousands of years ago, to machines invented to sow better and faster easing the workload of farmers. We have progressed way beyond simply planting a seed. And now the time has come for another agricultural revolution.
In a world enhanced by automation and IoT, farming deserves to get an update too. The application of the Internet of Things (IoT) into farming is known as Smart Farming. Smart Farming offers horticulturists the ability to remotely visualize how their plants are doing in real time—basically giving the plants a voice. That means, when the greenhouse needs watering, it is done automatically. Maybe that sounds too good to be true—to be able to sit down and drink tea while the plants water themselves. Well, there is a catch: the cost. Many Smart Farming solutions are on the expensive side. Recently though, as new tools and technologies have emerged, there are now more options are at our disposal allowing us to build applications at a lower cost. This is where SmartAgro comes in.
SmartAgro is a device I created that’s used to monitor multiple parameters on the agricultural field remotely (Figure 1). SmartAgro is an inexpensive solution for small and medium horticulture companies to step into the world of Smart Farming. SmartAgro consists of a device that is placed in the field or greenhouse. It can work autonomously in a network with other devices or as a stand-alone platform collecting data from an array of sensors about the soil, atmosphere and light in the area.
The device then reports the data to a back end through GSM where the data is displayed on a serverless dashboard. The end-user (horticulturist or company) will then be able to visualize the data collected by the device or devices on the field with just one click. For the project, I made use of several tools and services from Soracom, including Soracom Lagoon (Figure 2), Soracom Air, Soracom Beam and Soracom Harvest.
SmartAgro can work in a network with an array of similar devices collecting sensor data from the field. The network can include other devices controlling irrigation. Later, in the “Going Further” section, I will explain how this can be done. This article will mostly be based on building one device.
Now, let’s dive into the way this project works—from collecting the sensor data to illustrating it on the dashboard. I have split this discussion into two sections: the front end and the back end. In our case, the front end refers to the device that is placed in the field collecting sensor data and the back end is comprised of the infrastructure that gets the data from the device to the server and the data visualization. The code for this project is available on Circuit Cellar’s Article Code and Files webpage.
THE FRONT END
I decided to use the Arduino MKR GSM as the microcontroller (MCU) in this project (Figure 3). I personally like the MKR GSM because it has many great features that make it adequate for operation in the field. The device has a reliable sleep mode that turns off all functions except for the RTC (real-time clock). This significantly increases the device’s battery life, which is crucial to operation on the field. The device is also able to retrieve its geolocation coordinates from the GSM network. All in all, a great device for its price—easy to use and simply runs great.
I have attached an Arduino MKR MEM shield to the device. This is done by simply snapping it on top of the MKR GSM. This shield allows you to control an SD card module by just snapping the shield on the device. Most SD card modules require to be powered with 5 V to run. The MKR GSM operates at 3.3 V. This shield enables users to easily operate the module without needing to worry about logic level shifting. An external SD module can be used but that would require stepping up the voltage.
Data is collected from an array of digital and analog sensors attached to the device (Table 1). The major worry would be wear and tear of the soil sensors (soil temperature and humidity). I would personally advise the use of a capacitive soil sensor, which has a far longer life span than the traditional one. For the best precision, ensure that the UV sensor is not covered by any material
After the data is collected from the sensors attached to the device, it is compiled by the device. The data has to be saved to an SD card and sent to the cloud. The MKR GSM prepares two buffers. One of the buffers contains all the sensor data arranged in a line of .csv for example:
atmoTemp, atmoHum, SoilTemp, SoilHum
23, 53, 22, 45
Another buffer is prepared with the data to send to the back end. This buffer is compiled in a JSON buffer and includes other credentials such as the device name (used for identification) and the battery level for example:
The device then burns the buffer formatted to the SD card attached to the shield. I would recommend using a card with 16 GB or less to prevent errors with the shield. I have decided to save the data to the SD card as a backup to the cloud, thereby providing another source with the data other than the dashboard.
The MKR GSM then creates a HTTP client and connects to the Soracom Beam entry point. The device sends the data compiled into the buffer to the cloud. The data is sent through the GSM network and then received by the back end (Table 2).
I powered the device with a Li-Po battery (3.7 V). This seems to keep the device running for weeks on the field. To preserve energy, the device goes into a sleep mode between read cycles and wakes up at set intervals of time to collect data from the sensors. When the device wakes up and takes the samples, it will also read the voltage from the battery and send it to the cloud.
THE BACK END
I have mentioned Soracom a couple times earlier, but now let’s get into more detail. Soracom is a platform built for IoT. It focuses on GSM and SigFox. The platform allows you to buy a SIM with a pay-as-you-go subscription and connect it to the cloud. Soracom (the company) also offers a bunch of great tools for data processing and analyzing. I used three of its services in this project: Soracom Air, Soracom Beam and Soracom Lagoon. I’ll also be touching on Soracom Harvest and Soracom Funnel. The main benefit of using the Soracom platform is its wide variety of services and ease of use.
Soracom Air and Soracom Beam form the entry point for the data you have sent from the device. When the sensor data is sent by our device on the field, it is sent to Soracom’s server by Soracom’s GSM network: Soracom Air. The data is then input into the back end by Soracom Beam. This service then stores the data in a temporary database and allows other services to query it.
The data is then queried by Lagoon from Beam. Lagoon offers a dashboard that can be accessed by the end user (Table 3). The data is queried periodically from Beam and illustrated on maps, graphs and tables (Figure 4). Lagoon also allows the end user to receive notifications via email if data is not within a defined threshold.
PROJECT CONSTRUCTION STEPS
Step 1: Required Materials: I have compiled a list of components needed to construct the project. And Figure 5 shows of a photo of these components. You can find them in online stores. If you have any questions, feel free to contact me. You will also need a soldering iron to connect the components.
• Arduino MKR GSM 1400
• Arduino MKR MEM Shield
• Soracom Air SIM Card
• LiPo Battery (3.7 V)
• GY21 Temperature and Humidity
• SI1145 UV Light Sensor
• Capacitive Soil Moisture Sensor
• DS18B20 Waterproof Temperature Sensor
• Jumper Wires
• SD Card
• GSM Antenna
Step 2: Connecting the Circuit: I would solder the components together, but you can use a breadboard if it fits the enclosure you want to use for the device. A Fritzing “schematic” of the circuit is shown in Figure 6. You should place the MEM shield on top of the MKR GSM and use its pins. The pins on the shield are connected to the equivalent ones on the MKR GSM. Finally, attach your Soracom SIM card and antenna to your device and you are ready to get started.
Step 3: Code: The device that is placed on the field will execute the same code every time it wakes up. Figure 7 is a diagram illustrating the sections of code on the device and the order in which they are executed. Let’s look at each one. Read Sensors – the first step taken by the device after it wakes up. The device collects data from the attached sensors with the use of multiple libraries. Get Location – the device then gets its geolocation coordinates from the GSM network. The data is verified to ensure that the co-ordinates are accurate. Process Data – data is parsed into buffers, one buffer will be saved to the SD card attached while the other is sent to the back end. Save (burn) Data to SD – the device then burns the buffer to the SD card. Send Data – the data is finally sent to the Soracom server through GSM.
There are multiple variables in the code that have to be changed by users to their preference. These variables are described in Table 4. Ensure that you edit these variables before flashing the code.
Step 4: SD Card: As mentioned before, the device will burn the data to an SD card as a backup source. The SD card has to be formatted with MS DOS to allow the MKR GSM to interface it. GoPro provides a great tutorial for doing this on a Mac or Windows. A link to the tutorial is provided is provided at the end of this article.
There are a lot of projects that append data to text files on SD cards. I wanted the data to be easily visualized, so I decided to append the data to a CSV file. The device automatically creates the file on the SD card if there is not one there. If a file is available, the device will append to it.
Step 5: Setting Up Soracom: Now you get to the exciting part: the Soracom platform. You need to go through multiple steps before the back end is up and running. If you do not have an account yet, you can follow a video created by Soracom that will guide you through getting your account ready and registering your SIM. The video is posted at the end of this article.
After you have the SIM registered, you will want to create a new group, which you can then connect to other services. To do this, ensure you are on the main page of your Soracom account and then identify your SIM card from the list and check the checkbox beside it. Then click on the Actions button above the list and select Change Group. Click on the drop-down menu on the pop-up and then select Create and give the group a name. Now click on the menu icon in the top-left of the screen and select Groups from the menu. You should be able to see your group!
Before you move any further, you will need to flash the code to the device and have it run for a few cycles. This is done to populate the back end with data so you can use it when creating our dashboard. Ensure that the circuit is built and all the sensors are wired accordingly. Set the time to sleep to 2 seconds to send the data quickly to the back end.
Next, you have to ensure that the data gets to the back end. To do this, open Soracom Console again and select Groups from the menu. Click on your group on the next window and then navigate to the Soracom Harvest option and click on it. Ensure it is on.
Now you can return to the SIM Management page and check the SIM’s checkbox. Then press on the Actions button and click on Harvest Data. If you have successfully sent data to the back end, you should see the graph and table populated. If no data is visible, try refreshing the page or continue sending data through the device. Feel free to contact me if you cannot get it working.
Please note that you will need to play around with the different options on the page. There is no point in my dictating exactly which graphs to use and where to put them. In this section I will walk you through the graphs I would use and resources that can help you build your dashboard (Figure 8). But first, to open Lagoon click on the Menu icon in the console and select Data Storage and Visualization -> Soracom Lagoon. You will then be asked to create an account. Do so and add yourself as a user. You can choose any of the three plans presented.
Open the Soracom Lagoon console when you are ready. You will be directed to a menu, create a new dashboard. Your data source will automatically be added to the dashboard. To help you with the dashboard, there’s a very useful guide published by Soracom—it’s what got me started. The guide explains how to set up any type of graph and is extremely helpful. A link to the guide is provided at the end of this article. I would include maps, line graphs and tables to visualize the data. The table can be published and personal access can be granted to individuals. Everything you need to know is in the link.
Finally, now that the project is working, it would be time to create an enclosure for the device. To be honest this is my weak point. I personally built mine from a piece of piping and some wood. But I’m sure you can do better than that. Figure 9 shows an image of SmartAgro with the soil sensors are trailing beneath the device into the soil. Just one more quick note: ensure that the UV sensor is not covered by anything so that the data will be precise. Place the soil sensors about 5 cm to 10 cm beneath the soil.
This project can be improved in multiple ways. I personally like the idea of having multiple devices working in a network allowing data collection over a vast area. Soracom provides a service known as Soracom Funnel. This allows you to relay the data received from the device(s) to a third-party database. This would enable you to collect big data from a big number of devices and store it in a database like Amazon’s S3. You can then query the data from the database and display it on a dashboard or a mobile application using Amazon’s services.
For example, you can display data from the devices on a dashboard using AWS (Amazon Web Services) QuickSight which is a service for data visualization. This would allow the end-user to get more reliable information related to the entire agricultural surface. It is also possible to create an automatic irrigation system by having the device on the field send data to Soracom, which relays it onto AWS. The data is then retrieved using a callback by another device that controls the irrigation system and turns the irrigation on if the moisture is low.
RESOURCES and REFERENCES
Tutorial for formatting SD card with MS DOS: https://gopro.com/help/articles/Solutions_Troubleshooting/SD-Card-Reformat-on-a-Mac-Computer
Video for registering a Soracom IoT SIM Card:
Soracom Lagoon guide: https://developers.soracom.io/en/docs/lagoon/
https://developers.soracom.io/en/docs/ – Documentation and Help
https://console.soracom.io/ – Soracom Console
https://www.arduino.cc/en/Guide/MKRGSM1400 – An Intro into the MKR GSM
Libraries Used in Code:
- ArduinoLowPower (c) 2016 Arduino LLC GNU Lesser General Public Licence this library is in the public domain
- MKRGSM (c) 2016 Arduino AG GNU Lesser General Public Licence this library is in the public domain
- Wire (c) 2006 Nicholas Zambetti GNU Lesser General Public Licence this library is in the public domain
- OneWire (c) 2007 Jim Studt GNU General Public Licence this library is in the public domain
- DallasTemperature GNU General Public Licence this library is in the public domain
- RTCZero (c) 2015 Arduino LLC GNU Lesser General Public Licence this library is in the public domain
- SPI (c) 2015 Hristo Gochkov Lesser GNU Lesser General Public Licence this library is in the public domain
- SD (C) 2010 SparkFun Electronics GNU General Public Licence this library is in the public domain
PUBLISHED IN CIRCUIT CELLAR MAGAZINE • OCTOBER 2019 #351 – Get a PDF of the issue