HCMC UNIVERSITY OF TECHNOLOGY AND EDUCATIONFACULTY OF MECHANICAL ENGINEERING REPORTAI PROJECTMonitoring the health of cows using IoT devices combinedwith LSTM model for real data in Agri
Trang 1HCMC UNIVERSITY OF TECHNOLOGY AND EDUCATION FACULTY OF MECHANICAL ENGINEERING
-
REPORT
AI PROJECTMonitoring the health of cows using IoT devices combined with LSTM model for real data in Agriculture.
Instructor: Bui Ha ĐucStudent:
1 Nguyen Tan Hoang 20134015
2 Nguyen Cong Quy
Trang 2
POINT
Trang 3Monitoring the health of cows using IoT devices combined with LSTM model for real data in Agriculture.
Abstract
In the increasingly developing world of technology, the application of IoT andartificial intelligence in agriculture has opened up new opportunities To take advantage
of the strengths in the field of technology and the increasingly expanding development of
AI, this report will focus on monitoring the health of cows in agriculture through the use
of IoT technology and the LSTM model Firstly, the report will introduce the importance
of monitoring cow health and how IoT can be applied in agriculture Next, it describes indetail the designed system, including the types of sensors used, the configuration of thedevice box, and the process of data collection and transmission The report continues tofocus on data analysis and prediction of cow behavior The report introduces the AILSTM model and how it is applied to predict behavior based on data from accelerationsensors The results from the AI model are analyzed and explained Then it describes theprocess of sending data to the web and how information is presented on the user interface
To visualize and have accurate conclusions, an experiment is deployed, which describesthe process of testing the system in a real environment and evaluates the performance andreliability of the system Finally, the report summarizes the main findings and proposesfuture directions
1 Introduction
Agriculture plays a crucial role in the economy and development of every country.Among this, cattle farming is an indispensable part, especially in providing quality foodsources for humans Healthy cows will reproduce and produce milk more effectively.Moreover, monitoring the health of cows also helps reduce labor costs and antibiotic use,while improving the sustainability of the farm However, traditional cow healthmonitoring is often costly and ineffective This is the main motivation to seek a new
Trang 4solution, using IoT technology and LSTM models, to monitor cow health moreeffectively.
The main goal of this project is to apply IoT technology and LSTM models to monitor thehealth of cows, aiming to improve the quality of farming, reduce health risks, andoptimize business performance The student research team hopes to create an effective,accurate, and reliable cow health monitoring system, contributing to the development ofthe agricultural sector in the future
2 Overview of the topic
2.1 Livestock monitoring system
The livestock monitoring system, especially for cows, plays an important role inensuring the health and productivity of the herd These systems use IoT devices attached
to cows to collect data on their location, temperature, blood pressure, and heart rate Thisdata is then sent to the farmer’s computer almost in real time
The benefits of using a livestock monitoring system include the ability to accuratelytrack the health and activity of cows, detect early signs of disease, and optimize thefarming process This not only helps increase productivity and profits, but also helpsimprove the lives of cows
To get a broader overview of the livestock monitoring system market, we can refer tosome products currently on the market that are widely used and applied As well aslooking at some products combined with the integrated technology structure inside thosecomplete products
First is Allflex Livestock Intelligence: They provide advanced livestock monitoringsolutions to collect and analyze important data for each tagged animal Their technologymonitors millions of animals worldwide Allflex’s dairy cow monitoring solutionsprovide actionable information based on data, based on superior temperature detectionand real-time reproduction and health monitoring, for optimal productivity andmanagement Their monitoring technology is used daily to observe millions of cows, withsettings at tens of thousands of farms worldwide Allflex’s beef cattle monitoring solutionhelps producers increase the reproduction rate and maintain herd health By leveraging
Trang 5superior estrus detection capabilities, producers can increase the fertilization rate, monitorreproductive status, and identify reliable replacement pigs
Allflex Livestock Intelligence uses a range of technologies to build their livestockmonitoring system Allflex uses physical and electronic identification technology toidentify each animal in a herd This technology includes the use of tags with multiplecolors and printing options, as well as the use of RFID technology Allflex also usestissue sampling technology to collect biological samples from livestock ears Informationfrom biological samples can reveal the health status of each animal And based onlivestock monitoring technology to collect and analyze important data for each taggedanimal This technology helps manage reproduction, health, and nutrition
Figure 1
Secondly, I would like to mention SAS for Livestock Monitoring: SAS’s livestockmonitoring system, supported by Microsoft Azure, helps large-scale livestock producersand buyers (for example, retail food chains) optimize the growth cycle, productivity, andquality of animals with improved health monitoring across all locations
SAS’s livestock monitoring system uses a range of advanced technologies: Easilydeployable sensors combined with AI to collect data from livestock These sensors can
Trang 6track growth, physical activity and characteristics, as well as livestock’s digestive output.This system also uses AI to analyze data collected from sensors AI helps detectphysiological abnormalities (for example, diseases and stress), providing importantinformation for livestock health management Predictive analysis based on the cloud tomonitor livestock effectively This technology helps improve quality, reduce costs, andpredict output Automatic alerts: This system provides automatic alerts when systems arenot restarted and optimizes plans and schedules for feeding Use real-time availableinformation to improve supply and demand forecasts.
Figure 2
And finally, I would like to mention a product from AWS - AGCO Livestock Healthand Quality of Life Monitoring system With leading cloud technology, AWS hasintegrated many core services to optimize the livestock monitoring system AGCO isdeveloping a smarter platform to empower farmers and integrators with the insights theyneed There are three major components to the platform:
Trang 7Figure 3.
Load sensors on poultry feed containers and the Cumberland Broiler Hanging Scalesplatform transmit data to the central controller A receiving system to process data, runmodels, and estimate target indicators A self-service dashboard with detailedinformation, alerts, and predictions
This modular architecture with well-defined components working in conjunctionenables the building of an extensible cattle monitoring IoT system for the farm Next, wedive into the details of each main component
Trang 8The wearable device fixed on the animal contains a variety of sensors to measure vitalhealth parameters Motion sensors like accelerometers and gyroscopes can track the cow'smovements and activities like standing, lying down, walking, etc Location sensors likeGPS provide positioning coordinates and trace the animal's movement Biometric sensorslike heart rate monitors, temperature sensors, etc give insights into internal health Thenumber and types of sensors can be chosen based on monitoring requirements.
2.2.2 Processor
The wearable device contains an onboard processor like a microcontroller unit(MCU) or system-on-chip (SoC) The processor continually polls the integrated sensors,processes the incoming data, packages it into transmission packets, and outputs to thewireless module It provides the necessary computing capabilities for executing the deviceapplication firmware and algorithms Different MCUs offer varying processing power,flash storage, interfaces, power consumption, etc
2.2.3 Communication
A wireless communication module on the wearable device transmits sensor data tothe farm gateways Different protocols like WiFi, Bluetooth, Sigfox, NB-IoT, LoRa, etc.can be chosen based on bandwidth, range, power, and cost needs For large farm scales,low-power wide area networks allow long range The gateways are equipped withcompatible wireless technology to receive data
2.2.4 Server
The sensor data from cattle is aggregated and forwarded by the farm gateways to acloud-based server The server provides data storage in time-series databases, runsanalytics applications like ML models for health monitoring, and hosts web dashboards.The modular backend infrastructure enables storing high volumes of historical data, andon-demand analytics and provides access from anywhere
2.3 General data processing
The main goal of the developed prediction framework is to build behavior recognitionmodels in order to analyze the dairy cows’ behavior This framework includes twophases: training and validation The goal of the training phase (Figure3) is to create
Trang 9supervised prediction models that can be applied to new sensor data, which are unknown
to the model In this phase, the sensor data from a field experiment are labeled by adomain expert who observed the videos that were made during the experiment
Figure 4 Procedure of two steps: preprocessing and model training
Since the data coming from sensors contain noisy data or inconsistent timestamps, they require the application of preprocessing techniques These techniques:
• Cleaning: The initial step involves cleaning the data to remove any inaccuracies or irrelevant information or missing value
• Normalization: Data from different sensors may be normalized to ensure consistency
in scale and format, making it easier for analysis
• Balance dataset: A balanced dataset is one where the target variable (or variables) has approximately the same number of instances across its different classes
• Extract features: Key parameters that indicate cattle behavior or health status areidentified
For instance, patterns in movement data from accelerometers might indicate grazing,resting, or abnormal behavior are needed to create necessary datasets for training and toenhance the accuracy of the learned models During the training of the model, the data areclassified by a learning algorithm where the classes are the different behavioral patterns ofdairy cows (Labels) The output of the training phase consists of learned models, whichwere created after the model training These models comprise training datasetspecifications, which include the following:
• Which preprocessing techniques were applied
• What should be predicted ( cow’s behavior )
• Which learning algorithm is executed
• Which dataset is used for testing
Trang 10• The result achieved (e.g., 90% accuracy)
2.3.1 What should be predicted
An example of timely disease prediction in cattle due to continuous behaviorclassification by a monitoring system can be described as follows:
Imagine a dairy farm that has implemented a sophisticated behavior classificationsystem, equipped with sensors and machine learning algorithms, to monitor the health ofits herd This system continuously tracks various indicators of cow behavior, such asactivity levels, feeding patterns, and rumination times
One evening, the system observes that Cow #47, usually active and with consistentrumination cycles, is suddenly showing a sharp decrease in rumination and an unusualincrease in laying down time These behavior changes trigger an alert in the system.Because the monitoring is continuous, the alert is immediately sent to the farmer's mobiledevice, signaling a potential health issue
The farmer reviews the data and notices that Cow #47's behavior deviatessignificantly from her normal pattern and that of the herd Drawing on the insightsprovided by the system, which correlates such behavior with the early onset of mastitis,the farmer decides to conduct a physical examination of Cow #47 the next morning.Upon examination, early signs of mastitis are indeed found, and immediate treatment
is initiated The timely intervention, guided by the predictive alert from the behaviorclassification system, allows for a quick response that prevents the condition fromworsening, promoting a faster recovery for Cow #47 and preventing the spread ofinfection to other animals in the herd
This scenario showcases the critical role of continuous behavior classification in earlydisease detection, enabling proactive health management and minimizing the impact ofdiseases on cattle farms
The ability to accurately classify the behavior of cows through a monitoring systemholds immense value, particularly in facilitating rapid and precise diagnoses of healthconditions by professionals By effectively identifying and interpreting various behavioralindicators, such as changes in activity levels or rumination patterns, specialists can
Trang 11quickly detect anomalies that may signal health issues, including estrus and criticaldiseases like mastitis This proactive approach allows for timely intervention, which iscrucial in managing the health and well-being of the herd, ensuring both the animals'welfare and the economic viability of farming operations With the aid of advancedmonitoring tools that provide real-time data and historical analysis, experts can makeinformed decisions, optimizing the treatment process and potentially improving theoverall health management of the livestock.
2.3.2 Which learning algorithm is executed
Long Short Term Memory networks – usually just called “LSTMs” – are a specialkind of RNN, capable of learning long-term dependencies They were introduced byHochreiter & Schmidhuber (1997), and were refined and popularized by many people infollowing work They work tremendously well on a large variety of problems, and arenow widely used
LSTMs are explicitly designed to avoid the long-term dependency problem.Remembering information for long periods of time is practically their default behavior,not something they struggle to learn!
All recurrent neural networks have the form of a chain of repeating modules of neuralnetwork In standard RNNs, this repeating module will have a very simple structure, such
as a single tanh layer
The Core Idea Behind LSTMs
The key to LSTMs is the cell state, the horizontal line running through the top of thediagram
The cell state is kind of like a conveyor belt It runs straight down the entire chain, withonly some minor linear interactions It’s very easy for information to just flow along itunchanged
Trang 12Figure 5.The repeating module in a standard RNN contains a single layer
LSTMs also have this chain like structure, but the repeating module has adifferent structure Instead of having a single neural network layer, there are four,interacting in a very special way
Figure 6.The repeating module in an LSTM contains four interacting layers
The Core Idea Behind LSTMs
The key to LSTMs is the cell state, the horizontal line running through the top of thediagram
The cell state is kind of like a conveyor belt It runs straight down the entire chain,with only some minor linear interactions It’s very easy for information to just flow along
it unchanged
Trang 13An LSTM has three of these gates, to protect and control the cell state.
Step-by-Step LSTM Walk Through
The first step in our LSTM is to decide what information we’re going to throw awayfrom the cell state This decision is made by a sigmoid layer called the “forget gate layer.”
It looks at ht−1 and xt, and outputs a number between 0 and 1 for each number in the cell
Trang 14state Ct−1 A 1 represents “completely keep this” while a 0 represents “completely get rid
Trang 15We multiply the old state by ft, forgetting the things we decided to forget earlier.
Then we add This is the new candidate values, scaled by how much we decided
to update each state value
In the case of the language model, this is where we’d actually drop the informationabout the old subject’s gender and add the new information, as we decided in the previoussteps
Figure 11
Finally, we need to decide what we’re going to output This output will be based onour cell state, but will be a filtered version First, we run a sigmoid layer which decideswhat parts of the cell state we’re going to output Then, we put the cell state through tanh(to push the values to be between −1 and 1) and multiply it by the output of the sigmoidgate, so that we only output the parts we decided to
For the language model example, since it just saw a subject, it might want to outputinformation relevant to a verb, in case that’s what is coming next For example, it mightoutput whether the subject is singular or plural, so that we know what form a verb should
be conjugated into if that’s what follows next
Figure 12
Trang 16Location - A module GPS provides location accuracy up to 2.5 meters
Temperature - A digital temperature sensor with ±0.2°C accuracy, 0.1°C resolution,and fast response time below 5 seconds is needed to monitor body surface temperature.The measurement range should cover at least 30°C to +50°C
• Size - The module should be compact and lightweight to fit on a collar A target size
of 118x55x58 cm or less and weight under 200 gm is estimated
• Power - a battery power source with multi-day operation Low-power sensors andprocessing will maximize operation time
• Communication - Wireless protocols like LoRa allow data transfer to the farmgateway from the collar-mounted device Range, bandwidth, and power consumptionmust be considered
3 Block diagram of the system
3.1 Technical requirements
3.2 Block diagram of the system
Trang 17MPU9250 (Accelerometer, Gyroscope, Magnetometer): Normal operating current ofAccelerometer: 450µA When in standby mode, MPU9250 consumes about 8µA.Operating time in each cycle: 1 second / 5 minutes
NEO-6M GPS Module: Average current consumption: about 45mA or 67mAdepending on the operating mode When in standby mode, NEO-6M consumes about6mA Operating time in each cycle: 1 second / 5 minutes
NTC Thermistor Sensor: Average current consumption: very low consumption anddoes not affect the normal working current Operating time in each cycle: 1 second / 5minutes
Trang 18LoRa RA-01 Module with SX1278: Average receiving current: less than 10.8mA.Average transmitting current: less than 120mA When in standby mode, LoRa RA-01consumes about 1.6mA Operating time in each cycle: 1 second / 5 minutes
Arduino Uno: Average current consumption: about 120mA When in standby mode,Arduino consumes about 19 mA Operating time in each cycle: 1 second / 5 minutes And based on the current demand based on the battery to be able to supply themonitoring box is not constrained space proposed with lithium-ion battery current about5V And assuming the Battery will operate within 1 month Then the operating time in 1hour will be 12 seconds
Energy Demand (Wh) in an Operating Cycle:
E activity=P activity×t activity
E activity = EMPU9250+EGPS+EThermistor+ELoRa+ERaspberry Pi
E activity = (0.00045+0.045+ 0 +0.0108+0.12)×5× 3001 = 0.00294 Wh
E activity : Energy needed for each operating cycle (Wh)
P activity : Power consumption in each operating cycle (W)
t activity : Operating time in each cycle (h)
Energy Demand (Wh) in Standby Mode:
E standby= standby× standbyP t
E standby = (0.000008+0.006+0.0016+0.019)×5× 299300 = 0.1326 Wh
E standby: Energy needed in standby mode (Wh)
P standby : Power consumption in standby mode (W)
t standby : Standby time in each cycle (h)
Total Energy Demand (Wh) in a Cycle:
E total=E activity+E standby = 0.1355WhETotal : Total energy needed in each cycle (Wh)
Trang 19Battery Life (Number of Operating Cycles before Battery Replacement): (assuming2000mAh Battery)
Battery Life= Battery Capacity / E Total= 2000 mAh× 5 V0.1355Wh =74period ≈ 6.17hBattery Life: Battery life is measured by the number of operating cycles before the batteryneeds to be replaced (cycle)
So if we want to use it for 1 month (30 x 24 hours)
Required Battery Capacity (Ah):
Battery Capacity= Etotal × Battery LifeBattery Voltage = 0.1355 7205× = 19.512 Ah
Battery Capacity: Required battery capacity (Ah)
Battery Voltage: Battery voltage (V)
But with this project to continuously deploy for easy data monitoring, data will be takenevery 1 second
3.3.2
3.3.3 Wireless communication block
To choose the appropriate wireless communication technology for the project, thefollowing 5 evaluation criteria are considered:
Coverage and range: The range and coverage of wireless technology greatly affectthe operation of the monitoring system
Compatibility with other devices: The technology should not be compatible withother devices in the system such as the central processor, sensor block
Cost and complexity of development: The cost must be suitable for a whole system ofreceiving and transmitting devices And the complexity of upgrading the system whenwanting to optimize performance later
Trang 20Security and reliability: Security is also an important factor when choosing wirelesstechnology, choosing a type of communication with safe security with data as well ashigh data reliability
Scalability: Wireless technology should allow the system to be easily expanded when
necessary, as the number of dairy cows can increase or decrease at each stage
Based on these criteria and analysis of a popular wireless communication type LoRa.
Figure 14
Coverage and range: LoRa (Long Range) is a wireless communication technology
developed to create wide-area, energy-efficient networks necessary for Internet of Thingsapplications LoRa can transmit data over large distances, which is very important formonitoring livestock on a large scale
Energy saving: IoT devices often operate for a long time without needing to becharged or have their batteries replaced LoRa is an energy-saving technology, whichhelps extend the battery life of IoT devices
Scalability: LoRa supports networks with a large number of devices, which is veryuseful when you want to expand your system
Reliability: The reliability of wireless connections is very important, especially whenmonitoring the health of livestock LoRa provides reliable wireless connections, even inharsh environmental conditions