In our system, we will use an RS385 water pump motor and water pipes to pump water from the hot and cold water tanks into the main tank.. An HC-SR04 ultrasonic sensor will be placed in t
Trang 1VIETNAM NATIONAL UNIVERSITY UNIVERSITY OF ENGINEERING AND TECHNOLOGY
Automated Water Temperature and
Level Control System
Course: Mechatronics Systems
Class number: EMA3083_1
Lecturer: Prof Dinh Tran Hiep
Group members:
Tran Van Giang
Nguyen Xuan Duc
Nguyen Quang Duc
Trang 2Hanoi, Hanoi, May 2025
Trang 3B - Modeling a process stage 11
2 Mathematical model of the disturbance on the proposed stage? 12
C - Experimental and Results 18
D - Evaluation of the System 30
1 Evaluations of the system's successful features 30
E - System development proposal 30
Trang 4A - Overview of system
1 Introduction
The water temperature control system using mechanical control is an effective solution in many applications, especially in systems that require stable and automatic temperature adjustment This system primarily operates based on mechanical components such as thermal valves, mechanical thermostats, and heat exchangers to maintain the water temperature within a defined range For example, when the water temperature exceeds the allowed limit, thermal valves or mechanical thermostats will automatically intervene to reduce the temperature, stop heating, or open the cooling valves, helping to stabilize the water temperature Mechanical control in water temperature control systems is often combined with temperature sensors to accurately monitor and provide feedback on the water’s temperature
In our system, we will use an RS385 water pump motor and water pipes to pump water from the hot and cold water tanks into the main tank The L298N motor driver will be used to control the amount of water entering the main tank An HC-SR04 ultrasonic sensor will be placed in the main tank to monitor the water level Each tank will be equipped with a DS18B20 temperature sensor to monitor the temperature of each individual tank Additionally, a water heating element will be installed in the hot water tank to heat the water The entire system will be measured and analyzed using an Arduino platform
Trang 5Figure A.1:Actual finished product.
2 Structure
2.1 List of Equipments
Equipment Quantity Note Image
Arduino UNO R3 1 Main module
Trang 6Ultrasonic sensor HC-SR04 1 Monitors the water level
in the main tank.
Temperature sensor
DS18B20
2 Measure the water
temperature in each tank.
Water pump motor RS385
2 Controls the operation
and flow rate of the pumps.
Module relay 5V 1 Switching the
Immersion Heater on and off
Trang 7Immersion Heater 220VAC 1 Boiling Water
Switching mode Power
Supply ( 12V-5A Z)
1 Provide a stable 12V
power supply for the water pump, water heater (if 12V type), microcontroller, and other components
Water pipe 7m 1 Water transfer between
components
The automatic water pumping system consists of a VCC power source that supplies electricity to three pumps: the hot water pump, the drain pump, and the cold water pump These pumps are connected to three tanks: the hot water tank, the main tank, and the cold water tank The main tank is additionally equipped with a SONAR water level sensor, while all three tanks are equipped with DS18B20 temperature sensors to monitor the water temperature
The flow directions in the system are indicated by arrows: red for pumping and blue for suction The hot water pump draws water from the hot water tank and transfers it
to the main tank; the cold water pump draws water from the cold water tank to the main tank; and the drain pump draws water from the main tank to discharge it outside Another pipeline connects the main tank to the drain pump and passes through the cold water tank, so that when the main tank reaches a set water level, the drain pump can transfer the excess water back into the cold water tank Additionally, there is a pipeline from the cold water tank to the hot water tank,
Trang 8allowing water to be transferred for reheating and supplying hot water to the main tank when needed
This setup enables the system to flexibly adjust the temperature and volume of water according to different operating conditions The SONAR sensor in the main tank continuously monitors the water level to automatically control the pumps, ensuring the tank neither overflows nor runs dry Thanks to the integration of sensors and well-designed cross-piping, the entire process of supplying hot water, cold water, and discharging excess water operates fully automatically, continuously, and energy-efficiently
Figure A.2: Illustration of the system's structure.
2.2 Technical Specifications of the Components
2.2.1 Ultrasonic sensor HC-SR04
The water in the tank can overflow in the mixing water process so we use Ultrasonic Sensor HC-SR04 to control water level in the tank The table below illustrates the technical specifications of this sensor:
Output Signal Electrical frequency signal with 5V high level and
Trang 9+ Active the sensor by sending a high-level signal for 10μs
+ The module will automatically emit eight 40kHz square wave pulses and detect whether any echo signal in received
+ If an echo is detected, the sensor returns a high-level signal Based on the time interval between triggering the sensor and receiving the echo signal, the distance can be calculated
2.2.2 Temperature sensor DS18B20
Sensor DS18B20 is used to measure the temperature of water in the hot tank and mix tank The measured values sent from the sensor help adjust the control signal for the pumps And, the technical specifications of this sensor were described in the table:
Measurement Range -55 ~ 125oC (-67 ~ 257 oF)
Measurement Error ±0.5oC (In range -10 ~ 85oC)
Maximum Temperature
Conversion Time
750ms (In 12 Bits Resolution)
Stainless Steel Tube Diameter: 6mm; Length: 50mm
Trang 102.2.3 Water pump motor RS385 12V
The technical specifications of Water pump motor RS385:
Pump Inlet/Outlet Diameter Inner diameter: 6mm
Outlet diameter: 8.5mm
2.2.4 Motor control driver L298N
Motor control driver L298N is used to control the pump in the system The table below highlights the technical specifications of Motor control driver L298N:
High: 2.3 ~ Vss
Trang 11Control Input Signal:
* Signal = 0 : Relay is ON (closed)
* Signal = 1 : Relay is OFF (open) Output Relay Contacts: 220V 10A (It is not output voltage)
NC (Normally Closed)
NO (Normally Open) COM (Common) Power Pin Labels VCC, GND: Power supply for relay
IN: Control signal pin 2.2.6 Immersion Heater 220VAC
To ensure a stable supply of hot water, we use Immersion Heater 220VAC in the hot tank
The technical specifications are illustrated in this table:
Trang 123 Operating Principle
At the beginning of each process, when the system starts up, the HC-SR04 ultrasonic sensor will measure the water level in the tank and determine if it is below 2 cm The water pumped out at this stage will be directed into the hot water tank Once the condition of the water level being below 2 cm is met, the hot water circulation system will start operating to heat the water in the hot tank When the water in the hot tank reaches the required temperature, the system will proceed with the following steps:
Step 1: Initialization
· All motors and relays are set to their initial states (e.g., R1: Off)
Step 2: Check the temperature t1
· Compare t1 with tset1:
o If t1 ≤ tset1: Relay R1 remains Off → return to continue checking
o If t1 > tset1: Relay R1 turns On, allowing water temperature adjustment
Step 3: Check the temperature t2
· Compare t2 with tset2:
Step 4: Control the water level in the tank
· Compare h0 with hset:
o If h0 = hset: Both mT1 and mT3 are Off (no water is pumped in
or drained out)
Trang 13o If h0 < hset: More water needs to be added — the system continues or the external pump motor is activated to add water (not shown in this diagram)
o If h0 > hset: Turn On the external water pump motor (mT3 On)
to drain excess water and prevent overflow
Step 5: End of the Cycle
· When all temperature and water level conditions meet the requirements, the system ends its operation cycle
Figure A.3: Flowchart system
B - Modeling a process stage
1 Mathematical modeling of the proposed stage
To accurately model the DS18B20 temperature sensor in a water temperature control system, we consider the sensor's dynamic response and systematic measurement bias The DS18B20 is a digital temperature sensor that communicates via the 1-Wire protocol, offering 12-bit resolution and a conversion time of approximately 750 ms This time delay causes a lag in the sensor’s response, so that
Trang 14the measured temperature Tm(t) gradually approaches the actual ambient temperature Ta(t) rather than reflecting it instantly
To capture this behavior, the sensor is modeled as a first-order dynamic system:
Here, τ=0.75 sis the time constant, chosen based on the sensor's conversion delay and experimental response time
In addition, the sensor is subject to a systematic error due to its placement, such as the distance from the ideal measurement point This bias is modeled as a quadratic function of distance d (in cm):
This term represents a fixed offset in the measured value Incorporating this bias, the complete model becomes:
This equation reflects both the sensor’s delayed response and the measurement offset due to positioning It is particularly useful in the context of water temperature control, where accurate sensing is essential for effective feedback regulation The plot below demonstrates how the measured temperature responds to a step change in the ambient temperature, accounting for the dynamic delay and position-based bias
2 Mathematical model of the disturbance on the proposed stage?
In the process of measuring temperature using sensors in real-world environments, noise (error) is inevitable due to various factors such as sensor placement, heat transfer in the fluid, or non-uniform sensor sensitivity The team decided to model the error spatially within the tank The experiment was designed by measuring the error at different positions in a cylindrical tank (17 cm in diameter, 16.5 cm water height) The team defined a coordinate system, taking the sensor position at the suction tube as the origin (0,0,0) From there, sensors were placed at various locations in the tank and their coordinates were recorded
Instead of using multivariable regression with spatial coordinates (x, y, z), the model
Trang 15was simplified by converting all positions to a single input variable: the distance from the measurement point to the origin This approach reduces the number of input variables and helps prevent overfitting
The tank was divided into five horizontal layers, since the water height is 16.5 cm each layer separated by 4 cm In each layer, measurements were taken at five spatial points: one at the center (coordinates x = 7.5, y = 0), and four symmetrically placed near the tank wall This results in five measurement points per layer Excluding the origin point, a total of 24 survey points were used
At each survey point, temperature measurements were taken 100 times consecutively, and the average error was recorded With 24 symmetrically distributed points representing different regions within the tank, a mathematical model can be effectively developed to reflect the error pattern This structure also helps to reveal error trends based on distance and depth without requiring dense measurements throughout the entire space
Figure B.1: Illustration of the experimental setup for noise measurement.
The collected data was subsequently used to develop mathematical models describing the error as a function of distance, including quadratic regression, logarithmic regression, and exponential regression These models were evaluated based on the Root Mean Square Error (RMSE) metric, which quantifies the average magnitude of the prediction errors The model with the lowest RMSE was selected
as the most suitable for calibrating the sensors within the system
Trang 16Figure B.2: Collected data
Figure B.3: Collected data
Trang 17Figure B.4: Table of error values by coordinates and distance
Regression plot and RMSE:
Trang 18Figure B.5: Quadratic regression
Figure B.6: Logarithmic regression
Trang 19Figure B.7: Exponential Regression
Based on the analysis of three regression models quadratic, logarithmic, and exponential we evaluate the effectiveness of each model using the Root Mean Square Error (RMSE) metric The results indicate:
● Quadratic regression has the lowest RMSE (≈ 0.00511), suggesting it fits the actual data best The quadratic regression curve passes smoothly and accurately through the data points, indicating a high degree of conformity with the trend of sensor error variation relative to distance
● Exponential regression has the second-lowest RMSE (≈ 0.00893) While still acceptable, its fit to the data is inferior to the quadratic model
● Logarithmic regression has the highest RMSE (≈ 0.01538), indicating it is unsuitable for modeling the error distribution within the tank
Therefore, the quadratic regression model is the optimal choice in this case, as it not only has the lowest prediction error but also accurately reflects the relationship between distance and sensor error, thereby enhancing measurement performance in practical applications
Trang 20C - Experimental and Results
1 Experimental Process
The main objective is to determine the temperature each time water is pumped into a phase of the main tank Accordingly, the experiment uses an Arduino to read analog data from the DS18B20 temperature sensor, while simultaneously measuring the current water level in the main tank using the HC-SR04 ultrasonic sensor to prevent the tank from overflowing
The temperature output is calculated by the following formula:
T(t) = Tin + (T0 - Tin)e−𝑄𝑉 𝑡
In which:
T(t): Temperature in the tank at time t (°C
T0: The Initial temperature in the tank (°C) – at the beginning of mixing and calculated by:
T0= 𝑚ℎ*𝑇ℎ+𝑚𝑐*𝑇𝑐𝑚ℎ+𝑚𝑐
Tin: Average temperature of the hot and cold water mixture being pumped in
Tin= 𝑄ℎ*𝑇ℎ+𝑄𝑐*𝑇𝑐𝑄ℎ+𝑄𝑐 (°C)
Q: Total flow rate of water being pumped in (liters/second) = 𝑄 + 𝑄𝑐
V: Tank capacity (liters)
t: Time elapsed since the start of mixing (seconds)
mh: Weight of hot water pumped in
Th: Temperature of Hot water
mc: Weight of cool water pumped in
Tc: Temperature of Cool water
Qh: Hot water flow rate
Qc: Cool water flow rate
Trang 21The data is measured by an Arduino More specifically, the measured data includes various fields (e.g., Temperature, Date, etc.) The Arduino is responsible for sending data after each cycle of 100 measurements, with a 100 ms interval between each measurement The data is organized by fields and connected to the system to control the pumps accordingly.The system response is illustrated in the diagram below
Figure C.1 System response
For the characteristic graph verification,the water in the tank is measured 100 times during each operational phase of the system until the process completes, and the system's settling time is recorded This is done to verify whether the water has reached the desired temperature and to determine the optimal way to use the sensor
in the application
Based on physical properties and experimental observations, it is evident that when water is mixed in the tank, convection occurs, and it takes time for the heat to distribute throughout the water Therefore, the temperature sensor’s readings can be affected by its placement and by measurement delays As a result, more detailed studies on temperature noise were conducted by positioning the sensor at different locations within the tank
The data is stored in separate cells in google sheet and analyzed in MATLAB For each water mixing event into the main tank, 100 consecutive temperature measurements are recorded To clearly observe the trend, a scatter plot is utilized The collected data is analyzed using various regression plots, including quadratic, logarithmic, and exponential regressions
The data is evaluated based on several criteria: measured temperature versus desired temperature, error relative to the setpoint, stability of the temperature sensor, among others Additionally, the system's operational range is tested Finally, the response trend of the temperature sensor in adjusting pump power is emphasized and analyzed, with sensor placement positions evaluated and selected for optimal application