Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Liquid level Controller

By Ashutosh Bhatt December 21, 2012

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 

Liquid level controller circuit

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

  1. flow in – when it is given a positive pulse, water will start flowing inside tank
  2. flow out – when it is given a positive pulse, water will start flowing outside tank
  3. stop flow – when given positive pulse flow will be stopped

Three outputs forms the system are

  1. 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
  2. tank empty – as tank is flushed completely this o/p becomes high. It immediately becomes low as tank starts filling.
  3. 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

Block Diagram of Liquid level controller circuit

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.

Operation: –

  • 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

  1. writedata function sends data byte to be displayed on LCD. It also takes one argument byte and sends it to P0 
  2. 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
  3. lcddly function provides delay before sending data or command to LCD so that LCD becomes ready to accept it.
  4. dely function is small delay (around 100 ms) for applying pulse and for LED indications
  5. bigdly function is a variable delay. It takes one integer argument and provides delay in seconds depending upon the value passed to it.
  6. 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
  7. 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
  8. 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 ‘
  9. 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<reg51.h>

 #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 bigdly(int);

 void lcddly();

 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

  rd=1;

  dely();      //

  led5=0;

  writecmd(0xC0);    // display it on LCD

  writestr("cur water level:- ");

  display(d); 

  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

   TL0=0xAF;

   if(c==40)        // if count is 40

     {

       led4=1;

    dely();

    wr = 0;    // send write pulse to ADC

    wr = 1;

    led4=0;

    c=0;    // start countin again

   }

    EA=1;

  }

  void int0(void) interrupt 0 // external interrupt 0 subroutine

  {

   EA=0;      //disable interrupts

  led3=0;

  led1=1;

  wtrin=1;       // apply fwd puls and give indication

  dely();

  wtrin=0;

  EA=1;

   }

 

void display(unsigned char z)

   {

    unsigned int tmp1,tmp2,t,t1,a;

  unsigned char asci[3];

  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

   while(t>10)

   { 

    t1=t%10;

    asci[a]=t1+0x30;  // convert each digit in to ASCII

    t=t/10;

    a--;

   }

   asci[0]=t+0x30;

    }

  else

    {

   t1=t%10;     // if 2 digit

   asci[2]=t1+0x30;

   t=t/10;

   asci[1]=t+0x30;

   asci[0]=0x30;    // take first digit as 0

    }

  writedat(asci[0]);    // send all 3 digits to LCD

  writedat(asci[1]);

  writedat(asci[2]);

   }

 void dely()       // delay of 100 ms

   {

    int i,j;

  for(i=0;i<100;i++)

    for(j=0;j<250;j++);

    }

 void bigdly(int k)      // variable delay in seconds

   {

     int i,j;

  for(i=0;i<k;i++)

    for(j=0;j<10000;j++);

   }

 void lcddly()    // LCD delay

 {

  int x;

  for(x=0;x<1500;x++);

  }

 void writecmd(unsigned char a)

 {

  lcddly();

  rs = 0;

  rw = 0;

  P0 = a;

  en = 1;

  en = 0;

 }

 void writedat(unsigned char b)

 {

  lcddly();

  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

  for(i=1;i<l;i++)

  {

   writedat(*s);     // send all characters one by one to LCD

   s++; 

  }

 } 

 main()

 {

  P1=0xFF;

  P2=0x00;         // initialize ports

  P3=0xCE;

  P0=0x00;

  IE=0x87;         // enable interrupts

  TMOD=0x01;         // initialize timer

  TH0=0x3C;         // load timer to count up to

  TL0=0xAF;          // 50,000

  writecmd(0x3C);        // initialize LCD

  writecmd(0x0F);

  writecmd(0x01);

  writestr("set water level:- ");  // display set water level as

  display(0xB4);      // 180d

  wtrin=1;           // send fwd pulse

  led1=1;           // indicate on LED

  led4=1;

  dely();

  wr = 0;            // send WR pulse to ADC

  wr = 1;

  TR0=1;            // start timer

  wtrin=0;

  led4=0;

 agin:while(limit==1);       // wait until set value is reached

  led1=0;

  led2=1;

  wtrstp=1;          // stop water flow

  dely();

  wtrstp=0;

  bigdly(200);          // wait for 10 sec

  led2=0;

  led3=1;

  wtrout=1;          // send rev pulse

  dely();

  wtrout=0;

  bigdly(50);          // after 2-3 sec

  limit=1;

  goto agin;          // again wait for set value reached }

 

###

 


Circuit Diagrams

liqiud-ckt


Filed Under: Electronic Projects
Tagged With: control circuit, ic, liquid level, microcontroller, water level
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Finding past posts on edaboard?
  • I think i have devised a new type of "super_transformer" for the Electricity grid?
  • Industrial Relay Board Design for Motorcycle Use
  • sequence detector FSM design
  • Need suggestions in task NI6363 retrigger (analog trigger)

RSS Electro-Tech-Online.com Discussions

  • Sump pit water alarm - Kicad 9
  • Pic18f25q10 osccon1 settings swordfish basic
  • Anyone jumped from Easyeda std to Easyeda pro?
  • turbo jet fan - feedback appreciated.
  • More fun with ws2812 this time XC8 and CLC

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • How IoT network topologies work
  • The top five AI startups to watch in 2025
  • STMicroelectronics unveils SoC based on secure MCU
  • Nexperia’s 48 V ESD diodes support higher data rates with ultra-low capacitance design
  • Taoglas releases Patriot antenna with 18 integrated elements covering 600 to 6000 MHz

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe