Design and Implementation of an Esp32-Based Smart Embedded Industrial Poultry Farm

– Many poultry farmers are performing diverse operations manually. They, therefore, experience a huge financial loss as a result of their inability to properly automate the monitoring and control of environmental factors such as temperature, humidity, air quality, and to ensure an adequate supply of light and water. These factors adversely affect the chicks and lead to respiratory, digestive, and behavioural disorders. This affects the chicks’ food intake and leads to an increase in mortality rate and chances of diseases. Therefore, this paper seeks to address these factors by developing an embedded poultry farm. The system was developed using an advanced yet low-cost and low-power System-on-Chip offering WiFi baseband processor and a plethora of peripheral interfaces for the actuators and sensors while Arduino emulator in Proteus 8 was the tool used for the design simulation. The system when tested was able to sense environmental parameter status wirelessly and responds accordingly to regulate and maintain an optimum condition for improved health condition for the chicks. The automated system will help for the purpose of improving productivity and environmental or climatic conditions in the poultry farm, making it conducive for the broiler chicks.


I. INTRODUCTION
An embedded poultry farm is a poultry farm which has a reliable system that is capable of automatically regulating the variables that affect the wellbeing of a poultry farm. Such variables include climatic conditions, water supply system, lighting system, etc. The bid to ease labour and increase productivity in poultry farm has given rise to the emergence of automated poultry farms. According to the Food and Agriculture Organization of the United Nations (FAO), chickens are the largely domesticated birds and their meat represent in the region of 88% of global poultry meat output [1].
This work is focused on broiler chicks in particular. Bird wellbeing depends largely on several environmental or climatic parameters that affect the revenue and the performance of the production such as laying time, egg weight, and average broiler weight. The henhouse (chicks' house) should be able to not only measure and monitor but should control the temperature, humidity, moisture, water intake and period of illumination. When the environmental readings do not meet the standard levels, respiratory, digestive, and behavioural disorders probably take place. This leads to reduction in the food intake and eventually increases the mortality rate and chances of diseases [1].
Many poultry farmers are performing diverse operations manually. Therefore, they experience huge financial loss as a result of erroneous weather forecasts and unsuccessful methods employed in traditional farming. This, therefore, leads to new technological approaches required to continuously and effectively improves the productivity, profitability, and sustainability of major farming systems. An embedded poultry farm is, therefore, one that is fully automated with the purpose of improving productivity and environmental or climatic conditions in the poultry farm, making it conducive for the broilers (chicks).
The work proposes a very convenient solution for maintaining an optimum environmental condition by measuring, monitoring, and controlling these environmental parameters in order to achieve a relaxing and standard environment for the chicks. The farmhouse automation system based on the Arduino microcontroller technology is designed to manage temperature, relative humidity, automatic lighting, and water supply control. There is no comparison between the proposed embedded farmhouse and the conventional method utilized over the years. The performance superiority of the system should be enough to motivate poultry farmers to adopt this technology in their poultry farms.
The aim of this paper is to design and implement a smart embedded poultry farm. The specific sub-objectives are to determine the optimum temperature, humidity, and other environmental conditions for broiler chicks. It also includes the development of a flexible wireless embedded system and the use of an assembly language and AT commands with a mix of Arduino C/C++ to design the software for the overall functionality of the system. And to implement an automatic water supply control for chicks and control the environmental parameters of the poultry farm in real time using an inexpensive yet powerful System-on-Chip (SoC) as its onboard application processor.

II. REVIEW OF RELATED WORK
In [2] the authors published a paper on a smart farm: extending automation to the farm level. The work incorporated automation into various aspects of the farm not just poultry. Most of the features of the farmhouse proposed by this work can, however, be used in smart industrial poultry farm. Features of the farmhouse automation system as proposed by the work includes the automatic light switching system and using bidirectional counters to count the number of people entering the farmhouse. For the climatic control system, temperature, humidity, and other parameters are monitored. The system's humidity sensor is responsible for humidify or dehumidify the poultry depending on the value of humidity. Remote monitoring is also added to the farm with the help of GSM technology used in mobile phones. The system will notify the farm owners on their mobile phones and allow them to control the automated system. The work, however, has some setbacks which this work seeks to address. The parameters not being precisely regulated according to poultry specifications. That is, it gives a general overview of the automation of the farming system as a whole. Hence, the temperature and humidity range for chicks were not followed. Another limitation is that the automatic light switching system as implemented in the work is only used to count the number of people entering or leaving the room which will not give room to a stable illumination of the poultry when needed. The system uses sprinklers to increase humidity which if used in the poultry farmhouse will give rise to water droplets resting on the chicks.
A survey on smart poultry farm automation and monitoring system focused on the integration of wireless sensors and GPRS network to control and automatically monitor environmental parameters like temperature, humidity, ammonia gas, etc. in a poultry farm is proposed in [3]. The users are able to get the internal environmental situation of poultry farm by receiving a message on registered mobile number. The system will initiate the action automatically to control the environmental parameters when there is a sudden change in climate. Water level control and food control mechanism is also monitored and controlled with the help of sensors. All the sensors are connected with the raspberry pi which can control and monitor all data. The detail records of poultry farm with an environmental condition are later viewed on a webpage. The work was implemented using Raspberry Pi, which is a high performance, low power processor. LM35 Temperature Sensor, SY-HS-220 Humidity Sensor, MQ135 Sensor used for detecting Ammonia Gas, MQ Smoke Sensor, Level Sensor for monitoring level of water. These signals are feed to Analog-to-Digital Converter (ADC) MCP3204 which converts them to digital form. The system designed provides an efficiently automated poultry farm monitoring system for the healthy atmosphere for chickens without human interference. The farmer can monitor real time environmental contexts such as temperature, humidity, ammonia gas and water level using smartphone application. The work, however, has some limitations which this work also seeks to address. The system has no provision for sustainable lightening system. Raspberry pi is costlier and less easy to set up compared to Arduino Uno which can also be used to implement the system.
Automated control system for poultry farm based on embedded system is proposed in [4]. Here, wireless sensor network is used to collect information in the poultry farm. LM35 temperature sensor is used to take the temperature measurement. Temperature measurement and water level indicator is controlled using the microcontroller. The data is analyzed and presented on a graphical user interface (GUI), programmed with LabVIEW. It allows the user to retrieve upto-date information about the environmental factors in the poultry farm and control equipment easily through the SMS gateway. It provides great utility for the user as they can access the information or receive warnings at any location where GSM services exist. The system is labour-saving for the farmer and reports environmental changes immediately, thereby enabling the farmer to take appropriate action. It is also a flexible system as it can be integrated into small and medium-sized poultry farms with minimal modifications. The real time values are also displayed on the LCD. The work also has some setbacks which this work seeks to address. A temperature reading is taken only at one point of the poultry house and therefore could not give the average reading especially for an industrial poultry farm. The humidity control system is not implemented in this work as well as no provision for an automatic lightning system.
A web-based poultry farm monitoring system using a wireless sensor network (WSN) on Crossbow's TelosB motes for measuring temperature and humidity values is proposed in [5]. The network's data is uploaded into an online database using an agent program and then accessed via the internet using web analysis applications. Three measurement spots were used to get more accurate readings of the climatic condition. Wireless communication was used to gather sensor values and to communicate between the centralized control and actuators located at different parts of the poultry farm. It is easier to relocate the measurement spots by simply moving the sensor nodes (motes) from one location to another within the communication range. Additional costs occur when motes run out of batteries and the batteries need to be replaced or charged, but the lifespan of the battery can be several years if efficient power saving algorithm is applied. For measuring the temperature and relative humidity Sensirion SHT11 allround temperature and humidity sensor were used. In the work, commercial sensors with CrossBow's TelosB mote were integrated to measure temperature and humidity values in a poultry farm monitoring system. The system feasibility was verified in a simple star topology setup in a research poultry farm. The work has major advantages such as three measurement spots which would enable more accurate readings of the climatic condition within the poultry farm. The work also has some setbacks which this work seeks to address. Here, a lightening system, water level indicator and sustainable power were not implemented. The real time values of the parameters measured are not displayed on LCD.
This paper [6], focused on the wireless sensors for data collection and GPRS network for remote monitoring to automate environmental parameters in a poultry farm. The system is designed in such a way that the parameters; Ammonia gas, water level, feed level, humidity and temperature are monitored and controlled using a microcontroller. Atmega324A is a microcontroller that connects all the sensors while GPRS (General Packet Radio Services) module is used as GSM for remote reporting.
This paper is seeking to address the setbacks and limitations of the above reviewed works. The work has implemented a sustainable automatic lightening system which is independent on the heat source. Also, in this work, temperature and humidity readings are being taken from three different parts of the poultry farm in a star topology and the average is gotten which gives a more accurate result on the climatic condition of the poultry farm. The system gives a real time monitoring capability using LCD and transmits wirelessly to a TCP client on a host system software called PuTTY [12]. It is also an effective, low cost and flexible system which enables it to be integrated in small, medium, and industrial poultry farms with minimal modifications. For the sake of simplicity Arduino was used in the simulation as the application processor given that the code is portable to the implementation that uses Espressif's ESP32 SoC with the help of arduino-esp32 core.
III. DESIGN METHODOLOGY The proposed embedded system has different units which have been automated in other to achieve a smart poultry farm for broiler chicks.

A. System Consideration
These include the following automatic light switching system, climate control system (temperature and humidity control) and water feeder control.

1) Automatic light switching system
The two meshed openings by the side of the poultry farm allow sun rays to provide the needed illumination during the day. At night, the farmer may want to go into the farm to see the condition of the chicks. This time, an automatic lightening system would be needed by the farmer to illuminate the poultry farm. A PIR Sensor is used to sense motion at the entrance of the farmhouse, such that, when someone opens the door, the PIR sensor senses movement and sends a signal to the microprocessor, the microcontroller then sends a signal to the relay to turn on the light. The light goes off when motion is no more detected.

