# A Smart Sensing System of Water Quality and Intake Monitoring for Livestock and Wild Animals
## 2 System Design and Implementation
### Hardware and Software Implementation  
The hardware of the sensing system contains the SD Card Adapter, the motion detector with the camera, the thermal sensor, and the RFID Reader. The SD Card Adapter is the system's data storage, all the images, RFID tags, thermal readings, and timestamps taken by the other components of the system are stored on a single SD card slotted on to this adapter. In order to access the recorded data, users must manually remove the SD card and insert it into a device. The thermal sensor measures the temperature of the water in the drinking station's tank. The RFID Tag Reader reads the tag on the ears of the animals on the field and identifies them. It allows the system to match the recorded data of the volume of water consumed and the amount of time spent on the drinking station by each animal. The RFID Reader used in the smart sensing system is a Nordson NK-RF12 125 kHz long-range reader. It is a 125 kHz, RS-232 standard reader with a 9-16 V operating voltage and 70-100 cm reading range. Each unit weighs 1.5 kg and has a size of 230 \(\times\) 230 \(\times\) 35 mm. To operate, the reader is connected to a power source and the overall system through its VCC and GND, and RxD and TxD cables, respectively. The RFID tag [42] is another important component of the system. In our system, the RFID tags were passive RFID tags with a rectangle shape and a size of 8.5 cm by 5.4 cm that has a read distance of approximately 30 cm.  
The operation of the RFID reader is simple. Every time a compatible RFID tag is passed by the reader, the reader reads its ID and transmits the data to the system. The system then saves the ID alongside a timestamp and date of the detection in an excel file format within the SD card data storage. As the Reader operates on a typical RS-232, 9-16 V voltage range, its output cannot be connected directly to the Arduino Mega, as any input above 5 V can damage the Arduino board. Therefore, the reader's output is first passed through an RS232 to TTL converter which in turn is connected to the Arduino board. The functionality of the RFID Reader is first tested by attaching it alone to the Arduino board and running a simple RFID Reader code to ensure that it can read tag IDs and send them to the board. The simple testing code utilizes a custom library and sets the default pins for the Arduino Mega's respective RxD and TxD pins for both receiving and transmittingdata from and to the RFID reader. The scanned ID number is converted into a hexadecimal number and saved to the CSV file in the SD card alongside the time and date.  
The system software control flow chart is illustrated in Figure 3. After system initiation, the system checks if the connection of the SD card is in a good shape, then it measures the water level to make sure that there is enough water for the animal. If there is not enough water, the system sends an alert and displays the water level on an LCD screen. The water level information is then stored in the SD card. If the system passes the initial checkups, the system searches events from the RFID reader and motion detector, and if there is a drinking event, the system records the data of the event in terms of water depth, temperature, and animal ID. The control program is running on the Arduino Mega board. The current control flow chart uses a polling method to check the RFID and Motion detector every time. The algorithm efficiency could be improved by adapting the interrupt method to let the RFID or Motion Detector to trigger the system data collection.