Agri-Stick

Farmers spend endless hours of driving to their field to check on their crops and manually operate the irrigation systems. This is time and labour intense with significant costs to the farmers and sub-optimal use of expensive resources. By using IoT to deliver unobtrusive easy to use and highly reliable systems for precision monitoring and control of irrigation. So, we are going to make an IoT hardware named “Agri-Stick” which is going to measure the four Agri parameters including Soil Temperature, Soil Moisture, Atmospheric Temperature and Atmospheric Humidity. These values are going to be updated in the AWS cloud through LoRa technology with Raspberry Pi as single channel LoRa gateway. These values can be monitored in real time from both web browser and mobile phone. It enables growers to make decision based on in-field data. Thus, it saves the time and money for farmers and improve yield and crop quality. By extending the sensors in the Agri-Stick and analysing the data with proper methods, we can use it for measuring soil nutrition, pest detection, and crop planning, spraying pesticides, irrigation and harvesting crops. It prevents over and under watering, reduces crop diseases, confirms water delivery as planned, automate tasks that had been done manually, water savings, labour savings and re-allocation to higher value activities.

Supplies:

Step 1: TEMPERATURE SENSOR – DS18B20

We are going to make the hardware like a stick, which is going to be inserted in to the field. Therefore, the temperature sensor measuring the soil temperature should be waterproof and robust enough to corrosion. Temperature sensor (DS1B20) would match all these conditions. It exists in two forms. One is in IC and the other is in probe like structure. We are going to use the DS18B320 probe.

PIN CONNECTION:

DS18B20 Sensor <---> Arduino Nano

VCC - 5V

GND - GND

DATA - D5

Step 2: SOIL MOSITURE SENSOR – CAPACITIVE TYPE

Soil moisture sensors measure the volumetric water content in the soil . As we considered for soil temperature, the soil moisture sensor should also be water proof and corrosion resistant. Capacitive type soil moisture sensor would match all these condition. It is cheap and robust enough to resist corrosion than resistive type.

The sensor consists of a single probe contains separate vcc and ground copper paths covered by solder mask act as flat capacitor. This layer will prevent the direct passing of electric current into the soil.

The sensor measures the soil moisture levels by capacitive sensing, rather than resistive sensing like other types of moisture sensor. Depending upon the water content of the soil, the dielectric of the soil changes. Thus it leads to the changing of the capacitance which is corresponding to the soil moisture content.

PIN CONNECTION:

Capacitive Soil Moisture Sensor <---> Arduino Nano

VCC - 5V

GND - GND

A0 - A1

Step 3: ATMOSPHERIC TEMPERATURE AND HUMIDITY SENSOR – DHT22 (AM2302)

DHT22 output calibrated to digital signal. It utilizes exclusive digital-signal-collecting-technique and humidity sensing technology, assuring its reliability and stability. Its sensing elements is connected with 8-bit single-chip computer. Every sensor of this model is temperature compensated and calibrated in accurate calibration chamber and the calibration-coefficient is saved in type of programme in OTP memory, when the sensor is detecting, it will cite coefficient from memory. Small size & low consumption & long transmission distance(20m) enable DHT22 to be suited in all kinds of harsh application occasions.

PIN CONNECTION:

DHT22 <---> Arduino Nano

VCC - 5V

GND - GND

DATA - D4

Step 4: DEVICE CONNECTIVITY

The core part of Internet of Things is how we are going to connect the things. Communication through radio frequency (RF), light and sound, and Bluetooth allows physical things to communicate with each other without wires, making the IoT a reality.

Since the Agri-stick and the internet, providing part is usually apart from each other in Kilometers range, it should be free of cost for the user. Communication should be bidirectional. In our case, the size of the data to be transmitted is less than 50kb. Since our Agri-Stick is going to be operated in battery, it should consume less power. It should also support encryption and authentication. By considering all these things, among the available technologies, LoRa will be suitable for our case.

Step 5: LoRa WIRELESS RF TECHNOLOGY

LoRa (short for long range) is a spread spectrum modulation technique derived from chirp spread spectrum (CSS) technology. Technically, it is a radio modulation scheme - a way of manipulating a radio wave to encode information using a chirped, multi-symbol format. LoRa also refers to the systems that support the modulation, including LoRa chips and gateways. Sometimes it refers to the LoRa communication network for IoT applications.LoRa, essentially, is a clever way to get very good receiver sensitivity and low bit error rate (BER) from inexpensive chips. That means low-data rate applications can get much longer range using LoRa rather than using other comparably priced radio technologies.

A Semtech innovation, LoRa Technology offers compelling features for IoT applications including long range, low power consumption and secure data transmission. The technology can be utilized by public, private or hybrid networks and provides greater range than cellular networks. LoRa Technology can easily plug into existing infrastructure and enables low-cost battery-operated IoT applications. Semtech builds LoRa Technology into its chipsets, which are incorporated into devices manufactured by a large ecosystem of IoT solution providers, and connected to networks around the globe. Simply stated, LoRa connects devices (or all things) to the Cloud.

Step 6: LoRa GATEWAY

Gateways form the bridge between devices and Cloud Network Services. Devices use low power networks like LoRa link protocol to connect to the Gateway, while the Gateway uses high bandwidth networks like Wi-Fi, Ethernet or Cellular to connect to cloud. All gateways within reach of a device will receive the device’s messages and forward them to the cloud. The network will reduplicate the messages and select the best gateway to forward any messages queued for downlink. A single LoRaWAN gateway can serve thousands of devices. Gateways are routers equipped with a LoRa concentrator, allowing them to receive LoRa packets. LoRaWAN operates on unlicensed bands, so in most countries, running your own gateway is completely legal. However, for our use case, we are going to make our own cost effective gateway using Raspberry pi and a LoRa chip. It uses single channel to transfer information between LoRa chip and Raspberry Pi. i.e. only one Agri stick will be able to communicate with the Raspberry Pi for an instant. This does not comes under the LoRaWAN category. However, it will be easily adaptable to LoRaWAN in future.

Step 7: ROUGH PROTOTYPE

It contain two parts:

Sensor Node

Gateway

Sensor Node:

The rough prototype was made in breadboard. It just senses the agri parameters and displays in the local serial monitor in the PC and sends the data to the single channel LoRa gateway Raspberry Pi through LoRa chip. Arduino UNO was used for prototyping. It got power from the PC itself.

Gateway:

The gateway was also made in breadboard. The LoRa chip was connected to Rpi through jumpers. It got power from the 5V USB adapter.

Step 8: AGRI-STICK’s HARDWARE LAYOUT

The hardware part contains two sections.

Agri-Stick part

Gateway part.

In this, we are going to see how the hardware was designed which was robust enough to tolerate the field’s atmospheric condition.The hardware implementation of the stick consists of various auxiliary units like controller unit, communication unit, power unit and the sensor unit. All these units are connected together and kept in a stick like arrangement made up of PVC pipes.

Step 9: CONTROLLER UNIT

Here, we used ARDUINO NANO microcontroller as the controller. The Arduino Nano is a small, complete, and breadboard-friendly board based on the ATmega328P. The LoRa chip is going to be attached to this microcontroller via SPI interface. In addition, the sensors are going to be attached to this microcontroller through digital and analog pins.

Step 10: COMMUNICATION UNIT

As already discussed, for communication we are going to use LoRa chip. The chip is SX1278, 433 MHz Ai Thinker Ra-02. It uses 433 MHz to communicate to other modules. It communicates with the controller using SPI (Serial Peripheral Interface).

Am living in India. Here, the frequency allocated for LoRa is 868 MHz. But, currently I cant get the 868MHz version. Also, am not using the project for commercial purposes as of now, I used 433 MHz version.

Also, I used the antenna for boosting the RF signals. Without antenna, signals can't be transmitted after a few meters. I have not researched lot about the antenna. Just got it from a local store which is fit for this version board.

Step 11: POWER UNIT

The power unit consists of

single cell Lion battery,

Boost Converter,

TP4056-Lion Single cell charger.

18650 Lion Battery:

It is 2200 mAh battery with nominal output voltage of 3.7V and maximum charge voltage of 4.2V. It should not be discharged below 3.3V.

DC-DC Boost converter:

It is used to convert 3.7V Lion battery voltage to 5V for the microcontroller operations.

TP4056 Lion battery charger:

It is used to charge the Lion cell. It handles the all the constant current and constant voltage part.

A switch was used to switch on/off the power.

The connection was shown in the circuit diagram in the upcoming steps.

Step 12: CIRCUIT IN EAGLE PCB FOR AGRI STICK

It is a self explanatory diagram.

Step 13: PARTS OF THE AGRI-STICK