2) Climate control system (Temperature and Humidity Control)
A fan or a heater will get switched on automatically depending on real time readings from a temperature sensor. A DHT11 sensor is sufficient to provide the required accuracy for in-house temperature readings. Depending on whether cooling down or heating up is required inside the poultry house; the microcontroller decides to switch on the exhaust fan or the heater respectively. It offers comfortable conditions for livestock devoid of boring manual monitoring, with energy conservation. The DHT11 sensor which has a humidity sensor incorporated determines either to humidify or dehumidify the poultry house. The poultry house is humidified when the humidity value from the DHT11 sensor is below the threshold value using an electric jug which produces steam used to humidify the poultry house. The exhaust fan comes on when the humidity is above the threshold value. The exhaust fan sucks out the excess humidity in the air. The design data for the temperature and humidity control system is shown in Table I. Optimal temperature ranges vary by birds and stages of development. There different behavioural mechanism bird adapts to maintain their temperature after the first few days of hatching. Bird's behaviour most at time indicates their thermal discomfort. Some of these behaviours include crowding away from heat source, frequent spreading and flapping of wings which indicate high temperature. If the temperature is low chicks tend to crowd around the heat source, rigid posture, trembling, ruffling of feather, huddling, and piling on top of each other and distress sound or vocalization.
Birds are very sensitive to extremes of relative humidity. A relative humidity below 30% will cause increased agitation of the chicks and may cause aggressive behaviour. On the contrary, extreme moisture can lead to wet litter conditions, allied with high ammonia concentrations, poor air quality, enteric diseases, and respiratory problems. Ideally, the relative humidity should be between 50 and 70%. 3

) Water supply control
The system also has a water level sensor which detects when the water level goes below a given threshold value and send a signal to the microcontroller which in turn sends a high output to the pump. The pump is turned on to refill the water feeder. When the water feeder gets to the upper threshold value, the sensor also detects it and sends a signal to the microcontroller to turn off the pump. The water level sensor was recalibrated from the default range of 1-1023 to a range of 1-100 using the map function provided in the Arduino library, which was used to achieve better evaluation. A threshold range of 90-10 was assigned to the sensor. Where 90 is the upper limit and 10 is the lower limit.

