# A Microservice-Based Smart Agriculture System to Detect Animal Intrusion at the Edge
## 6 Evaluation
### Energy Consumption
#### 5.5.1 Our Strategy: Rotating Cameras with PIR Sensors  
In our proposed strategy, we need to measure energy consumption for two components across various scenarios involving different numbers of animal detections (as detailed in Table 9). The components tested are: (1) One Arduino board, one LoRa hat for the communication with the edge server, along with PIR sensors; (2) One single rotating camera and its connected Raspberry Pi. Here, \"number of animal detections\" refers to instances where animals intrude into the field and were detected by the PIR sensors and captured by the cameras. The rotation angle was randomly generated for each image captured by the rotating camera.  
With the data presented in Table 9, we can calculate the power consumed by both components in one day, as illustrated in Table 10.  
Figure 11: Power meter connection.  
\begin{table}
\begin{tabular}{c c} \hline
**Device Name** & **Cost (USD)** \\ \hline Arduino Shield for LoRa & 6.12/each \(\times\) 3 = 18.36 \\ \hline Raspberry Pi 4 & 95 \\ \hline GPS Concentrator & 120 \\ \hline PIR Sensor & 0.75/each \(\times\) 36 = 27 \\ \hline Camera & 25 \\ \hline
**In Total** & **285.36** \\ \hline \end{tabular}
\end{table}
Table 8: System cost.  
Besides determining the power consumption of each component, we also need to calculate the number of components required to monitor the entire field. As depicted in Figure 12, since the detection distance of PIR sensors is 5 m (as illustrated in Table 1), the capture boundary for the camera is also set to be 5 m away from the farm boundary, aligning with the sensing boundary of the PIR sensors to minimize the number of cameras used. We positioned all cameras along the boundary to ensure coverage of the entire area with the fewest number of cameras, leveraging the maximum distance between points \(A\) and \(B\). Since the cameras are rotatable, the angle \(\beta\) can be wider than the field of view as long as the distance between camera and point \(B\) is not greater than 40 m.  
For a field of 1000 by 1000 m, the number of cameras required, \(C_{1}\), is  
\[C_{1}=\frac{1000}{39.686\times 2}\times 4\approx 52 \tag{1}\]  
where 39.686 is the distance between points \(A\) and \(B\), as marked in Figure 12. Here, multiplication by four is done to account for the four sides of the farm field.  
The number of PIR sensors, \(S\), can be calculated using the following equation:  
\[S=\frac{1000}{3.5}\times 4\approx 1143 \tag{2}\]  
where 3.5 is the distance between two adjacent PIR sensors in Layout B. Thus, the number of Arduino boards or LoRa hats needed, \(A\), is  
Figure 12: Placement of cameras.  
\begin{table}
\begin{tabular}{c c c} \hline \hline \multirow{2}{*}{**\#Detections**} & **Arduino Board, LoRa Hat,** & **Camera and** \\  & **and Nine PIR Sensors** & **Raspberry Pi** \\ \hline
0 & 8.64 & 154.839 \\ \hline
1 & 8.64 & 154.844 \\ \hline
3 & 8.641 & 154.862 \\ \hline
5 & 8.641 & 154.867 \\ \hline
10 & 8.643 & 154.882 \\ \hline \hline \end{tabular}
\end{table}
Table 10: Energy consumed (_Wh_) by components in one day (24 h).  
\begin{table}
\begin{tabular}{c c c} \hline \hline \multirow{2}{*}{**\#Detections**} & **Arduino Board, LoRa Hat,** & **Camera and** \\  & **and Nine PIR Sensors** & **Raspberry Pi** \\ \hline
0 & 166 min 40 s & 9 min 18 s \\ \hline
1 & 166 min 40 s & 9 min 15 s \\ \hline
3 & 164 min 23 s & 9 min 5 s \\ \hline
5 & 164 min 23 s & 9 min 2 s \\ \hline
10 & 160 min & 8 min 54 s \\ \hline \hline \end{tabular}
\end{table}
Table 9: Time taken to consume 1 Wh for components.  
\[A=\frac{S}{9}=\frac{1143}{9}=127 \tag{3}\]  
Finally, the total energy consumption (_Wh_) can be calculated roughly with  
\[P_{1}=(((C_{1}-1)\times 154.839+1\times 154.882)+\\ ((A-1)\times 8.64+1\times 8.643)=9148.954 \tag{4}\]