You are on page 1of 6

Project Name

Water Level Control Using 8051

Aim:- To design system using 8051 for detection of water level of tank and operate
Pump Depending on Level Input.

Component List:-Transformer, Bridge, Resistor, Capacitor, 8051,LED,sensing electrodes.

Block diagram:

89S51 LCD
Water Sensing
Tank Electrode

CIRCUIT DIAGRAM:

PROGRAM:

//program for water level indication

//lcd connected to P2
//water level i/p are at P0.0-P0.3

//rs connected to P3.7

//rw connected to P3.6

//e connected to P3.5

#include <REGX51.H>

#define lcdport P2 //lcd port P2

sbit rs=P3^7; //command or data select pin

sbit rw=P3^6; //read or write select pin

sbit en=P3^5; //enable pin

//void msdelay(unsigned int itime); //delay function

//void lcdini(void); //lcd ini function

//void lcdcmd(unsigned char value); //lcd command function

//void lcdwrt(unsigned char value); //lcd write function

//void water_indi(); //water level indication function

unsigned char text[]={"WATER LEVEL IS"};

unsigned char text1[]={"AT BOTTOM"};

unsigned char text2[]={"AT MIDDLE"};

unsigned char text3[]={"AT QUARTER"};

unsigned char text4[]={"TANK FULL"};

unsigned char k,l;

/*---------------------------------------------------------------------------------------*/

void msdelay(unsigned int itime) //delay routine for 1ms

unsigned int i,j;

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

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

}
/*---------------------------------------------------------------------------------------*/

void lcdcmd(unsigned char value)

msdelay(10); //10ms delay

lcdport=value; //command to lcd

rs=0; //lcd command selection

rw=0; //lcd write selection

en=1; //enable high

msdelay(10); //10ms delay

en=0; //enable low

/*---------------------------------------------------------------------------------------*/

void lcdwrt(unsigned char value)

msdelay(10); //10ms delay

lcdport=value; //data to lcd

rs=1; //lcd data selection

rw=0; //lcd write selection

en=1; //enable high

msdelay(10); //10ms delay

en=0; //enable low

/*---------------------------------------------------------------------------------------*/

void water_indi()

switch (P0)

{
case(0xFE):

for(l=0;l<9;l++)

lcdwrt(text1[l]);

break;

case(0xFC):

for(l=0;l<9;l++)

lcdwrt(text2[l]);

break;

case(0xF8):

for(l=0;l<10;l++)

lcdwrt(text3[l]);

break;

case(0xF0):

for(l=0;l<9;l++)

lcdwrt(text4[l]);

break;

/*---------------------------------------------------------------------------------------*/
void lcdini()

lcdcmd(0x38); //16*2 lcd select

lcdcmd(0x0C); //cursor off lcd on

lcdcmd(0x06); //increment addr

lcdcmd(0x01); //clear lcd

lcdcmd(0x80); //lcd position 1st line 1st coloum

/*---------------------------------------------------------------------------------------*/

void main()

P2=0x00; //port P2 as o/p

P3=0x00; // port P3 as o/p

P0=0x0FF; //port P0 as i/p

lcdini();

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

lcdwrt(text[k]); //send text to lcd

while(1)

lcdcmd(0xC0); //lcd 2nd line

water_indi();

/*---------------------------------------------------------------------------------------*/
Description:
As shown in block diagram, there are no. of blocks which contains sensing electrodes ,water
tank microcontroller 8051 and finally display unit such as 16*2 lcd display.

As shown in the circuit diagram there are four sensing electrodes are used to sense the
water level present in the water tank and one ground electrode is dipped in to the water tank ,when
water is at bottom level the electrode present at bottom sense the ground(as water is good
conductor of electricity) and microcontroller detects the level and displays it on lcd.

The sensing electrodes are connected at port pins P0.0 to P0.3,and lcd data bus is connected
to port 2,lcd control pins are connected to P3.5-RS,P3.6-RW,P3.7-En.

The water levels to be displayed on lcd are;

1. AT BOTTOM
2. AT MIDDLE
3. AT QUARTER
4. TANK FULL

You might also like