4) Wireless Fidelity (WiFi)
To enable remote collection of data from the embedded poultry, a WiFi SoC is also attached The SoC is ESP32 which is based on a low-power Xtensa® 32-bit dual core LX6 microprocessors, each running at a speed of 240MHz while integrating 448kB ROM, 520KB SRAM, Wi-Fi baseband protocol processor and so many hosts of peripherals used to interface the sensors and actuators [13]. Using PuTTY as a TCP client, we were able to collect the sampled data from the sensors over a wireless local area network. Using the rich library support for the Arduino-esp32 port, all application code was integrated with the communication. A fair radius of 25-meter Line of Sight is covered by the implementation. The system data streaming interface is quite flexible given that any TCP client irrespective of the host device (PC, Tablet or Smart Phone) can access the data with the provision of proper network credentials.

B. Hardware System Design
PIR motion sensor, DHT11 sensor and water level sensor are used to collect information in the poultry farm. The collected information or data is sent to the microcontroller (Arduino Uno). The fan, heat source and humidifier which require more than 5 V supplied by the Arduino Uno are each connected to a relay which serves as a switch and also shields the microcontroller from the higher voltages (i.e., 12 V and 240 V used by the fans and other appliances respectively). The lighting system is controlled by the microcontroller in response to the data sent by the PIR sensor. The fan, heat source and humidifier are controlled by the microcontroller through the relays in response to the data received from the DHT11 sensor. The microcontroller turns an LED on or off in response to the data gotten from the water level sensor. The LED comes on when the water level is below a certain threshold value indicating that the pump has been turned on. The overall architecture and circuit diagram of the proposed system is shown in Fig. 1 and Fig. 2, respectively. The circuit diagram of the entire system was designed with Proteus 8 showing the detailed connections of the LCD, Arduino Uno R3, two DHT11 sensors, fans, LED, heat source, neon lamp (for lighting), 5 relays, PIR motion sensor, AC Voltage sources and 12V dc voltage sources. Fig. 2 shows the circuit diagram of the entire system.

