Smart Farming: The 3 Elements of an AI Pest Detection System

Rafik Mitry -
Smart Farming: The 3 Elements of an AI Pest-Detection System

Every year, across the globe, farmers lose up to 40% of their crops to pests and disease. On their own, invasive insects inflict at least $70 billion worth of losses. And, as the Earth continues to warm, crop-eating bugs are migrating to entirely new areas, making the problem even worse.

Indiscriminate pesticide use is not the solution. 

“Over-reliance on pesticides impairs the natural balance of the crop ecosystem,” says the Food and Agriculture Organization (FAO) of the United Nations. “It also contributes to a vicious cycle of pest resistance, which can lead to increased pesticide use with little change in crop losses to pests and diseases.” 

The FAO recommends “rational use of pesticides” among other strategies for safe pest management in global agriculture. However, such “rational use” requires increased visibility for targeted, low-impact responses.

In other words, farmers need to know which bugs are eating their crops. They need to know when they visit, and where they are, exactly.

The Internet of Things can help. Here’s a proof-of-concept proposal for an IoT pest-detection system that should be simple enough to build, whether you’re an IoT product developer or a tech-forward farmer. 

The pest-detection system we propose boils down to three key elements. We’ll explore each of them in this article.

Designing an IoT Pest-Detection System for Global Agriculture

The pest-detection system we propose must have at least four capabilities. It must:  

  1. Visually monitor a sample area of the field.
  2. Recognize specific pests, and differentiate them from surrounding images. 
  3. Send sensor data wirelessly, over long distances, to the human user. 
  4. Function in the field for a long time, without using too much power.

To meet all of these goals, we propose the following three-component IoT pest-detection system:  

1. Sensor Nodes

Pest detection starts with devices in the field. Our design for an AI pest-detection device contains two main components: 

  1. A camera module with a microcontroller capable of running TinyML: machine learning at the edge.
  1. A radio module that can run a 2.4 Ghz proprietary protocol, and transfer sensor data to a centralized gateway.

AI pest-detection devices will be deployed in the field; swapping batteries out will be extremely inconvenient (and therefore expensive). That’s why these devices must operate with very low power consumption. 

By using a 2.4 Ghz proprietary protocol for local data transmission, from the device to the gateway, we eliminate the need for multiple SIM cards—and keep power use low by eliminating network scans. 

The other way to program the microcontroller is for limited activity. The user will need to determine how often devices collect images—and therefore use energy waking up, taking a picture, processing the image at the edge, transmitting the data, and finally going back to sleep.   

That might be once an hour, once a week, or anywhere in between. Imagine a spectrum, with reading density on one end and energy conservation on the other. Each user must decide where on that spectrum to locate their sensors. 

So what technology might create such a device? We used the Arduino Nicla Vision for the camera module/microcontroller and the Würth Elektronik Thyone-I radio module for connectivity.

Of course, we still needed a way to transmit data from the field to the cloud. That’s where our next component comes in. 

2. Cellular Gateways

Edge IoT systems in agriculture need to balance low power with wide-area connectivity. The cellular technologies built for massive IoT—LTE-M and NB-IoT—meet these needs. 

For each localized cluster of sensor nodes, this system uses a cellular gateway running on LTE-M and/or NB-IoT. Remember that our sensors send data to this gateway using a 2.4 Ghz proprietary protocol, eliminating the need for individual SIM cards. 

Only one SIM card is needed per gateway, and this handles the transmission of aggregated sensor data to the cloud. 

We connected a Thyone board to an Adrastea-I FeatherWing kit; the Thyone board receives data from the sensors, and the Thyone-I FeatherWing passes it on to the cloud.

But how does the sensor node process image data to identify pests in the first place? It runs machine learning software at the edge, bringing us to the final element of our proposed pest-detection system. 

3. Machine Learning Software

For our system to work properly, we couldn’t rely on the typical cloud-based machine learning. That would use more power and reduce efficiency. 

Instead, we chose edge-based machine learning through TinyML, which can run directly on our camera/microcontroller boards. This approach decentralizes data processing from the cloud to the edge, improving both functional efficiency and security. 

Machine learning is the real strength of this proposal. It allows you to train your models, customizing a detection system for threats specific to a given field. Customized machine-learning models can help save pest-control costs considerably. Here’s one example of how.

Take caterpillars, a common pest in soybean fields. Caterpillars aren’t always a threat, however. They only eat crops during one phase of their lifecycle, consuming ravenously until they reach a certain size, at which point they start preparing for metamorphosis. 

By training your machine learning models on only smaller caterpillars, your system can learn to ignore the larger, harmless stage of the bug’s life. That way you can address only the real threat, reducing pesticide use to improve safety, reduce environmental impacts, and, of course, save money. 

A word of warning about training machine learning models, however: you must create the largest, most comprehensive dataset possible. Look for images that depict your targeted pest from many different angles, in all sorts of lighting conditions. That’s the only way to ensure high accuracy rates.

The good news is that training machine learning models aren’t just for AI laboratories anymore. We used the Edge Impulse platform to train our AI pest-detection models. All you have to do is input the datasets, and Edge Impulse creates the model for you. It’s an affordable, time-efficient way to create powerful machine learning models—like the ones you need to build a highly effective IoT pest-detection system. 

IoT Pest Detection: A Bill of Materials

To sum up, you can build a cellular AI pest-detection system that runs machine learning at the edge yourself. Many components will work perfectly to build something like we just described, but here’s what we used: 

  • Arduino Nicla Vision
  • Würth Elektronik Thyone-I FeatherWing radio modules
  • Adrastea-I FeatherWing boards
  • NB-IoT/LTE-M SIM cards
  • The Edge Impulse platform

Of course, this is just one design proposal for IoT and AI pest detection—and there are many other ways to tackle the same challenge. However, any effective pest-detection system will likely rely on the three main elements of sensor nodes, cellular gateways, and machine learning at the edge.