This is the final prototype of the Agri-Sick. PVC pipes of different sizes, shapes were chosen. The sensors are placed in the stick as shown in the zoomed pictures. All the circuits, sensors, battery and arduino were placed and glued inside the stick. The bottom part was made water proof by properly sealing.

Step 14: INSTALLATION IN FIELD

STEP 1:

A hole of one foot was dug in the land where we want to place the stick with diameter little bit larger than that of the Agri- Stick’s diameter.

STEP 2:

Surface of the soil moisture and temperature sensor were covered with some wet sand that had taken from the same land. Thus, it would make good contact with the underground soil and measure the correct values.

STEP 3:

Insert the Agri-Stick into the hole and cover the remaining volume of the hole with the same sand that had taken from the field.

STEP 4:

The Agri-Stick was powered by switching on and the streaming of sensor values in the cloud were checked.

Step 15: GATEWAY’s HARDWARE LAYOUT

The gateway part consists of Raspberry Pi 3B and SX1278 LoRa chip. The LoRa chip receives the data from the Agri-Stick, sends it to Raspberry Pi through SPI and it sends the info to cloud via internet. Raspberry Pi converts RF packets into IP packets. As we tested, the range for our gateway is about 250 meters with some interference. Without interference, the range may be higher than that.

Step 16: Raspberry Pi 3 B Features:

It contains Broadcom BCM2387 ARM Cortex-A53 Quad Core Processor powered Single Board Computer running at 1.2GHz! With 1GB RAM so you can run bigger and more powerful applications. It contains 40pin extended GPIO to enhance your “real world” projects. It uses 10/100 BaseT Ethernet socket to quickly connect the Raspberry Pi to the Internet

Step 17: CIRCUIT IN EAGLE PCB FOR GATEWAY

It is a self explanatory diagram.

Step 18: PARTS OF THE GATEWAY

Since my main goal is to properly design the Agri-stick and not the gateway, I left the gateway part as it is in the initial breadboard prototype. The another reason is in future we are going to use the commercial LoRa gateways.

Step 19: AMAZON WEB SERVICES - EC2

Amazon Web Services (AWS) is a secure cloud services platform, offering compute power, database storage, content delivery and other functionality to help businesses scale and grow. Explore how millions of customers are currently leveraging AWS cloud products and solutions to build sophisticated applications with increased flexibility, scalability and reliability.

Amazon Elastic Compute Cloud (EC2) provides virtual servers -- called instances -- for compute capacity. The EC2 service offers dozens of instance types with varying capacities and sizes, tailored to specific workload types and applications, such as memory-intensive and accelerated-computing jobs. AWS also provides an Auto Scaling tool to dynamically scale capacity to maintain instance health and performance. Also, it offers one year free tier usage with some limitations.

So by considering all the benefits, I have chosen AWS the for cloud part.

Step 20: EC2 CONFIGURATION

For our purpose, we have used “Ubuntu Server 18.04 LTS (HVM), SSD Volume Type” with t2.micro type instance which contains one virtual CPU and one GB memory. All these configurations are come under one year Amazon’s free tier policy for new users. The instance is configured with security group, which controls the inbound traffic to the server. Our configuration contains SSH protocol for remote access of the instance, HTTP and HTTPS protocols for internet traffic to our instance, and custom TCP protocol for MQTT for our instance. The ports associated with these protocols are 22, 80, 443, and 1884 respectively. Our instance is accessed from a SSH client software like Putty with the key pair. The key pair is used by the putty to connect to the instance. It is like a security option provided by AWS to authorise the user.

Step 21: MESSAGE QUEUING TELEMETRY TRANSPORT (MQTT)

It is a lightweight publish and subscribe system where you can publish and receive messages as a client. MQTT is a simple messaging protocol, designed for constrained devices with low-bandwidth. Therefore, it is the perfect solution for Internet of Things applications. MQTT allows you to send commands to control outputs, read and publish data from sensor nodes and much more. For this, we need a broker and clients as subscriber and publisher. Here our gate way is our publisher, AWS EC2 instance is our subscriber and also it acts a MQTT Broker. Here the publisher (Raspberry pi gateway) publishes the sensor values to a specific topic like “agrstick1”. If we are using multiple gateways, we can publish under different topics. The MQTT broker captures these values under the topic and wait for the subscriber to subscribe for the same topic. If any client subscribes under the same topic, it will then send the values to it. Thus, our subscriber client in EC2 instance will get the values whenever the publisher publishes the message.