C. Software System Design
The microcontroller was programmed using the Arduino C. The programming of the components was done on the Arduino platform. The Arduino platform is an attempt to simplify the process of writing codes without unduly limiting the user's flexibility and also takes care of the unneeded complexities. The Arduino software consists of two main parts: the development environment known as the IDE (Integrated Development Environment) and a core library, both open-source. The Arduino development environment is a minimal but complete source code editor. All functions needed for programming were accessed from a set of seven toolbar buttons or a few drop-down menus. The environment which includes a serial monitor enabled sending and receiving of data from the board, easing debugging without requiring additional software. The Arduino core library consists of AVR C/C++ functions that are compiled along with the user's sketch. The compiled binary file was then uploaded to the Arduino board. Programs were created in the Arduino development environment and then loaded to the Arduino board. Codes were entered in the proper syntax which means using valid command names and grammar for each code line. The compiler detected and flagged syntax errors before loading to the board. In some cases, the error message was cryptic, and a bit of hunting was done because the actual error occurred on a program line different from that which was flagged. Although sometimes, programs passed cleanly through the syntax checker has still failed to do as intended. In this case, the Arduino did what it was told to do rather than what we wanted it to do. Through debugging, the errors were detected by acting as the computer, reading the codes line by line and discovering where the mistakes were made. The software design followed the flowchart shown in Fig. 3.

