Reader small image

You're reading from  Arduino IoT Cloud for Developers

Product typeBook
Published inNov 2023
PublisherPackt
ISBN-139781837637171
Edition1st Edition
Right arrow
Author (1)
Muhammad Afzal
Muhammad Afzal
author image
Muhammad Afzal

Muhammad Afzal is a senior software engineer, with more than 14 years of experience working on web-based and IoT systems in multinational organizations. He always enjoys working and solving real-world business problems with technology. He provides freelance services to IoT-based product companies to write technical reviews and projects, and he also provides consultancy to organizations. In his free time, Muhammad creates videos and courses for YouTube and Udemy. He also runs a maker movement in his region for young students to boost their interest in adopting the latest technologies.
Read more about Muhammad Afzal

Right arrow

Project 4 – Collecting Data from the Soil and Environment for Smart Farming

This chapter is dedicated to smart agriculture. Our population is growing rapidly and food consumption is directly proportional to population. Fortunately, we have the latest tools and technologies that help us to boost our crop yields by using fewer natural resources. In smart agriculture, there are different parameters to monitor, but we will only focus on soil moisture and soil temperature as both are linked to water consumption; access to clean water is another issue with the rapid growth of industries and population.

In this chapter, we will practically explore smart agriculture by monitoring the soil moisture level, soil temperature, and outdoor temperature and humidity, which will help us to understand how our soil responds to changes in the outside environment and for how many days the soil retains moisture after watering the crop. Our smart agriculture device will send all the data to the...

Technical requirements

The following hardware components are required to complete this chapter:

  • ESP32 development board
  • ADS1115 ADC module
  • DHT22 module
  • Soil moisture sensor x4
  • DS18B20 x4
  • PCB (link is available in the PCB design and the assembly of hardware components section)
  • 2.54 mm three-pin connectors
  • Female headers
  • Jumper cables

For coding, we will use the Arduino Web Editor, which includes a large collection of development board and sensor libraries, and we will use the Arduino IoT Cloud for Thing and dashboard setup. To develop hardware and sensor designs, we need the Fritzing desktop software.

The chapter code is available in the book’s official GitHub repository, or you can directly download the code at https://github.com/PacktPublishing/Arduino-IoT-Cloud-for-Developers.

Smart farming with IoT

Internet of Things (IoT) technology is used in smart agriculture to optimize farm operations, improve crop yields, reduce waste, and increase profits. Here are some examples of how IoT is used in smart agriculture:

  • Automated irrigation: IoT sensors can be used to monitor soil moisture levels and weather conditions to determine when to irrigate crops. Automated irrigation systems can then be triggered to deliver the right amount of water to crops, which can reduce water wastage and increase crop yields.
  • Livestock management: IoT sensors can be used to monitor the health and behavior of livestock, such as their movement, feeding habits, and sleeping patterns. This data can be used to detect early signs of illness, track breeding cycles, and ensure optimal conditions for the livestock.
  • Crop monitoring: IoT sensors can be used to monitor crop growth, detect pests and diseases, and identify areas that need attention. This data can be used to make timely...

Essential hardware for your agri-tech project

In this project, we have chosen open source and easily available hardware components. To demonstrate how the Arduino IoT Cloud works with ESP32 series development boards, we have chosen the following hardware. In the ESP32 series, we have a wide selection of development boards that vary in size and number of pins. In this chapter, we are using ESP32-DevKit V1 as it’s very compact and smaller in size compared to other boards. It is, of course, also cheaper and provides a 5V pin, which is also known as VIN, as well as having the option of a 3.3V pin. The following figure shows the pin layout (pinout) diagram of ESP32 V1.

Figure 9.1: ESP32-DevKit V1

Figure 9.1: ESP32-DevKit V1

ESP32 provides multiple pins for digital and analog input/output. If you want to use multiple analog sensors, then ADCs are available. One of the most well-known ADCs is the ADS1115/ADS1015 module, which provides four analog pins and is good when you need to...

Architecting your agriculture IoT system

In the previous sections, we discussed the sensors and development board in detail. Now it’s time to put things into practice. In hardware development, before starting to work with sensors and development boards, we need to develop the design concepts to get a better understanding of how things will be connected. There are many pieces of software available to design and develop design concepts for electronic projects, but we are going to use Fritzing.

In the following two subsections, we will first talk about the schematics and design of the project and explain how to connect the pins with the development board. Then, we will talk about PCB design and its implementation to make the product ready for deployment in the field.

Schematics and design

The purpose of the design is to get a clear understanding of how sensors will connect with the development board. It helps engineers develop prototypes on a breadboard or Veroboard by...

Perfecting sensor calibration

