Keeping the liquid up to certain level in tank is one of the widely used applications in petroleum and consumable goods producing industries. Certain amount of liquid should be always there in the tank to keep the liquid pressure as it is. To maintain this level there is a need of liquid level controller.
It’s a close loop control system. It may be ON-OFF type of or continuous type system. There are two valves in tank. One is inlet and other is outlet. If one wants constant flow of liquid from tank then outlet valve must be fully open and liquid level in the tank should be above minimum specified limit. And this limit is maintained by controlling flow from inlet valve.
ON-OFF type: – in this system there are two limits. 1) Max limit 2) min limit. If liquid levels go beyond max limit then inlet valve is closed. Now as outlet valve is fully open the liquid level will start decreasing. As it reaches min limit and go below this inlet valve is again open. So liquid level will remain within these two limits.
Continuous type: – in this system there is only one limit. That is called set value. The liquid level in the tank is continuously compared with this set value. The opening of inlet valve is varied according to the change in the level in tank. Opening becomes wider if level falls and becomes shorter if level goes beyond set value. So continuous correction is made to maintain set value of level.
Here I am giving you an example of very simple controller in which first the tank is filled up to required level using pump and then after some time it is flushed completely by reversing pump. Again when tank is empty the pump automatically starts filling tank. And this cycle continuous. One can set the required level every time or he can change it in every cycle. This is demo application in which I am using simulated water tank from multisim software to illustrate this application.
So first let us understand the operation of this water tank. Here the figure given below shows the arrangement of water tank with pump and other assembly.
Water Tank Assembly & Block Diagram
As shown in above figure the full capacity of tank is 50 later. The set point (required level) is fixed at 35 letters. The rate at which pump fills the tank that depends upon valve setting. Flow control (which is not the part of this system) can be achieved by changing voltage applied at this terminal. There are three inputs to this system that controls pump operation
- flow in – when it is given a positive pulse, water will start flowing inside tank
- flow out – when it is given a positive pulse, water will start flowing outside tank
- stop flow – when given positive pulse flow will be stopped
Three outputs forms the system are
- set level – this o/p will become high when tank is filled upto set level. It will remain high till level is maintained. As the level decreases o/p becomes low
- tank empty – as tank is flushed completely this o/p becomes high. It immediately becomes low as tank starts filling.
- analog o/p – it gives DC o/p 0 – 5 V corresponding to the liquid level in tank. That means 0V when tank is empty and 5V when tank is full
So actually the system is very simple. Only we have to send pulses to input signals and use the outputs for indications and control actions. So let’s first see the block diagram of the system.
Block diagram of system
Let us see all the major building blocks one by one
89C51 – this controller chip is the heart of entire system. It receives the inputs from system, it generates suitable outputs to control the system, it displays the data on LCD and indicates various ongoing processes on LEDs
ADC 0801 – it converts analog input 0-5V from system in to digital equivalent
LCD panel – it displays the liquid level in tank as well as the set point value
buffer and latch – they are provided for protection of port pins
LED indicators – they indicate various processes going on like water flow inside-outside tank, water flow stop etc.
So all four ports 89C51 are engaged for various peripheral interfacing.
Liquid level controller circuit & software program
Liquid level controller circuit
The figure givenin circuit diagram tab1 shows complete schematic diagram of the system.
Connections:- the port P1 is connected with digital outputs D0-D7 of ADC. The RC components R2 and C1 forms basic clock circuit for ADC. R3 & R4 forms voltage divider network to generate reference voltage for ADC. The analog output from tank system is directly fed to +Ve input of ADC. Chip select signal CS is tied to gnd. Three control signals RD, WR and INTR of ADC are connected with P3.7, P3.6 and P3.3 respectively. The data pins of LCD are connected with P0 through latch 74LS373. Three control signals RS, RW & En are connected with P2.0, P2.1 and P2.2 respectively. Five LEDs D1 – D5 are connected with P2 pins as shown. Three inputs Fwd, Rev and Stop of tank system are connected to P3.4, P3.5 and P3.0 through buffer IC 74LS07. Tank empty output and set level output are connected with P3.1 and P3.2 through inverter 74LS04. Two LEDs (red and green) are connected for indication of tank empty and set level reached.
- Initially controller displays the set water level on LCD and then applies fwd pulse to pump control
- So the liquid will start flowing inside tank. This is indicated by LED D2.
- Then after every 2 seconds controller will read the liquid level in tank through ADC and displays it as current water level
- Now as the liquid is filling in tank, when it reaches the set level it sends signal to controller on P3.1 and immediately controller will apply stop pulse
- No more liquid is pumped into tank. This is indicated by D3
- This level is maintained for 10 seconds. Then controller sends rev pulse. So liquid will start flowing outside from the tank. This is indicated by D1.
- As tank is completely flushed, the tank empty output is given to controller generates an interrupt. And immediately controller will apply fwd pulse
- So again the pump will again start filling tank. And this cycle continuous.
- LEDs D4 and D5 indicates sensing of current liquid level in tank through ADC.
Software program: –
the program written in C language for this application. Entire program is divided into 10 different functions along with one main function. So let us understand them one by one.
writecmd function sends command byte to LCD. It takes one argument byte and sends it to P0
- writedata function sends data byte to be displayed on LCD. It also takes one argument byte and sends it to P0
- writestr function writes whole string (message) on LCD. It takes pointer as an argument that points address of first character of string. then through pointer it sends all the character one by one to P0
- lcddly function provides delay before sending data or command to LCD so that LCD becomes ready to accept it.
- dely function is small delay (around 100 ms) for applying pulse and for LED indications
- bigdly function is a variable delay. It takes one integer argument and provides delay in seconds depending upon the value passed to it.
- display function takes any hex value as an argument and first convert it into decimal. then this decimal value is further converted into 3 ASCII characters and displays them onto LCD
- int0 function is actually interrupt subroutine. So it is called automatically when interrupt is generated. This function is called when external interrupt is generated that means when tank is completely flushed. so this function just gives fwd pulse and indicates on LED
- int1 function is also interrupt subroutine. It is called automatically when external interrupt 1 is generated that means when ADC finishes conversion and provides INTR signal. so it reads the data from ADC and display the value as ‘ current water level ‘
- timer function is also interrupt subroutine and it is called when timer overflows from all 1’s to all 0’s. Timer overflows after every 50 ms due to the loaded count. This function counts 40 such overflows. so finely it generates 40*50 = 2000 ms = 2 s
The main function performs following tasks
- initializes port (as i/p or o/p), LCD, timer and enables all interrupts
- loads the count in timer registers
- displays set value as ‘ set water level ‘
- applies fwd pulse and indicates on LED
- applies WR pulse to ADC to read ‘ cur water lever ‘
- Then waits for set limit is reached. when it is reached sends stop pulse and indicates on LED
- then after waiting for 10 sec it sends rev pulse and indicates on LED
- as when tank is flushed it automatically sends fwd pulse the main function again waits for set limit reached
- So this is a continuous cycle.
Project Source Code
Project Source Code
#include <string.h>sbit rs = P2^0; // defining different pins of 8051
sbit en = P2^2;
sbit rw = P2^1;
sbit wr = P3^6;
sbit rd = P3^7;
sbit led1 = P2^3;
sbit led2 = P2^4;
sbit led3 = P2^5;
sbit led4 = P2^6;
sbit led5 = P2^7;
sbit wtrin = P3^4;
sbit wtrout = P3^5;
sbit wtrstp = P3^0;
sbit limit = P3^1;
unsigned char data d;
unsigned int c=0;
void dely(); //function definations
void display(unsigned char z);
void writecmd(unsigned char a);
void writedat(unsigned char b);
void writestr(unsigned char *s);
void int1(void) interrupt 2 // external interrupt 1 subroutine
EA=0; // disable all interrupts
led5=1; // read pulse indication
rd = 0; // send read pulse to ADC
d=P1; // read the data
writecmd(0xC0); // display it on LCD
writestr("cur water level:- ");
EA=1; // enable all interrupts
void timer(void) interrupt 1 // timer overflow interrupt subroutine
EA=0; // disable all interrupts
c++; // increment count
TH0=0x3C; // relaod timer
if(c==40) // if count is 40
wr = 0; // send write pulse to ADC
wr = 1;
c=0; // start countin again
void int0(void) interrupt 0 // external interrupt 0 subroutine
EA=0; //disable interrupts
wtrin=1; // apply fwd puls and give indication
void display(unsigned char z)
unsigned int tmp1,tmp2,t,t1,a;
unsigned char asci;
tmp1 = (z & 0x0F); // separate upper and lower nibbles of hex value
tmp2 = z >> 4;
tmp2 = tmp2*16; // convert it into decimal
t = tmp1+tmp2;
if(t>=100) // if its 3 digit
a=2; // take a as 3 digit value
asci[a]=t1+0x30; // convert each digit in to ASCII
t1=t%10; // if 2 digit
asci=0x30; // take first digit as 0
writedat(asci); // send all 3 digits to LCD
void dely() // delay of 100 ms
void bigdly(int k) // variable delay in seconds
void lcddly() // LCD delay
void writecmd(unsigned char a)
rs = 0;
rw = 0;
P0 = a;
en = 1;
en = 0;
void writedat(unsigned char b)
rs = 1;
rw = 0;
P0 = b;
en = 1;
en = 0;
void writestr(unsigned char *s)
unsigned char l,i;
l = strlen(s); // first get the lenght of message
writedat(*s); // send all characters one by one to LCD
P2=0x00; // initialize ports
IE=0x87; // enable interrupts
TMOD=0x01; // initialize timer
TH0=0x3C; // load timer to count up to
TL0=0xAF; // 50,000
writecmd(0x3C); // initialize LCD
writestr("set water level:- "); // display set water level as
display(0xB4); // 180d
wtrin=1; // send fwd pulse
led1=1; // indicate on LED
wr = 0; // send WR pulse to ADC
wr = 1;
TR0=1; // start timer
agin:while(limit==1); // wait until set value is reached
wtrstp=1; // stop water flow
bigdly(200); // wait for 10 sec
wtrout=1; // send rev pulse
bigdly(50); // after 2-3 sec
goto agin; // again wait for set value reached }
Filed Under: Electronic Projects