Water Level Indicator and Controller Using PIC Microcontroller
Water Level Indicator and Controller Using PIC Microcontroller
Water Level Indicator and Controller Using PIC Microcontroller
Microcontroller
B Y LIG O G E OR G E / 21 7 C O MME N TS
Here is a simple, versatile project which indicates the level of water and
automatically controls it by using PIC Microcontroller. The Water Level Sensing
Section senses the level of water in the tank and sends it (wireless) to the Receiver
Section. Receiver Section is connected to the Controlling Section, which process the
received information and produces visual, sound indications and controls the
operation of the motor whenever required. The project is divide into 4 sections.
ASK RF Transmitter
Level Sensor module is made of with HT12E encoder and ASK (Amplitude Shift
Keying) RF transmitter. This circuit can be drive using 9V battery. For more details
about this transmitter, please read the article Wireless RF Transmitter and Receiver
using ASK RF Module. This circuit is placed near the Water Tank and connected to
the tank as show in the figure below.
3. Receiver Section
ASK RF Receiver
Receiver Module is made of with HT12D decoder and ASK RF receiver. The data
transmitted by the Sensor module is received by this module and is given to the
Controlling Module. For more details about this receiver, please read the
article Wireless RF Transmitter and Receiver using ASK RF Module.
4. Controlling Section
Circuit Diagram
Water Level Indicator Controller using PIC Microcontroller
rolling Section is PIC16F877A. It process the data given by the Receiver Section.
LCD Display, LED Indications and Motor status are updated according to the data.
You can download the hex file and mikroC Source Code at the bottom of this article.
MikroC Code
// LCD module connections
void main()
{
int i = 0;
int c = 16;
int b = 0;
CMCON = 0x07;
ADCON1 = 0x06;
TRISA = 0x0F;
PORTA = 0x00;
PORTD = 0x00;
PORTC = 0x00;
TRISB = 0x00;
TRISC = 0x00;
TRISD = 0x80;
PORTD.F2 = 1;
PORTD.F7 = 1;
Lcd_Init();
// Initialize LCD
Lcd_Cmd(_LCD_CLEAR);
// Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
// Cursor of
Lcd_Out(1,1,txt1);
Lcd_Out(2,1,txt2);
Delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
// Clear display
Lcd_Out(1,1,txt3);
Lcd_Out(2,1,txt4);
Delay_ms(500);
// Moving text
for(i=0; i<15; i++)
{
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Delay_ms(125);
}
do
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,wtr1);
Lcd_Out(2,1,mtr1);
if(c>0)
{
PORTD.F2 = 1
//LCD Backlight ON
c--;
}
else
PORTD.F2 = 0;
if(b>0)
{
PORTD.F0 = 1;
//Buzzer ON
Delay_ms(125);
PORTD.F0 = 0;
//Buzzer OFF
b--;
}
if(PORTD.F7 == 0)
//Manual Backlight ON
c = 16;
if(PORTA == 0x0F)
{
PORTD.F1 = 1;
Lcd_Out(1,8,wtr2);
Lcd_Out(2,7,mtr3);
PORTC = 1;
if(i == 0)
{
c = 16;
//Backlight
b=3;
//Buzzer
i=1;
}
else if(PORTA == 0x0E)
{
Lcd_Out(1,8,wtr3);
if(i == 1)
Lcd_Out(2,7,mtr3);
else
Lcd_Out(2,7,mtr2);
PORTC = 3;
//LED Bar
}
else if(PORTA == 0x0C)
{
Lcd_Out(1,8,wtr4);
if(i == 1)
Lcd_Out(2,7,mtr3);
else
Lcd_Out(2,7,mtr2);
PORTC = 7;
//LED Bar
}
else if(PORTA == 0x08)
{
Lcd_Out(1,8,wtr5);
if(i == 1)
Lcd_Out(2,7,mtr3);
else
Lcd_Out(2,7,mtr2);
PORTC = 15;
//LED Bar
}
else if(PORTA == 0x00)
{
Lcd_Out(1,8,wtr6);
Lcd_Out(2,7,mtr2);
PORTD.F1 = 0;
if(i == 1)
// Motor OFF
{
c = 16;
//Backlight
b = 3;
//Buzzer
}
i=0;
PORTC = 31;
//LED Bar
}
else
PORTA = 0x0F;
Delay_ms(125);
}while(1);
// Endless loop
Working
For the transmission and reception of data we have used Holtek encoder-decoder
pair of HT12E and HT12D. Both of them are CMOS ICs working voltage ranges from
2.4 to 12v. The oscillator resistances are chosen according to the datasheet. When
water level raises, the data pins of the encoder will be grounded corresponding to
the level of water, which will be transmitted to the Receiver via ASK RF module. The
received data is decoded by the decoder HT12D. LED on the receiver indicates that
it is receiving data. Then the data is given to the PIC for processing.
D0
D1
D2
D3
Status
When the water level becomes Very Low, the motor will turned ON, buzzer sounds
and the LCD backlight will automatically turned ON for 5 seconds. After this, when
the water level reaches Full level, the motor will automatically turned OFF, buzzer
sounds and the LCD backlight will automatically turned ON for 5 seconds. During
normal operation you can manually turn on LCD backlight by pressing the Push
button switch. The LCD indicates the Level of water (Very Low, Low, Medium,
High,Full) and the status of the motor (ON or OFF). The LED bar will also
indicate the level of water.