# Low-Cost IoT and LoRaWAN-Based System for Laying Hen Identification in Family Poultry Farms
## 3 System Design and Implementation
### OT Layer  
The OT layer comprises the nodes (nesting box node and environment node) and the communication gateway. Each nesting box node is equipped with the following components (see Figure 2):  
* ESP32 Heltec WiFi LoRa v2 controller (with SX1276) for LoRaWAN communication;
* RC522 RFID reader for hen identification;
* 3.7V 1200 mAh LiPo battery with power consumption optimization (battery connected to the red + and black \(-\) wires in Figure 2). The environment node is integrated with the following components (see Figure 3):  
* DHT11 sensor for measuring temperature and humidity in the chicken loop;
* Arduino Pro Mini 328 microcontroller optimized for low power consumption;
* LoRa RFM95W module for transmitting environmental data;
* Powered by two standard AAA alkaline batteries connected in series (battery connected to the red + and black \(-\) wires in Figure 3). To protect the components from potential exposure to dust, humidity, and temperature fluctuations inside the chicken loop, all sensor nodes were enclosed in sealed protective casings (see Figure 2). This design choice ensured environmental resistance during field testing, contributing to the reliability and durability of the system in rural farm conditions. Regarding power supply, the two nodes use different types of batteries depending on their energy demands. The nesting box node, which requires wireless communication and frequent readings, is powered by a rechargeable 3.7 V LiPo battery. In contrast, the environment node uses standard AAA alkaline batteries, which are sufficient given the lower energy demands of its periodic temperature and humidity readings. LoRaWAN was chosen for both nodes not only for its long-range capabilities but also for its low energy consumption. \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Layer** & **Level** & **Function** & **Item** \\ \hline \multirow{4}{*}{**OT**} & \multirow{2}{*}{1} & \multirow{2}{*}{Controllers} & \multicolumn{2}{c}{Heltec ESP32 WiFi Lora v2,} \\  & & & & \\  & & & & \\  & & & & \\ \cline{3-4}  & & & & \\ \cline{3-4}  & & & & \\ \cline{3-4}  & & & & \\ \cline{3-4}  & & & & \\ \cline{3-4}  & & & & \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Selected software and hardware technologies. Although formal battery life testing was not conducted, preliminary calculations and field experience suggest that the nesting box node can operate for approximately  
Figure 3: Environment node components (**bottom** image) and its connection diagram (**top** image). Figure 2: Nesting box node components (**bottom-left** image). Nesting box node (**bottom-right** image) and its connection diagram (**top** image). 2 weeks between charges, while the environment node may achieve even longer durations. Furthermore, since farmers visit the coop regularly to collect eggs, battery replacement or recharging can be integrated into their normal routine. The system's modular design also allows for the integration of higher-capacity batteries. The selection of LoRaWAN as the communication protocol was driven by its suitability for agricultural environments. As previously discussed in Section 2, LoRaWAN offers long-range coverage, low power consumption, and robust performance in the presence of moderately obstructed scenarios. In our deployment, the communication range of LoRaWAN significantly exceeded the dimensions of the farm. The nodes and the gateway were strategically positioned to ensure optimal signal reception, and their placement remained fixed throughout the trial, contributing to stable and reliable communication. As will be explained later, the system was tested over a 1-week period in a real farm under stable weather conditions. The objective of the test was to validate the proper functioning of the system, not to assess the behavior of the LoRaWAN communication layer under adverse climatic or topographic conditions. Nevertheless, no transmission errors or signal degradation was observed.