0% found this document useful (0 votes)
2 views16 pages

Control Engineering Report

The document outlines the design and implementation of an Arduino-based automated water level control system utilizing a PID controller, aimed at improving efficiency and reducing resource waste in fluid management. It details the integration of ultrasonic sensing, a relay module for pump control, and a manual override feature, alongside a comprehensive analysis using MATLAB/Simulink for simulation and validation. The report includes problem statements, system design, flow diagrams, mathematical modeling, and performance evaluations through various graphical representations.

Uploaded by

huzaifariasatm
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views16 pages

Control Engineering Report

The document outlines the design and implementation of an Arduino-based automated water level control system utilizing a PID controller, aimed at improving efficiency and reducing resource waste in fluid management. It details the integration of ultrasonic sensing, a relay module for pump control, and a manual override feature, alongside a comprehensive analysis using MATLAB/Simulink for simulation and validation. The report includes problem statements, system design, flow diagrams, mathematical modeling, and performance evaluations through various graphical representations.

Uploaded by

huzaifariasatm
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Arduino-Based Automated Water Level Control System

With PID Controller

Control Engineering (ME-332)


Submitted by:
Hafsa Naveed Iqbal 23-ME-06
Abdullah Zia 23-ME-26

Ubaid Ullah 23-ME-30


Jawad Ul Hassan Alvi 23-ME-34
Syed Nouman Shah 23-ME-42
Zohaib-Ul-Hassan 23-ME-58

Muhammad Huzaifa Aftab 23-ME-74


Anas Awan 23-ME-86
Huzaifa Riasat 23-ME-158

Raaid Rauf 23-ME-166


Muhammad Ahmad Raza 23-ME-178
Ahsan Bashir 23-ME-202

Imran Ullah 23-ME-214

Section B
Submitted to:
Dr. Sajjad Sabir

Department of Mechanical Engineering


University of Engineering & Technology Taxila, Pakistan
Table of Contents
1 Problem statement .............................................................................................................. 4
2 Introduction: ....................................................................................................................... 4
2.1 Overview of the Control System: .............................................................................. 4
3 Scope of the Report:........................................................................................................... 5
3.1 Flow Diagram: ........................................................................................................... 5
4 Block diagram Reduction .................................................................................................. 7
5 Simulink model .................................................................................................................. 9
6 Code ................................................................................................................................... 9
7 Graphs .............................................................................................................................. 11
7.1 Simulink output graph.............................................................................................. 11
7.2 Bode plot .................................................................................................................. 12
7.3 Root locus points...................................................................................................... 12
8 Discussion ........................................................................................................................ 13
8.1 Graphical observation .............................................................................................. 13
8.2 Derivations ............................................................................................................... 13
8.2.1 The Controller (PID) ........................................................................................ 13
8.2.2 Water Pump ...................................................................................................... 14
8.2.3 The Plant (Water Tank) .................................................................................... 15
9 Conclusions ...................................................................................................................... 16
List of Figures
Figure 1 Physical Apparatus of the Automated Water Level Control System ........................... 5
Figure 2 Flow Diagram of the Proposed Automatic Water Level Control System .................... 6
Figure 3 Physical Block Diagram of the Water Level Control System ..................................... 7
Figure 4 Mathematical Block Diagram Used for Transfer Function Derivation ....................... 7
Figure 5 Reduced Closed-Loop Transfer Function of the System ............................................. 8
Figure 6 Simulink Model of the Closed-Loop Water Level Control System ............................ 9
Figure 7 Simulink Step Response of the Water Level Control System ................................... 11
Figure 8 Open-Loop Bode Plot of the Water Level Control System ....................................... 12
Figure 9 Root Locus of the Water Level Control System ........................................................ 12
1 Problem statement
Manual fluid level management leads to resource waste, pump degradation, and operational
inefficiencies. The objective of this project is to design, simulate, and validate an automated
water level control system using an Arduino-based physical prototype and MATLAB/Simulink
modeling. By integrating ultrasonic sensing, hysteresis logic, and a manual override, this
project aims to achieve precise control stability while analyzing real-time performance data
and theoretical responses for industrial applications.