Sensor calibration is a very important aspect of product development, especially when you have a plan to deploy your product in a real-time environment. So, before moving on, first we need to calibrate the capacitive soil moisture and DS18B20 sensors. The soil moisture sensor operation varies from area to area due to air humidity and water levels.

So firstly, we will calibrate the soil moisture sensor by taking the values of sensors in the air and then putting sensors in the water. These values will be used to bind the final readings and, finally, we will convert the soil moisture sensor value from 0 to 100% via the map method. The soil moisture sensor is an analog sensor, so there is no requirement for an extra helping library, except the ADS module library, which is shown in the following figure with the name Adafruit ADS1X15.

Figure 9.9 – ADS1115 library

Figure 9.9 – ADS1115 library

Here, we need to install a library for ADS1115/ADS1015 in...

Setting up things, networks, and cloud variables

After setting up the hardware, it’s time to set up a thing in the Arduino IoT Cloud. For this project, we need 10 cloud variables to fetch monitoring parameters from the device; the network settings will be different due to the ESP series board. The following figure gives a complete overview of the AgriStack Thing we will set up.

Figure 9.14: Smart agriculture system thing setup

Figure 9.14: Smart agriculture system thing setup

Set up a new thing with the name AgriStack. Follow these steps to create variables, an associated device, network configuration, and, finally, the code. We have marked the preceding figure with different red boxes and assigned numbers. These numbers correspond to the following steps, which will help you to set up the Thing:

  1. Firstly, we need to set up 10 cloud variables, as shown in Figure 9.14. There are two cloud variables for outdoor temperature and humidity; these values will be taken from DHT22. There are four...

Creating web and mobile dashboards

After uploading the code to the device, it’s time to set up a dashboard for web and mobile to visualize the data with different widgets. The following figure shows the visualization of readings with different widgets:

Figure 9.17: Thing dashboard

Figure 9.17: Thing dashboard

We have 10 different readings: Outdoor Temperature, Outdoor Humidity, four Soil Moisture readings, and four Soil Temperature readings. For every reading, we are using the gauge widget control, and advanced charts have been used to compare Soil Moisture and Soil Temperature to visualize the proper correlation between these two attributes. But we also want to monitor historical data; graphs are the best widgets to display live as well as older data. Here, as seen in the lower part of the preceding figure, we have used four graphs, and each graph is connected to a specific cloud variable.

In this section, we have successfully created a dashboard for a smart agriculture...

What next?

We still have a lot of options available to explore, but now it’s your turn to use different sensors and development boards to do some more experiments and learn from them. In this chapter, we used 10 sensors but only 3 different types, that is, moisture, temperature, and outdoor temperature and humidity. However, on the market, there are a lot of sensors that provide a wide variety of functionalities for soil, such as NPK (which stands for nitrogen, phosphorus, and potassium), EC (which stands for electrical conductivity), and pH sensors and different gas sensors for outdoor measurement.

Try the following sensors to enhance your practical knowledge and compare them with other sensors in terms of features, ranges, and cost:

  • NPK sensor
  • Soil EC sensor
  • Soil pH sensor
  • MQ series sensors, which are designed to sense specific gases, including MQ-2, MQ-3, MQ-4, MQ-5, MQ-7, MQ-8, and MQ-9, to find the correlation of gases and their effects on soil and...

Summary

In this chapter, we explored how to develop a smart agriculture monitoring system using DHT22, capacitive soil moisture sensors, a DS18B20 probe for soil temperature, and an ESP32 development board along with the ADS1115 ADC module. We calibrated soil moisture and temperature sensors in the lab before using them in the field. We also set up a thing, which included creating cloud variables, device association, network configuration, and coding of the development board. Then, we created a dashboard to visualize the Thing’s sensor readings with different types of widgets to display current readings as well as historical data with the help of graphs.

This project will help you and give you the confidence to collaborate with agriculture researchers and soil scientists to work on a more advanced level. It will help you to add IoT systems to real fields and tunnel farms, as well as help you in home gardening.

In the next chapter, we will work on a smart home project where...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Arduino IoT Cloud for Developers
Published in: Nov 2023Publisher: PacktISBN-13: 9781837637171
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Muhammad Afzal

Muhammad Afzal is a senior software engineer, with more than 14 years of experience working on web-based and IoT systems in multinational organizations. He always enjoys working and solving real-world business problems with technology. He provides freelance services to IoT-based product companies to write technical reviews and projects, and he also provides consultancy to organizations. In his free time, Muhammad creates videos and courses for YouTube and Udemy. He also runs a maker movement in his region for young students to boost their interest in adopting the latest technologies.
Read more about Muhammad Afzal