# An IoT-Based System for Efficient Detection of Cotton Pest
## 2 Materials and Methods
### Sensors Design and Deployment  
As shown in Figure 1, the field is shaped like a square of x by y meters. A sensor device was placed in the form of a grid, at a distance of d meters. The farmer, after looking at the population and the growth of insects in the field, decided on the number of devices to be installed in the field. The sink node was placed in a way that all nodes n could easily transfer their data directly to the sink node and the gateway node.  
Since the sensors were not communicating with each other, they conserved their energy by switching to idle mode when they did not have data to send to the sink node. We estimated the amount of energy required during the transmission with the base node. We also perform various calculations to find the required optimal battery configuration for our proposed sensors. For this task, we have kept a low-cost battery that can power a prototype for several days and we can also use solar energy for these prototypes to recharge the batteries.  
Though this prototype is ideal for the targeted operation of a sensitive area that was decided by the farmers themselves, we know that the sensors have a certain range and if an insect comes in that sensing range of the sensor, it will sense it and if more sensors are installed, the sensing range will increase. Therefore, the location of this system can be easily changed in the fields to monitor a specific area.  
The gateway node performed the following tasks:  
* It periodically collected information from the field sensors;
* It could also seek information on demand by a special request;
* Since it was a single-hop communication system, therefore, no routing was required;
* It used XCTU (XBee Configuration and Testing Utility) which was Zigbee communication software;
* It could transfer the aggregated data through a web service remotely;
* It could also send spray messages to drones based on the location of the gateway node sensors.  
For cotton moth monitoring and detection, it was proposed to use an infrared (IR) light wall around the cotton plant to protect it, as shown in Figure 2A. In addition, it was suggested to use a box or channel-based sensor array of IR-emitting diodes. Once a hovering insect or cotton moth tried to cross the light wall, its body and wings' movement somewhat obstructed the light and produced a tiny light deviation that was monitored andcught by the position-sensitive detector (PSD). As shown in Figure 2B, this is the way our prototype works with a straight infrared light constructed vertically or horizontally. When any of the flying insects try to cross the light wall, variation is captured through PSD.  
Later, the Zigbee communication module sends the detection signal to the gateway node. If constant messages were coming from the same sensor, the gateway could send a message to the drone for pesticide spray, and thus insect breeding could be destroyed in time. Figure 2B shows the logical design of the sensor.  
Fundamentally, data obtained by the sensor during experiments consisted of background noise with brief instants during which moths attempted to cross the IR beam. To use this application additionally with houseflies and mosquitos, a controlled and favorable environment was created for hovering flies over the proposed model.