2 Introduction:
Liquid level control has extensive applications across various industries, including food and
beverage production, chemical processing, and power generation plants. To investigate and
optimize such control systems, this project develops a dual-approach control mechanism,
combining a physical hardware prototype with mathematical modeling and simulation in
MATLAB/Simulink.
The physical control mechanism utilizes a non-contact ultrasonic level sensor (HC-SR04),
which accurately measures the actual liquid depth and converts it into a digital signal. A 5V
relay module is employed as the actuator to safely toggle the heavy-duty water pump. To ensure
user interaction and system transparency, an I2C LCD is integrated to display real-time water
percentages and pump status. Furthermore, a physical push-button switch is incorporated into
the circuit, serving as a critical Auto/Manual override. This allows operators to bypass the
microcontroller for safe maintenance or emergency manual control, bridging the gap between
full automation and essential human supervision.

2.1 Overview of the Control System:


This project is an automatic and safe water tank controller designed to replace manual
monitoring. We used an Arduino microcontroller as the "brain" and an ultrasonic sensor as the
"eyes" to check the water level without physically touching the water. If a normal sensor sees
water splashing, it will turn the heavy pump on and off rapidly, which can quickly burn out the
pump's motor. To fix this, we programmed a smart rule: the pump only turns ON when the
water drops below 19% and completely turns OFF when it reaches 95%.
For human safety and convenience, we added an LCD screen so anyone can easily read the
current water percentage. More importantly, we included a physical Auto/Manual button. If a
person needs to clean the tank or stop the system in an emergency, they can press this button
to take control away from the automatic brain. Finally, to prove that our hardware idea is
mathematically correct and stable, we made a digital copy of the system in MATLAB and
Simulink software. We used this software to draw step response graphs and test control math,
showing that our water tank fills up smoothly and safely in all conditions.
Figure 1 Physical Apparatus of the Automated Water Level Control System

3 Scope of the Report:


The scope of this report is to provide a comprehensive solution to the problem statement by
bridging a physical hardware prototype with theoretical software analysis. The report includes
the flow diagram of the automated controlled system, mathematical transfer function
derivations, theoretical background, and block diagram reduction. Furthermore, it incorporates
the MATLAB/Simulink model used to simulate the task, alongside step-response graphs that
interpret the transient performance and overall stability of the system.

3.1 Flow Diagram:


The closed-loop water control system implemented in this project includes the following
components:
START

Initialize parameters
target =20cm

YES
NO
Mode (Auto)

Press manual mode


button

Sensor measure level


NO

YES Is push button


Do Nothing
NO pressed
Level< 19%

YES

Pump on
Pump
start

Level >95% YES

NO Turn off the


pump

Hold current state

Return to the system

Figure 2 Flow Diagram of the Proposed Automatic Water Level Control System
4 Block diagram Reduction
To derive the Simulink transfer function, we use the block diagram reduction method for our
closed-loop negative feedback system. The user sets a 8 target water level of 20 cm. The HC-
SR04 sensor continuously measures the actual depth, allowing the Arduino to calculate the
error. Based on this error, the PID algorithm triggers a 5V relay to activate the submersible
pump. As the water approaches 20 cm, the PID's integral and derivative actions damp the
response, eliminate steady-state error, and stop the pump exactly at the target to prevent
overflow.
To make this entire process easy to understand, the figure below shows a simple visual layout
of how these components are connected.

R(s) Controller pump Tank C(s)

Sensor

Figure 3 Physical Block Diagram of the Water Level Control System

This block diagram shows the mathematical representation of the water level control system.
The PID controller, water pump, storage tank, and sensor are modeled using transfer functions
and connected to form a closed-loop control system for analysis in MATLAB/Simulink.

