Liquid Level controller Using “LabVIEW + PID controller”

Narendran Srinivasan
7 min readJul 16, 2021

Nowadays, many industries are using a level controller which means a level transducer for simply control the level in the storage tank, process control, and so on. In Industry what exactly happens is ( Basic Controller ) the person have to give a set point to the machine (eg. 70 ). Which can be set into a variable called setpoint for the machine. By using a simple PID controller we can easily able to control the physical parameters with the help of mathematical modelling.

Final value of setpoint with process variable
Final value of setpoint with process variable

Demo Video — Liquid Level controller Using “LabVIEW + PID controller”

Before explaining design, have to know about PID: What is PID?

Brief History of Control Systems:

PID is nothing but, which is one type of controller used from the 1950s as a classical system of control that comes under the control system design as transfer function representation after the 1980s introduced a new concept in control system design due to limitation of the transfer function, that is state-space representation. State Space representation is an advanced one. We can model and stable both the non-linear as well as linear systems under non-zero initial conditions, but the transfer function model neglect every initial condition in every model for stabilizing. After 2000 ( In 21st Century ) Introducing a new concept called robust control design, which is the most advanced one. The robust control system is a combination of state-space and transfer function modelling. Nowadays a lot of research is happening in the robust control system domain.

What is PID:

This is a “no calculus required” explanation of PID control.

Let us say you have a small toy car that can move left and right. And let us say you can tell it where it ought to be (target location) and it can know where it is (actual location). Now let’s say you want to make the car move quickly and accurately to a new location. You can apply electricity to the motor in the car but you don’t know how much electricity to apply. The solution to your problem is PID control.

The difference between the target location and the actual location is something we call an error. Error = Target — Actual. For PID control there are 3 constants Kp, Kp and Ki that we mathematically manipulate with the error to know exactly how much electricity to apply to the motor at any point in time. Each of these “K”s is called a gain factor. Here is how the 3 gains or “K”s works.

Proportional gain (Kp) means that the electricity you apply to the motor is proportional to the error. A big error means big electricity to correct it. If the proportional gain is too low the car just moves slowly. If you keep increasing the proportional gain it moves faster but eventually, the car zooms past the target and then runs back and forth several times eventually stopping near the target.

This is why you need derivative gain (Kp). Derivative gain means that if you have an error but the error is going down quickly (the car is moving fast), then you can decrease the electricity applied to the motor a little bit. This prevents zooming past the target and helps you stop at or near the target directly.

But even with the proportional gain Kp and derivative gain Kp, your car will never land exactly on the target because even if you are close, such a small error won’t make enough electricity to move the car at all. To solve this problem we keep track of the accumulated error over time and use that to add some electricity so that the car doesn’t stop short of the target. This is called integral gain Ki and will ensure that you move to the target.

Finding the best values for Kp, Kp and Ki can be done by sophisticated mathematical modelling or by trial and error. The best part is that after you find the ideal values for all 3 gains, your car will move with optimum efficiency and performance for all conditions. So you can imagine why PID controllers are so helpful and popular in many engineering applications.

Design construction (block diagram):

Basic Closed loop Control Design
Basic Closed loop Control Design

LABVIEW Block diagram:

LabVIEW PID Controller Block diagram
LabVIEW PID Controller Block diagram

By selecting Advanced PID Block: create a setpoint control, Manual control, Give a respective time rate, PID Gain.

PID Block in LABVIEW

Advanced PID labVIEW
Advanced PID labVIEW

Manual control: specifies the value of the control output when auto? is FALSE.

Auto?: specifies whether to use automatic or manual control. In some situations, you might need to switch off the PID controller and operate the system in manual, or open-loop, mode. The default is TRUE. When auto? is TRUE, this VI uses automatic control. When auto? is FALSE, this VI uses manual control. This VI uses bumpless transfer from manual control to automatic control.

Output range: specifies the range to which to coerce the control output. The default range is –100 to 100, which corresponds to values specified in terms of percentage of full scale. You can change this range to something that is appropriate for your control system. For example, you can relate engineering units to engineering units instead of percentage to percentage. This VI implements integrator anti-windup when the controller output is saturated at the specified minimum or maximum values.

  1. output high specifies the maximum value of the controller output. The default is 100.
  2. output low specifies the minimum value of the controller output. The default is –100.

Setpoint: specifies the setpoint value, or desired value, of the process variable being controlled.

Process variable: specifies the measured value of the process variable being controlled. This value is equal to the feedback value of the feedback control loop.

Setpoint range: specifies the maximum and minimum values for the setpoint/process variable range. This VI uses the setpoint range to calculate nonlinear integral action. The default range is 0 to 100, which corresponds to values specified in terms of percentage of full scale. You can change this range to something that is appropriate for your control system. For example, you can relate engineering units to engineering units instead of percentage to percentage. This VI uses the setpoint range in the nonlinear integral action calculation and the nonlinear error calculation.

  1. setpoint low specifies the minimum value of the setpoint/process variable range.
  2. setpoint high specifies the maximum value of the setpoint/process variable range.

PID gains specifies the proportional gain, integral time, and derivative time parameters of the controller.

  1. proportional gain (Kc) specifies the proportional gain of the controller. The default is 1. In the equation that defines the PID controller, KC represents the proportional gain.
  2. integral time (Ti, min) specifies the integral time in minutes. The default is 0.01.
  3. derivative time (Td, min) specifies the derivative time in minutes. The default is 0.

dt (s) specifies the loop-cycle time, or interval in seconds, at which this VI is called. If dt (s) is less than or equal to zero, this VI calculates the time since it was last called using an internal timer with 1 ms resolution. If dt (s) must be less than 1 ms, specify the value explicitly. The default is -1.

Reinitialize? specifies whether to reinitialize the internal parameters, such as the integrated error, of the controller. Set reinitialize? to TRUE if your application must stop and restart the control loop without restarting the entire application. The default is FALSE.

beta specifies the relative emphasis of setpoint tracking to disturbance rejection. The default value of 1 is appropriate for most applications. You can use a smaller value between 0 and 1 to specify emphasis on disturbance rejection, such as process load changes. The VI uses this value in the two degree-of-freedom algorithm.

Linearity specifies the linearity of the error response. The valid range for linearity is 0 to 1. A value of 1 provides a normal linear response, while a value of 0.1 provides an approximately parabolic response. The VI uses this value in the nonlinear error calculation and the nonlinear gain factor calculation.

Output returns the control output of the PID algorithm that is applied to the controlled process. If this VI receives an invalid input, output returns NaN.

dt out (s) returns the actual time interval in seconds. dt out (s) returns either the value of dt (s) or the computed interval if you set dt (s) to –1.

In a PID Advanced block: Give a setpoint value as range whatever you want, then define a process variable to get the output from level transducer for controlling. We can add a graph chart to visualize the level of tuning with the proportional(Kp), integrative(Ki) and derivative gain(kd).

Tuning of liquid level using PID controller in LabVIEW
Tuning of liquid level

In a pressure gauge ( Liquid Control Valve ) controlling the liquid flow by tuning concerning the controller that here designed. In this design, the range of liquid levels is set to 0–100.

Here is the simple design which is a setpoint level controller, there were advanced controllers without a setpoint that can control the liquid level, temperature, pressure and so on. We can easily able to implement the above design easily with the help of a microcontroller called Arduino. Control systems and process control is a wide and fantabulous area for deep diving in research. Take a read, explore more.

--

--

Narendran Srinivasan

Eidetic Learner | Bridging the Gap on Electronics, IoT, and ML | A Big Fan of PID | Intriguing Finance