Step 22: SQLITE DATABASE

SQLite is a relational database management system contained in a C programming library. In contrast to many other database management systems, SQLite is not a client–server database engine. Rather, it is embedded into the end program. The data that we got from the broker is first stored in the sqlite base for future processing. It uses sqlite3 version. The database file name is “agristick.db” and the table name inside the database is DATASEN as shown in the above figure. It contains six columns for storing the auto increment id, date time, soil temperature, soil moisture, atmospheric temperature and atmospheric humidity.

Step 23: WEBPAGE AND VISUALISATION

For webpage, we used plotly and dash. Dash is a framework for building analytics web apps. Dash is a productive Python framework for building web applications. Written on top of Flask, Plotly.js, and React.js, Dash is ideal for building data visualization apps with highly custom user interfaces in pure Python. Through a couple of simple patterns, Dash abstracts away all of the technologies and protocols that are required to build an interactive web-based application. Dash apps are rendered in the web browser. You can deploy your apps to servers and then share them through URLs. Since Dash apps are viewed in the web browser, Dash is inherently cross-platform and mobile ready.

The above image is the webpage that I have created. Whenever the Agri-Stick publishes a new valu, the webpage get updated. Since I have not used DNS for the website, I simply used the IP address of the server to access the page. For security reasons, I hid the IP address.

Step 24: DATA FLOW

The flow of data from the Agri-Stick to web page was illustrated in the figure.

Through RF(LoRa) from Agri-Stick to Raspberry Pi gateway.

Through internet from gateway to AWS EC2 instance using MQTT protocol.

Codes for all modules are in the github page:

Step 26: OBSERVATION FROM THE GRAPH

These graphs were created using Microsoft Excel for observation purposes.

The above graphs were plotted between time in X-axis and Soil Temperature, Soil Moisture, Atmospheric Temperature and Atmospheric Humidity in Y-axis of corresponding graphs. The time for recording the values were from 6:44 PM to 10:42 PM on 01-April-2019 and from 9:48 AM to 2:45 PM on 02-April-2019.

The soil temperature in night time is higher than that of in the daytime.

Soil moisture depends upon the irrigation pattern.

Atmospheric temperature of night time is lesser than that of the day time.

Atmospheric humidity of night time is higher than that of the day time.

Step 27: CONCLUSION

As of now, the device is capable of sensing limited parameters only. In future, it should be equipped with many sensors like NPK, Co2, O2, pH, etc to increase the features of the stick.

Now it is powered with battery which should be recharged. It is a hassle thing to the farmer. In future, it should be solar powered.

As of now we used Raspberry pi as a single channel gateway to receive LoRa packets. Since the LoRa technology is popular now a days, in future, there is more possibility for the installation of LoRa gateway towers in our country. So, it becomes easier to send the sensor data to cloud from anywhere in the field.

As of now, the values are just monitored in the cloud. In future, it is used to automate the farming, to take intelligent decisions about pest attack, sowing period and harvesting period using machine learning and AI.

A farmer friendly mobile app could be done.

It could be converted into commercial product with the above-mentioned suggestions.

The Agri-Stick was prototyped with minimum cost and robust features. It is capable of sending the sensor data to cloud where we can analyse, process and use it for the betterment of agriculture. It is a plug and play device where you can stream the sensor data in webpage once you placed it on the field and connect it to the internet. This project helps farmers to improve their agricultural practices with the help of technology. For all these, we need to invest once for the Agri-Stick and depends on the usage we need to pay for the cloud services. By automating the manual processes and introducing this kind of devices may attract many people to change into farming career. This will change the current situation of agriculture.

“I believe in the future of agriculture, with a faith born not of words but of deeds.”

Message to the readers:

Any suggestions to improve the project are welcomed. Some of the steps were skipped during writing the instructables. So If you have any doubts feel free to ask.

IoT Challenge

Party Challenge

Gardening Contest

8 Discussions

Excellent write up! I was in the middle of doing a similar system, but shorter range and using MySensors as the comm framework. However, pushing data to AWS is possible no matter what hardware you opt for. My question is - do you have an idea of the AWS costs you might incur for this setup, with say, 5 sensors? I know they have a free (time limited) option but mine has run out.. Also, do you have links/guidance on how to process this data and apply it to your agricultural effort?