An-Najah National University Faculty of Engineering and Information Technology Computer Engineering Department Graduation Project 2 Automated Sample Preparation System Accomplished by: Supervisor:  Jenan Abualrub Dr. Aladdin Masri  Yaqout Salameh Presented in partial fulfillment of the requirements for Bachelor degree in Computer Engineering. May. 25, 23 1 Acknowledgment We would like to show our gratitude towards our supervisor Dr. Aladdin Masri for the support and help he offered throughout the project. We also want to thank all professors in the Computer Engineering Department for their efforts during our academic years. Finally, special thanks to our families and friends for their endless support. 2 Disclaimer This report was written by students Jenan Abualrub and Yaqout Salameh at the Computer Engineering Department, Faculty of Engineering, An-Najah National University. It has not been altered or corrected, other than editorial corrections, as a result of assessment and it may contain language as well as content errors. The views expressed in it together with any outcomes and recommendations are solely those of the students. An-Najah National University accepts no responsibility or liability for the consequences of this report being used for a purpose other than the purpose for which it was commissioned. 3 Table of contents Acknowledgment .................................................................................................................................... 1 Disclaimer ............................................................................................................................................... 2 List of figures .......................................................................................................................................... 4 Nomenclature .......................................................................................................................................... 5 Abstract ................................................................................................................................................... 6 1 INTRODUCTION ................................................................................................................................ 7 1.1 Statement of the problem ............................................................................................................... 7 1.2 Objective ....................................................................................................................................... 7 1.3 Scope of the work .......................................................................................................................... 7 1.4 Significance of the work. ............................................................................................................... 7 1.5 Organization of the report .............................................................................................................. 8 2 CONSTRINTS, STANDARDS and EARLIER COURSEWORK ......................................................... 9 2.1Constraints...................................................................................................................................... 9 2.2 Standards/ Codes: .......................................................................................................................... 9 2.3 Earlier coursework: ........................................................................................................................ 9 3 LITERATURE REVIEW .................................................................................................................... 11 4 METHODOLOGY ............................................................................................................................. 12 4.1 Hardware components.................................................................................................................. 12 4.2 Structure ...................................................................................................................................... 16 4.3 Mobile application interfaces ....................................................................................................... 17 4.4 Sensing circuit ............................................................................................................................. 20 4.5 Mechanism of action .................................................................................................................... 21 5 Results and discussion ........................................................................................................................ 23 6 Conclusion ......................................................................................................................................... 24 6.1 What we have learnt: ................................................................................................................... 24 6.2 Future work: ................................................................................................................................ 24 References............................................................................................................................................. 25 4 List of figures Figure 4. 1: Arduino MEGA 2560 ............................................................................................. 12 Figure 4. 2: ESP32 ................................................................................................................... 12 Figure 4. 3: : Stepper motor ....................................................................................................... 13 Figure 4. 4: : A4988 Driver ....................................................................................................... 13 Figure 4. 5: : Servo motor.......................................................................................................... 13 Figure 4. 6: Optocoupler ........................................................................................................... 14 Figure 4. 7: Electronic valve...................................................................................................... 14 Figure 4. 8: Relay ...................................................................................................................... 14 Figure 4. 9: 74HC14 IC ............................................................................................................. 15 Figure 4. 10: 7414 IC schematic ................................................................................................ 15 Figure 4. 11: 7474 IC ................................................................................................................ 15 Figure 4. 12: 7474 IC schematic ................................................................................................ 15 Figure 4. 13: System's parts 1 .................................................................................................... 16 Figure 4. 14: System's parts 2 .................................................................................................... 16 Figure 4. 15: System control screen........................................................................................... 17 Figure 4. 16: Test scheduling screen .......................................................................................... 18 Figure 4. 17: Test control screen ............................................................................................... 18 Figure 4. 18: Scheduling section screen ..................................................................................... 19 Figure 4. 19: Show/delete scheduled tests screen ....................................................................... 19 Figure 4. 20: Update tubes' availability screen .......................................................................... 20 Figure 4. 21: Sensing circuit ...................................................................................................... 21 5 Nomenclature Abbreviations Abbreviation Definition ASPS Automated Sample Preparation System MQTT Message Queuing Telemetry Transport IoT Internet of Things WIFI Wireless Fidelity 6 Abstract Analytical chemistry occupies a crucial role in the medical field for being the deterministic criteria in diagnosis. It primarily relies on performing chemical laboratory tests on patients’ samples, which are widely done manually and vulnerable to errors. In light of these challenges, the development of an automated sample preparation system (ASPS) provides a viable alternative to overcome the flaws of the manual process. The ASPS eliminates the need for manual intervention from the laboratory technician, as a needle would move automatically towards the samples and the reagents based on the selected test. The needle would then sense the substance and precisely dispense the required amount for the test in the reaction cup. Simultaneously, a syringe would help drawing in and expelling the substances. Throughout the test, the needle is cleaned to prevent any contamination. Additionally, the laboratory technician has the ability to schedule up to 4 tests, which the system would perform sequentially. The ASPS was developed using Arduino mega, motors, and a sensing circuit built upon capacitance manipulation. 7 1 INTRODUCTION 1.1 Statement of the problem A study conducted in 2020 states that (61.9 - 68.2%) of the errors associated with laboratory tests occur within the pre-analytical phase of the test[1]. The result is somewhat expected, considering that having the process performed manually paves the way for human factors to affect it undesirably, which leads to imprecise results. Moreover, there’s also contamination occurrence risk, which raises doubts about the reliability of the process. Hence, an ASPS is needed to overcome such issues. It would provide a consistent precise performance and reduce errors resulting from human factors. Automating the process would supposedly repeat the exact same steps for a certain test, enhancing the reliability and the efficacy of the process. 1.2 Objective The system is mainly built to modify sample preparation. It offers a mobile application that enables the laboratory technician to perform tests. Consequently, the needle starts moving based on the received information. Performing tests in this manner saves time and standardizes the process, this implies that all tests will be performed precisely and the repetition of the same test would result in an identical outcome. 1.3 Scope of the work The ASPS is specifically built to prepare samples for analysis purposes. The structure supports a set of reagents, samples and reaction cups. It also provides a needle cleaning mechanism. It mainly targets analytical laboratories where chemical laboratory tests are performed. 1.4 Significance of the work. Automating the process leads to advancement in sample preparation. Offering such an option would make performing tests be more accurate and precise. The ASPS is also reliable and capable of operating autonomously without a need for human supervision, which saves time and reduces the staff needed in a laboratory. 8 1.5 Organization of the report The first chapter is the introduction, where the definition of the problem, the scope of the work, and the significance of the work can be found. The second one is the Constraints, Standards/ Codes, and Earlier coursework. This chapter shows the project's constraints and how they were overcome. Also, it shows how earlier coursework has been utilized in doing the project effectively. After that, the Literature Review chapter comes. In that chapter, relevant work and results are included. Then, the next chapter which is the Methodology. That chapter explains the hardware components used in the project, the structure of the device, its mechanism of action, and the mobile application’s features. Then, the Results and Analysis chapter contains the final results of working on this project, as well as a discussion of them. The final one is the Conclusion in which you can find the project's summary, things that were learnt, and future work that can be done to the project. 9 2 CONSTRINTS, STANDARDS and EARLIER COURSEWORK 2.1Constraints - One of the constraints was in the sensing part, where we dealt with high frequencies, but the Arduino could not read them. It is correct that using the raspberry pi can help solve this problem, but its price is high. To overcome this problem, we used a frequency divider circuit so the Arduino could read the frequency correctly. - Another constraint was building the wooden parts and designing them. It was difficult to find a carpenter who could precisely make the design we wanted that was full of precise and critical details. So, we had to build them ourselves. - Occasionally, the WIFI connection becomes weak, leading to a slowdown in message transmission. To ensure the messages are sent and received correctly, we implement a mechanism in the code to wait until the transmission is completed successfully. - The reagents required for the defined tests need special care and a specific temperature degree. Also, they expire within a short time and can't be used after that. Our project’s purpose is to implement a process capable of preparing samples for tests, not to take care of reagents and introduce suitable conditions for them. Therefore, we used colored water instead of real reagents. 2.2 Standards/ Codes: - We utilized MQTT as our communication protocol, enabling clients to control the device through a dedicated mobile application. - We used the Arduino IDE to develop our code, enabling us to control the hardware through the Arduino platform. - We used the App Inventor platform to build the mobile application that enables users to control the system. 2.3 Earlier coursework: - We gained a solid foundation in microprocessors and hardware control through the Micro- Controllers course. This knowledge was crucial in controlling the hardware components of our project. - The Critical Thinking and Scientific Research course equipped us with valuable skills in conducting thorough research and writing effective reports. These skills were instrumental in our project's documentation and understanding of its various components. 10 - In the Digital Circuits course and its Lab, we learnt how to work with mini-circuits, which serve as the fundamental building blocks of our project. We gained hands-on experience in wiring them on breadboards and conducting comprehensive testing. - The Network and Wireless courses played a vital role in our project as they provided us with a deep understanding of communication between nodes through wireless protocols. - Lastly, the Arduino course proved invaluable in familiarizing us with the Arduino IDE. This knowledge was essential since we hadn't previously worked with Arduino. Overall, these courses provided us with the necessary knowledge and skills to successfully develop and implement our project. 11 3 LITERATURE REVIEW The project incorporates many aspects that need to be considered. Those aspects mainly include the methodology in which the sensing is to be performed, the 3D-printed parts needed to facilitate certain functionalities, and the principles of the MQTT protocol. Souly Solar Rebuild website has an article that discusses building a capacitive liquid level sensor. It shows an experiment that was conducted using a tank of water and two sheets of aluminum foil covering opposing sides of the tank’s, forming a capacitor. This capacitor is connected to a Schmitt trigger circuit that has a square wave signal as the output. The frequency of the output signal clarifies the liquid’s level in the bucket[2]. Additionally, a 3D-printed design presented by research done at Sorbonne University helped designing a convenient structure to carry the syringe and move its plunger in and out[3]. Furthermore, a tutorial called ‘Transmitting data over WiFi using MQTT’ explained how a connection is established properly using the MQTT protocol. It also gave extensive details stating each step of the process. This tutorial helped connecting the ESP32 with the mobile application adequately[4]. 12 4 METHODOLOGY 4.1 Hardware components Arduino mega: It was used to control the system, receive commands and move other components accordingly. Figure 4. 1: Arduino MEGA 2560 Esp32: It was responsible for holding a connection between the mobile application and the Arduino board. It was capable of communicating with the mobile application through a WIFI connection over the MQTT protocol, and performing a serial connection with the Arduino to ensure a complete transmission of data. Figure 4. 2: ESP32 Stepper motor: Three stepper motors were used. The first one was used with a linear actuator to move the needle up/down. Another one was used to draw in/out substances using the syringe, which was also built based on the linear actuator concept. The last one was used to revolve the disk carrying the reagents in order to get the reagent needed. 13 Figure 4. 3: Stepper motor A4988 driver: Each stepper motor was driven using an A4988 driver. Figure 4. 4: A4988 Driver Servo motor: It controlled the needle’s position as the base of the system is divided into 4 areas. Hence, the servo motor moved the needle into a certain area based on the current state of the system. Figure 4. 5: Servo motor 14 Optocoupler: Five optocouplers were needed. Two were used to restrict the movement of the needle within a certain range. The same idea was applied for the syringe’s movement. The last one was used to reposition the revolving disk into its home position. Figure 4. 6: Optocoupler Electronic valve: The syringe intakes substances through two means based on the current state of the system. It either uses the needle, which is applied in case of trying to add a substance into the reaction cup, or it draws in distilled water using a tube in order to clean the needle. Thus, the valve was used to switch between the needle and the distilled water tube. Figure 4. 7: Electronic valve Relay: It was used to connect the electronic valve with the Arduino board and the 12v power supply. Figure 4. 8: Relay 15 7414 IC (Schmitt trigger): The Schmitt trigger was used alongside a 100pF capacitor and a resistor to implement a circuit capable of sensing the desired substance’s surface. Figure 4. 9: 74HC14 IC Figure 4. 10: 7414 IC schematic 7474 IC (Flip-Flop): Two 7474 ICs were needed to provide 4 D flip-flop gates to implement a frequency divider circuit. Figure 4. 11: 7474 IC Figure 4. 12: 7474 IC schematic 16 4.2 Structure The system comprises 5 parts, which are clearly shown in figures 4.13 and 4.14 Figure 4. 13: System's parts 3 Figure 4. 14: System's parts 4 Part A: It describes the actuator holding the syringe, which moves the syringe’s plunger in and out. It is important to mention the syringe is positioned upside to remove any air that might be in the syringe when first inserted, this process is called priming. Part B: It shows the actuator holding the servo motor that carries the needle around. Part C: It shows the revolving disk that’s responsible for carrying the reagents. 17 Part D: It imitates a rack that has two divisions. On one side it has slots for the sample tubes, on the other side it holds the reaction cups. Part E: It imitates the washing cup which the needle moves towards to clean itself. 4.3 Mobile application interfaces A mobile application was created to make it easy for the user to control the system. This application can communicate with the device wirelessly through WIFI. That was done using the MQTT protocol. Figure 4.3.15 shows the screen that helps the user to choose the action they want. They can perform a new test or control the running test if there is one. Also, they can go to the scheduling section to see the scheduled tests or schedule new ones. Another thing user can do is modify the availability status of the tubes. Figure 4. 15: System control screen 18 The screen in Figure 4.3.16 enables the user to specify the test to be scheduled. A similar one is used to choose the test to be performed now. Figure 4. 16: Test scheduling screen After choosing the test to be performed, the user can start, pause, or terminate that test form the screen shown in Figure 4.3.3 Figure 4. 17: Test control screen 19 If the user chooses to go to the scheduling section, they will be taken to the screen shown in Figure 4.3.18. From this screen, they can choose to schedule a new test or to see the scheduled ones. The screen for the second action is shown in Figure 4.3.19, where the user can delete some of the scheduled tests. Figure 4. 18: Scheduling section screen Figure 4. 19: Show/delete scheduled tests screen 20 The samples and reaction cups will not always be available, so the user needs to tell the system about the available ones. This can be done from the screen shown in Figure 4.3.6 Figure 4. 20: Update tubes' availability screen 4.4 Sensing circuit When the needle moves down a tube, in spite of it being for a sample or a reagent, it is quite essential to make sure the tube is filled with a substance in the first place. Thus, it is important to provide a mechanism to do so. The solution was to build a circuit that would make a change that could be detected by the Arduino once the needle reaches the surface of that substance. Therefore, an implementation of a circuit containing a Schmitt trigger, 100pF capacitor, and a 100k  resistor took place. Under normal conditions, the output signal would have a 1M Hz frequency. However, when another capacitor is connected parallel to the initially positioned one, the frequency will vary. In terms of that, a design imitating a capacitor was made. Since a capacitor by definition refers to two conducting surfaces with a dielectric in between, the designed capacitor had the needle as the first surface, and aluminum foil surrounding the tube as the other end of the capacitor. According to that, when the needle starts to move and hasn’t reached the substance yet, this side 21 of the circuit refers to an open circuit, and the frequency remains unchanged. On the other hand, when the needle encounters the surface of the substance, the surfaces of the capacitor are now connected by the appearance of a dielectric material presented by the substance, which in this case is water. Based on that, the output frequency has to drop down due to the increase of the capacitance at the input. After conducting a few experiments, it was found that the frequency would drop down in about (80-100) K Hz. To make use of that frequency change, it has to be detected by the Arduino. Unfortunately, the Arduino board has limitations over the frequencies it can comprehend. In order to overcome this issue, a frequency divider circuit can be built. One way to implement a frequency divider is by the use of D Flip-flops. This circuit takes the frequency of the sensing circuit as an input, and sends its output frequency to the Arduino board in lower ranges that it can comprehend. Figure 4. 21: Sensing circuit 4.5 Mechanism of action The needle rotates automatically towards the desired substance using a servo motor, then moves down using a stepper motor until it senses the substance, which is done through the circuit built using the Schmitt trigger. Afterwards, the syringe draws in the required amount for the selected test as the needle moves the needed distance in the substance. Then, the syringe expels the carried amount into a reaction cup. System states: Initialization: The instant the system is turned on, all components have to maintain their home positions. As a result, the needle moves up until it’s detected by the optocoupler placed at its home position. The 22 revolving disk also has slots defined into indices. In order to ensure proper access to the reagents in those slots, a reference point is defined using an optocoupler. The disk revolves anti-clockwise until the optocoupler emits a signal stating that each slot is correctly positioned relative to the reference point. Afterwards, the servo motor rotates the needle until it reaches the cleaning area. In this area, the needle moves down towards the washing cup, and the syringe moves upwards to expel any substance that could have been stuck in the needle from former tests, then, it moves into the cleaning state. Cleaning: This state is entered after the initialization as well as during the tests after carrying any substance to prevent contamination. Basically, an electronic valve works alongside the syringe to flush distilled water through the needle to clean it on the inside, which, in its turn, causes a splash that cleans the outside of the needle, ensuring proper sanitation. Substance selection: At the beginning, the servo motor will rotate the needle until it reaches the targeted sample, withdraws a specific amount of it. Then, the servo motor will move the needle to a designated reaction cup where it will dispense the withdrawn sample. After that, the needle will start adding the required reagents. Since multiple reagents are used, they are positioned on a rotating disk. A stepper motor is responsible for rotating the disk precisely the required number of steps, aligning the desired reagent underneath the needle. 23 5 Results and discussion The system was able to accurately prepare the final sample to be tested. This was done by automatically adding the required amount of each reagent, and performing the cleaning process after each addition to ensure that the chemical substances aren’t contaminated. It also allows users to control the test being processed after choosing it. Furthermore, it allows the user to schedule up to 4 tests to be performed. These features are available using a friendly GUI through a mobile app. In the sensing circuit, it was found out that the best value for the capacitor is 100pF. Other values wouldn’t not cause a good noticeable difference in the frequency when the needle reaches the substance's surface. However, due to the susceptibility of the sensing circuit, the frequency value sometimes changes for an instant then goes back to its former state. This might give a false indicator that the needle has reached the substance, even though, it actually hasn’t. In order to overcome this issue, when such a sudden change occurs, the Arduino has to make sure that the frequency has changed because the needle has reached the substance. This was done by getting the Arduino to measure the frequency repeatedly over a short period to ensure that the frequency has maintained its new value, and it’s not just a false alarm. To ensure the accurate addition of reagents, it was essential to position the syringe's plunger at the precise distance required. As previously mentioned, the plunger is controlled by the rotation of a stepper motor. However, when determining the number of steps needed for the stepper motor to draw in a specific amount of liquid, there may be a situation where a fractional step remains, making it impossible to achieve a precise volume extraction. To address the issue, the error resulting from this issue was minimized to the point the maximum fraction left does not exceed half a step using the software code. This means that if a loss or excess were to exist, it won’t be more than 0.003 ml, taking into account that a complete step from the stepper causes the drawing of 0.12 ml based on the used actuator. 24 6 Conclusion In conclusion, the ASPS improves laboratory testing. We were able to build a system that could enhance the reliability, safety, and efficiency in both analytical chemistry and medical fields. 6.1 What we have learnt: 1. Using Arduino to control our system. 2. Applying the MQTT protocol using ESP32. 3. Using new components and connect them together to build our system. 4. Building a full design hardware and software. 6.2 Future work: 1. Provide the ability to schedule more tests. 2. Enhance the frequency reading mechanism. 3. Make it adaptable to actual reagents and samples and provide temperature serving sources. 4. Provide substances scanning method. 5. Identify items based on their frequency to ensure no errors. 25 References [1] Mrazek, C., Lippi, G., Keppel, M. H., Felder, T. K., Oberkofler, H., Haschke-Becher, E., &Cadamuro, J. (2020). Errors within the total laboratory testing process, from test selection to medical decision-making - A review of causes, consequences, surveillance and solutions. Biochemia medica, 30(2), 020502. https://doi.org/10.11613/BM.2020.020502 [2] Capacitive Liquid Level Sensor « Souly Solar Rebuilds. (n.d.). Capacitive Liquid Level Sensor &Laquo; Souly Solar Rebuilds. https://soulysolar.mudventions.com/?p=681 [3] Transmitting data over WiFi using MQTT. (n.d.). Transmitting Data Over WiFi Using MQTT. https://www.tutorialspoint.com/esp32_for_iot/esp32_for_iot_transmitting_data_over_wifi _using_mqtt.htm [4] Syringe Pump Project — Jieyeon Woo. (n.d.). Jieyeon Woo. https://www.jieywoo.com/projects-research/syringe-pump-project https://doi.org/10.11613/BM.2020.020502 https://www.tutorialspoint.com/esp32_for_iot/esp32_for_iot_transmitting_data_over_wifi_using_mqtt.htm https://www.tutorialspoint.com/esp32_for_iot/esp32_for_iot_transmitting_data_over_wifi_using_mqtt.htm Acknowledgment Disclaimer List of figures Nomenclature Abstract 1 INTRODUCTION 1.1 Statement of the problem 1.2 Objective 1.3 Scope of the work 1.4 Significance of the work. 1.5 Organization of the report 2 CONSTRINTS, STANDARDS and EARLIER COURSEWORK 2.1Constraints 2.2 Standards/ Codes: 2.3 Earlier coursework: 3 LITERATURE REVIEW 4 METHODOLOGY 4.1 Hardware components 4.2 Structure 4.3 Mobile application interfaces 4.4 Sensing circuit 4.5 Mechanism of action 5 Results and discussion 6 Conclusion 6.1 What we have learnt: 6.2 Future work: References