𝐾𝑖
Controller:𝐺𝑐 (𝑠) = 𝐾𝑝 + + 𝐾𝑑 𝑠
𝑠

Pump: 𝐺𝑝 (𝑠) = 𝐾𝑝𝑢𝑚𝑝

1
Tank: 𝐺𝑇 (𝑠) = 𝐴𝑠

Sensor: 𝐻(𝑠) = 𝐾𝑠

R(s) 𝐺𝑐 (𝑠) = 𝐾𝑝 +
𝑘𝑖
+ 𝐾𝑑 𝑠
𝐺𝑝 (𝑠) = 𝐾𝑝𝑢𝑚𝑝 𝐺𝑇 (𝑠) =
1
𝐴𝑠 C(s)
𝑠

𝐻(𝑠) = 𝐾𝑠

Figure 4 Mathematical Block Diagram Used for Transfer Function Derivation


To accurately reflect our physical hardware setup, these specific empirical values were assigned
to the mathematical model:
• PID Controller(𝑲𝒑 = 𝟐, 𝑲𝒊 = 𝟎. 𝟎𝟓, 𝑲𝒅 = 𝟎. 𝟎𝟏): A lower proportional gain (𝐾𝑝 =
2) was specifically selected so that the pump does not fill the tank too aggressively.
This prevents sudden overshoot and ensures the water level stabilizes smoothly without
overflowing.
• Tank Constant (147.33): This represents the actual cross-sectional area of our
cylindrical tank. It was physically calculated using the formula 𝐴 = 𝜋𝑟 2 ,where the
measured inside radius of our tank is 6.85 cm (i.e.,3.14 × (6.85)2 = 147.33 cm2 ).
• Sensor Feedback (H(s)=1): The ultrasonic sensor directly measures the true water
level without any scaling, thus acting as a pure unity feedback loop.
Substituting these justified values gives us the following transfer functions

R(s) 𝐺𝑐 (𝑠) = 2 +
0.05
𝑠
+ 0.01𝑠 𝐺𝑝 (𝑠) = 8.33 𝐺𝑇 (𝑠) =
1
78.5𝑠 C(s)

𝐻(𝑠) = 1

Figure 5 Reduced Closed-Loop Transfer Function of the System

𝐺(𝑠) = 𝐺𝑐 (𝑠) × 𝐺𝑝 (𝑠) × 𝐺𝑇 (𝑠)

0.05 1
𝐺(𝑠) = (2 + + 0.01𝑠) × (8.33) × ( )
𝑠 147.33𝑠

0.0833𝑠 2 + 16.66𝑠 + 0.4165


𝐺(𝑠) =
147.33𝑠 2
Now for solving for the feedback

𝐶(𝑠) 𝐺(𝑠)
=
𝑅(𝑠) 1 + 𝐺(𝑠)𝐻(𝑠)

0.0833𝑠 2 + 16.66𝑠 + 0.4165


= 147.33𝑠 2
0.0833𝑠 2 + 16.66𝑠 + 0.4165
1+[ ] (1)
147.33𝑠 2
𝐶(𝑠) 0.0833𝑠 2 + 16.66𝑠 + 0.4165
=
𝑅(𝑠) 147.33𝑠 2 + 16.66𝑠 + 0.4165

So, by using simple block diagram rules, we combined the pump, tank, and sensor into one
single formula. After that, we put this final equation into our real Simulink software to test how
it works with the PID controller.

𝐶(𝑠) 0.0833𝑠 2 + 16.66𝑠 + 0.4165


R(s) = C(s)
𝑅 (𝑠) 147.33𝑠 2 + 16.66𝑠 + 0.4165

After that, we put this final equation into our real Simulink software to test how it works with
the PID controller.
5 Simulink model
This Simulink model represents our closed-loop water level control system. The Step input sets
the 20 cm target, while the summing junction calculates the error using real-time sensor
feedback. The PID controller uses this error to regulate the pump, filling the tank smoothly.
Finally, the system's performance is visualized on the Scope block.

