# IoT-Based Cotton Plant Pest Detection and Smart-Response System
## 3 IoT-Based Smart Detection and Response System Architecture
### Algorithm Operations and Analysis  
Our Drone movement prediction algorithm consists of three parts, (See Appendix B at the end of the paper for the algorithm). In the first part, all the devices start their work so that they can instantly synchronize with each other. The reason for separating this portion is that when different wireless devices start their communication, it takes some time, and they send initial bits (beacons) to let each other know that we are ready for further communication. The second part of the algorithm shows the actual operation. The sensors will first send a message to the base about the presence of insects, and then the base station will send a message containing the sensor's coordinates to the drones so that the drones can go there and respond (pesticides) accordingly. For example, if we look at the first case or the first condition of the algorithm, it is an ideal situation that the base receives a message from the sensor in the field about the presence of flying insects and the base immediately dispatches the drone to the cluster from which the message came, and it should be completely sprayed to protect crops from insects. This is the scene we have shown in the simulation in which the drone goes there and sprays after giving the message to the sensors, as shown in both parts of Figure 9.  
Once the drone is finished with spraying, it checks for any other messages from the base station about the presence of pests in any other cluster. If yes, then it will travel straight to that cluster for spraying, and then it will come back to the hanger. In the second case, if the drone has come out of its hanger and only one message comes to the base, and no other message arrives later, the base will call back the drone, and it will return without spraying. In this case, it is more likely that the sensor sent the message for reasons other than the presence of pests. If the base station receives messages from many clusters at the same time, the base station will make the drone a complete path to decide which cluster to spray first and then which other cluster to spray later. So that complete spraying can be completed at the same time, and if more than one drone is needed for this work, they can also be used. In addition, if there are still permanent messages coming from any cluster, the base station will be able to send the drone to the base station. Figure 9: Drones and insects moving to different clusters in Field. will send a camera drone to see why the messages are coming from there. Maybe the sensor is generating messages because of something other than the presence of bugs. Suppose the above three scenarios have to be implemented accurately so that the crop can be protected in any case. Similarly, all possible scenarios will be applied to the crop, and the algorithm will be applied to the framework so that in case of any scenario, the crop will be safe, the quality of the crop will be maintained, and the farmer will be saved. The second part of the algorithm is very important, and even after this part of the algorithm is properly run and implemented. If a problem still exists, then the third part of our algorithm will solve the remaining problems. For example, If a sensor is sending a message despite the drone being sprayed and monitored by a camera, then as a last step, we will send a human helper there to monitor the problem. If there is a problem that can be seen, then they will report to the control room immediately, and immediate action can be taken. We know that pesticide sprays affect both the quality and quantity of the crop, and there is a separate cost to the farmer for a pesticide which reduces its profit. This whole framework is an effort to maintain the quality of the crop as well as save the farmer money and increase profit. We know that this is a distributed artificial intelligence system and its many factors work together. All the sensors and devices working together in the right way is very useful for the framework and provides very good results.