# An IoT-Based System for Efficient Detection of Cotton Pest
## 2 Materials and Methods
### Implementation Scenarios  
#### 2.4.1 Scenario 1 Experimental Lab  
Several experiments were carried out with Guava fruit flies, grain moths, and a few cotton moths inside an acrylic box with the prototype at the Agriculture Research Institute's labs, University of Agriculture, Pakistan. Figure 3 shows the experimental setup. Fruit flies and grain moths were monitored by confining the insects in a transparent box that is large enough to allow the moths to fly and be captured by PSD. The system's sensing, computing, and wireless communication capabilities were tested and obtained satisfactory results for further analysis and modifications. The prototype was assembled using a squared plastic box with a Sharp sensor associated with the Arduino AT Mega 2560 board and the Zigbee communication shield. Table 1 shows the technical details  
Figure 3: (**A**). Results received on Zigbee console monitor with some unwanted values. (**B**) Acrylic box for an experiment. of the AT Mega 2560 board. Before using these prototype boxes, a stripe-based sensor array was used on which the sensor was placed at some distance. It was proved by the initial analysis and experimental results that the design and size of the prototype were important features. The duct was replaced with a box and a sensor was mounted on top of the box at a relatively small distance, which made the box more sensitive than duct-based sensor assembly. Two boxes with sensors installed on their horizontal and vertical sides were used. Nevertheless, the result of the vertically installed sensors was much better than the horizontally installed sensors. The sensors used in this study had a range of 4 to 150 cm. This sensor consisted of a signal processing circuit, position-sensitive detector (PSD), and infrared light-emitting diodes. It had a maximum of 7 volts of input and 0.3 volts of analog output. The sensor physical sizes (Type A = 29.5 \(\times\) 13 \(\times\) 13.5 mm and Type B = 29.5 \(\times\) 13 \(\times\) 21.6 mm) were suitable for this application. Figure 4 displays the used sensors. A lithium polymer (LiPo) battery was used to power up the prototype. To increase node lifespan and provide a consistent power source, an ample size battery with the ability to re-charge is sufficient. A lithium polymer (LiPo) rechargeable battery with 22,000 mAh was used in this prototype. It is also possible to use solar energy in the field for this prototype to provide recharging. To analyze, first, measurements from the result of a signal that occurred on the sensor due to any flying insects were obtained. A sketch was used for coding the complete circuit. It was defined in the code that when any of the prototype sensors caught the presence of insects flying in front of it, it must transfer its sensed data (3 volts) to the Arduino board \begin{table}
\begin{tabular}{c c} \hline \hline
**Component** & **Value** \\ \hline Microcontroller & AT Mega2560 \\ \hline Operating voltages & 5 V \\ \hline Input voltages & 7–12 V \\ \hline Digital I/O pins & 54 (of which 14 provide PWM output \\ \hline Analog input pins & 16 \\ \hline DC per I/O pin & 20 mA \\ \hline Flash memory & 256 KB (8 KB used by the boot loader) \\ \hline SRAM/EEPROM & 8 KB/4 KB \\ \hline Clock speed & 16 MHz \\ \hline Length x width & 101.52 mm \(\times\) 53.3 mm \\ \hline Weight & 37 g \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Arduino Mega board technical specifications [30]. Figure 4: Lightweight, low-cost range sensors suitable for small movement detection. Photos courtesy of Sparkfun Electronics [31]. with the help of an analog pin. It was also determined in the code that if any flying insect came across the sensor 1 beam, the remote machine would receive a message \"Bee detected in sensor 1\" with some predefined hexadecimal code. The Arduino AT Mega with Zigbee controller converted analog data to digital data packets and the prototype sent 16-bit data packets for each reading to the remote computer. Figure 5A shows a fully assembled prototype with Zigbee Dongle and a lithium polymer battery.