IV. RESULTS AND DISCUSSIONS
The results obtained after the implementation and testing running the embedded poultry farm for four (4) weeks.

A. Climatic Condition
The climatic condition within the poultry farm based on temperature and humidity was adequately controlled and maintained within the range conducive for the chicks as provided in Table I. The climatic control was adequately carried out using two DHT11 sensors placed at strategic positions not far from the chicks in the farm such that it gave relatively accurate readings of the hot or cool air in the poultry farm. The average readings of the two temperature values of the two DHT11 sensors as well as that of its humidity have been calculated by dividing the sum of the two temperature readings by two and dividing the sum of the two humidity readings by two respectively.

1) Humidity and moisture control
The humidity within the farm for chicks of a day old to 4 weeks is 50-70 %. At a value greater than 70%, the exhaust fan automatically turned on. The excess humidity was sucked out in a very short time via the exhaust fan, thereby restoring the humidity to a normal range. When the exhaust fan turned on, humidity value reduced and immediately it comes down to 70%, the fan turned off. When the humidity fell below the given lower threshold value, 50, the relay connected to the electric jug switched on, and the electric jug was powered. The water in the electric jug boiled for a short time, producing steam which was used to increase the humidity to the appropriate range. When the steam increased the humidity of the farmhouse to 50%, the relay turned off. This process ensured the poultry farm maintained humidity within the acceptable range all the time.
2) Automatic temperature control Two DHT11 sensors were used which were placed at strategic parts of the poultry farm. The average value of the temperature reading had an initial normal room temperature 27 ºC before the system was set up. After the setup, the heat source (bulb) came on to heat up the room to the temperature range given for day 1. When the temperature value was up to 32 ºC which is the lower threshold value for the first day, the heat source goes off. When the temperature exceeded the maximum threshold value, for example, 34 ºC for the first day, the cooling fan came on. After a short while, the temperature in the farm dropped to the maximum threshold value to turn off the fan automatically. The RTC module helped to automatically change the threshold values of the temperature as the number of day increases.

B. Automatic Lighting System
The switch was kept at the door-hinge in such a way that opening the door caused the switch to be pressed which when it did, caused the lighting system to come on automatically by sending an input high command to the microcontroller. Illumination of the farmer at night was achieved.

C. Automatic Water Supply System
At a point where water in the tank was almost full, the sensor gave a reading of 90. On the other hand, using 10 as the lower limit, when the water level in the tank was almost empty, the water level sensor gave a reading of 10. When the water level decreased below 10, the pump was switched on and switched off when the water level exceeds 90.

D. Real-Time Monitoring Using Liquid Crystal Display (LCD)
The LCD was able to display the temperature and humidity value as well as the water level and current date. The parameters: temperature, humidity, and the water level have been abbreviated to TEMP, HUM and W in such a way that the 16 by 2 LCD was able to display all the needed characters and numbers. The LCD displayed the real time values of the poultry farm which enabled the system to be monitored. This is also useful to ease troubleshooting as it would enable one to easily know when a DHT11 sensor is not functioning properly. One would be able to see the readings and know if the appliances that should come on at a given condition respond in the desired way.

V. CONCLUSION
The design and implementation of an embedded poultry farm that will measure and automatically control the climatic conditions in addition to water and power supply of the poultry farmhouse was successfully developed. The system was designed for a day to 4 weeks old broiler chicks. The real time values of the temperature, humidity and water level are all displayed on an LCD at all time. The microcontroller monitors continuously the measured parameters and regulates these parameters to meet the recommended international standard operating condition for broiler chicks at all time. The automated system will help for the purpose of improving productivity and environmental or climatic conditions in the poultry farm, making it conducive for the broiler chicks. Therefore, this work is recommended for use in an industrial poultry farm. The system can be further improved by adding an intelligence unit.