Figure 6 Simulink Model of the Closed-Loop Water Level Control System

6 Code
clc; y = 50;
clear; dx = 130;
close all;
%% STEP INPUT (20 cm Setpoint)
%% CREATE SIMULINK MODEL add_block('simulink/Sources/Step',...
model = 'WaterLevel_PID_System'; [model '/Step'],...
new_system(model); 'Position',[x y x+30 y+30]);
open_system(model);
set_param([model '/Step'],...
%% BLOCK POSITIONS 'Time','0',...
x = 30; 'Before','0',...
'After','20'); add_line(model,'Tank/1','Sum/2');

%% SUM BLOCK %% SIMULATION SETTINGS


add_block('simulink/Math set_param(model,'StopTime','300');
Operations/Sum',...
[model '/Sum'],... save_system(model);
'Inputs','+-',...
'Position',[x+dx y x+40+dx y+40]); %% RUN SIMULATION
sim(model);
%% PID CONTROLLER
add_block('simulink/Continuous/PID %% CONTROL SYSTEM ANALYSIS
Controller',... s = tf('s');
[model '/PID'],...
'Position',[x+2*dx y-10 x+70+2*dx Kp_pid = 2;
y+50]); Ki_pid = 0.05;
Kd_pid = 0.01;
set_param([model '/PID'],...
'P','2',... Kpump = 8.33;
'I','0.05',... A = 147.33;
'D','0.01');
%% Plant Transfer Function
%% PUMP GAIN G = Kpump/(A*s);
add_block('simulink/Math
Operations/Gain',... %% PID Controller Transfer Function
[model '/Pump'],... C = Kp_pid + Ki_pid/s + Kd_pid*s;
'Gain','8.33',...
'Position',[x+3*dx y x+50+3*dx y+40]); %% Open-Loop Transfer Function
G_OL = C*G;
%% WATER TANK TRANSFER
FUNCTION %% Closed-Loop Transfer Function
add_block('simulink/Continuous/Transfer T = feedback(G_OL,1);
Fcn',...
[model '/Tank'],... %% STEP RESPONSE (20 cm Input)
'Numerator','[1]',... figure;
'Denominator','[147.33 0]',... step(20*T,300)
'Position',[x+4*dx y x+90+4*dx y+50]); title('PID Closed-Loop Step Response')
xlabel('Time (seconds)')
%% SCOPE ylabel('Water Level (cm)')
add_block('simulink/Sinks/Scope',... grid on
[model '/Scope'],...
'Position',[x+5*dx y x+60+5*dx y+40]); %% BODE PLOT
figure;
%% CONNECTIONS bode(G_OL)
add_line(model,'Step/1','Sum/1'); title('Open-Loop Bode Plot')
add_line(model,'Sum/1','PID/1'); grid on
add_line(model,'PID/1','Pump/1');
add_line(model,'Pump/1','Tank/1'); %% ROOT LOCUS
add_line(model,'Tank/1','Scope/1'); figure;
rlocus(G_OL)
%% FEEDBACK LOOP title('Root Locus')
grid on
disp('Closed-Loop Poles:')
%% SYSTEM INFORMATION pole(T)
disp('==========================
============') disp('==========================
disp('Closed-Loop Transfer Function:') ============')
T disp('Simulation Completed Successfully')
7 Graphs
Run the MATLAB commands provided in Section 4.2 to generate the following three graphs.
Each graph is described below with its expected characteristics and engineering interpretation.
Insert the corresponding MATLAB screenshot in each subsection.

7.1 Simulink output graph

Figure 7 Simulink Step Response of the Water Level Control System


7.2 Bode plot

Figure 8 Open-Loop Bode Plot of the Water Level Control System

7.3 Root locus points

Figure 9 Root Locus of the Water Level Control System


8 Discussion
8.1 Graphical observation

The Root Locus analysis confirms that all closed-loop poles reside strictly within the left-half
of the s-plane along the negative real axis, establishing absolute mathematical stability for all
positive controller gains. The resulting overdamped transient response achieves the 20 cm
target with a settling time of approximately 236 seconds and zero percent overshoot, entirely
eliminating the risk of water overflow during operation.

The Bode plot further corroborates this stability, revealing a phase margin of 90° and an infinite
gain margin — both substantially exceeding classical control theory thresholds. These stability
reserves confirm that the system can accommodate parametric uncertainties arising from pump
variations, tank geometry, and HC-SR04 sensor disturbances without compromising steady-
state accuracy. Collectively, these results validate that the PID controller (Kp = 2, Ki = 0.05,
Kd = 0.01) delivers a stable, robust, and reliable water level regulation system across a wide
range of operating conditions.

8.2 Derivations
Having established the overall block diagram of the water level control system, it is essential
to understand the mathematical model behind each block. The following section provides the
fundamental derivations for the transfer functions of the PID Controller, the Pump, the Water
Tank, and the Ultrasonic Sensor.
8.2.1 The Controller (PID)
The control effort in the closed-loop system is governed by a Proportional-Integral-Derivative
(PID) algorithm. The controller continuously calculates an error signal 𝑒(𝑡)as the difference
between the desired target setpointℎ𝑟𝑒𝑓 (𝑡) and the actual measured water level ℎ(𝑡):

𝑒(𝑡) = ℎ𝑟𝑒𝑓 (𝑡) − ℎ(𝑡)


The time-domain control effort, u(t) generated by the PID controller to drive the pump is
expressed as the sum of three distinct terms:

𝑡
𝑑𝑒(𝑡)
𝑢(𝑡) = 𝐾𝑝 𝑒(𝑡) + 𝐾𝑖 ∫ 𝑒 (𝜏)𝑑𝜏 + 𝐾𝑑
0 𝑑𝑡
where𝐾𝑝 , 𝐾𝑖 , 𝑎𝑛𝑑 𝑘𝑑 are the proportional, integral, and derivative tuning gains, respectively.
Since the controller operates directly on the error signal (which inherently represents a
deviation from the desired state), we can directly apply the Laplace transform to the time-
domain equation. Assuming initial conditions are zero (e (0) = 0), the transformation yields:

𝐾𝑖
𝑈(𝑠) = 𝐾𝑝 𝐸(𝑠) + 𝐸(𝑠) + 𝐾𝑑 𝑠𝐸(𝑠)
𝑠
Factoring out E(s), we obtain the standard parallel-form transfer function of the PID controller:

𝑈(𝑠) 𝐾𝑖
𝐺𝑐 (𝑠) = = 𝐾𝑝 + + 𝐾𝑑 𝑠
𝐸(𝑠) 𝑠

To implement this into the Simulink model as a single rational transfer function block, we find
the common denominator s, which results in the ideal PID polynomial form:

𝐾𝑑 𝑠 2 + 𝐾𝑝 𝑠 + 𝐾𝑖
𝐺𝑐 (𝑠) =
𝑠
Based on the precise tuning parameters established for this system the final derived transfer
function for the controller is:

0.01𝑠 2 + 2𝑠 + 0.05
𝐺𝑐 (𝑠) =
𝑠

8.2.2 Water Pump


The submersible pump is driven by a control signal 𝑢(𝑡)generated by the PID controller. We
may express the delivered volumetric flow rate 𝑞𝑖𝑛 as directly proportional to the applied
control effort, assuming the electrical time constant of the pump motor is negligible compared
to the slow hydraulic dynamics of the tank.
The transient relationship is modeled as:

𝑞𝑖𝑛 (𝑡) = 𝐾𝑝 ⋅ 𝑢(𝑡)

where 𝐾𝑝 represents the lumped process gain of the pump. Converting this into deviation
variables:
𝛥𝑞𝑖𝑛 (𝑡) = 𝐾𝑝 ⋅ 𝛥𝑢(𝑡)

Taking the Laplace transform yields the zero-order transfer function for the actuator:

𝛥𝑄𝑖𝑛 (𝑠)
𝐺𝑃 (𝑠) = = 𝐾𝑝
𝛥𝑈(𝑠)

Based on our experimental calibration, the pump delivers a steady flow, yielding the established
process gain:

𝐾𝑝 = 8.33 cm3 /s per unit control effort


𝐺𝑃 (𝑠) = 8.33
8.2.3 The Plant (Water Tank)
We express the volumetric behavior of the system by applying the conservation of mass. For
an incompressible fluid (constant density), the initial steady-state volumetric balance (input
flow rate = output flow rate) is expressed as:

𝑑ℎ𝑠𝑠
𝐴 = 0 = 𝑞𝑖𝑛,𝑠𝑠 − 𝑞𝑜𝑢𝑡,𝑠𝑠
𝑑𝑡

where t is time, A is the constant cross-sectional area of the cylindrical tank, the subscript $ss$
denotes the initial steady-state condition (null operating condition), 𝑞𝑖𝑛 is the incoming
volumetric flow rate from the pump, and 𝑞𝑜𝑢𝑡 is the discharge rate.
In our specific control setup, the tank acts as a pure accumulator during the filling phase,
meaning there is no continuous gravity-driven discharge valve during operation 𝑞𝑜𝑢𝑡 = 0.
Assuming that at t = 0, the inflow 𝑞𝑖𝑛 starts to deviate from its steady-state value, the dynamic
response of the liquid level is described by the transient-state balance equation:

𝑑ℎ
𝐴 = 𝑞𝑖𝑛
𝑑𝑡
To analyze the system using classical control theory, we express the variables as deviation
quantities from their steady-state operating points:

𝛥ℎ = ℎ − ℎ𝑠𝑠

𝛥𝑞𝑖𝑛 = 𝑞𝑖𝑛 − 𝑞𝑖𝑛,𝑠𝑠

Substituting the deviation variables into the transient mass balance equation yields:

𝑑𝛥ℎ
𝐴 = 𝛥𝑞𝑖𝑛
𝑑𝑡
Since there is no gravity-drain valve introducing nonlinear dynamics, the system is inherently
linear. Taking the Laplace transform of the deviation equation (assuming zero initial
conditions) gives:

𝐴 ⋅ 𝑠 ⋅ 𝛥𝐻(𝑠) = 𝛥𝑄𝑖𝑛 (𝑠)

Rearranging this yields the plant transfer function, which takes the form of a pure Type-1
integrator:
𝛥𝐻(𝑠) 1
𝐺𝑇 (𝑠) = =
𝛥𝑄𝑖𝑛 (𝑠) 𝐴 ⋅ 𝑠

Given our physically measured tank area 𝐴 = 147.33 𝑐𝑚2 :

1
𝐺𝑇 (𝑠) =
147.33𝑠

9 Conclusions
These individual component models were integrated into a complete block diagram and
simulated using MATLAB and Simulink. The simulation results support the theoretical design
of the water level control system. The closed-loop step response shows that the system can
reach the target water level of 20 cm with an overdamped response and zero overshoot,
reducing the possibility of water overflow.

The control system analysis further confirms stable system behavior. The Root Locus plot
shows that the closed-loop poles remain in the left-half of the s-plane, indicating stability.
Similarly, the Bode plot demonstrates satisfactory gain and phase characteristics, suggesting
that the system can maintain reliable performance under normal operating conditions.

In conclusion, the selected PID parameters (Kp = 2, Ki = 0.05, Kd = 0.01) provide effective
control of the water level for the proposed system. The project successfully combines practical
hardware implementation with control system modeling and simulation, resulting in a reliable
and efficient automatic water level control system.

You might also like