AUTOMATIC WATER LEVEL CONTROLLER USING MICRO-CONTROLLER PIC18F45K22




The objective of this project is to design an automatic water level control system. It indicates the level of water in the tank and automatically controls it by using PIC Microcontroller and water level sensors.

Water Sensor

AUTOMATIC WATER LEVEL CONTROLLER USING MICROCONTROLLER PIC18F45K22

Water Sensor

Water level sensor is an easy-to-use, cost-effective high level/drop recognition sensor, which is obtained by having a series of parallel wires exposed traces measured droplets/water volume in order to determine the water level. Easy to complete water to analog signal conversion and output analog values can be directly read by using Microcontroller PIC18F45K22 to achieve the level alarm effect..

Features:

Operating voltage: DC3-5V
Operating current:less than 20mA
SensorType:Analog
DetectionArea: 40mmx16mm
Humidity: 10% -90% non-condensing
Product Dimensions: 62mm x 20mm x 8mm

Description :

This project displays water level in the tank and it controls the motor which pumps the water in it :

  • when tank’s water level isvery low (0%),motor is automatically turned on and buzzer off
  • when water level reaches 25% in the tank, motor is automatically turned on and buzzer off
  • when water level reaches 50% in the tank, motor is automatically turned on and buzzer off
  • when water level reaches 75% in the tank, motor is automatically turned on and buzzer off
  • when the water level is full or 100%, the microcontroller turns off the switch of motor automatically and buzzer on (alarm activated).

Seven segment display shows the current water level in the tank.Also LCD 4×20 is used to show different levels in percentage and five LEDs.

As you know there’s no library of the water sensor in PROTEUS Isis, so i replace it by a potentiometer.

READ  Fire Fighting Controlling Robots Used in Dangerous Situations

 

Software Development :

The code developed for the PIC is written in the C language. The compiler used to write the C code is mikroC PRO for PIC V. 7.1.0. After the c code is successfully compiled, a HEX file is generated.

AUTOMATIC WATER LEVEL CONTROLLER USING MICRO-CONTROLLER PIC18F45K22 (Code)


/*
* Project name:
Automatic Level tank control with microcontroller
* Copyright:
(c) lET'S THINk BINARY, 2017.
* Revision History:
V0.0
* Description:
Automatic Level tank using PIC Microcontroller .
* Test configuration:
MCU: PIC18F45K22
Oscillator: 8.0000 MHz Crystal
SW: mikroC PRO for PIC
http://www.mikroe.com/mikroc/pic/
* NOTES:
- This Our Group (thanks to join and participate) :
https://www.facebook.com/groups/816450708460518/
- Facebook page (thanks to like and share) :
https://www.facebook.com/Lets-Think-Binary-1728910547340654/
- Youtube Channel (thanks to subscribe) :
https://www.youtube.com/channel/UCTIAzxEkyeA6HTvl_VHd-Tw
*/
#include "Display_Utils.h"
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
unsigned char txt[14];
unsigned long adc_rd;
float Level;
unsigned short shifter, portd_index;
unsigned short portd_array[4];
char digit,digit1, digit10,digit100,i;
void interrupt() {
LATA = 0; // Turn off all 7seg displays
LATD = portd_array[portd_index]; // bring appropriate value to PORTD
LATA = shifter; // turn on appropriate 7seg. display
// move shifter to next digit
shifter <<= 1; if (shifter > 8u)
shifter = 1;
// increment portd_index
portd_index++ ;
if (portd_index > 3u)
portd_index = 0; // turn on 1st, turn off 2nd 7seg.
TMR0L = 0; // reset TIMER0 value
TMR0IF_bit = 0; // Clear TMR0IF
}
void display(){
digit = i % 10u;
digit1 = conversion(digit); // prepare ones digit
portd_array[1] = conversion(digit); // and store it to PORTD array
digit = (char)(i / 10u) % 10u;
digit10 = conversion(digit); // prepare tens digit
portd_array[2] = conversion(digit); // and store it to PORTD array
digit = (i / 100u) % 10u; // extract hundreds digit
digit100 = conversion(digit);
portd_array[3] = conversion(digit); // and store it to PORTD array
}
void level1(void) //function level1
{
LATC =0x01; // LED RED ON indicates the tank is empty
delay_ms(50);
}
void level2(void) //function level2
{
LATC =0x02; // LED YELLOW ON LEVEL 1/4
delay_ms(50);
}
void level3(void) //function level3
{
LATC =0x04; // LED YELLOW ON LEVEL 1/2
delay_ms(50);
}
void level4(void) //function level4
{
LATC =0x08; // LED YELLOW ON LEVEL 3/4
delay_ms(50);
}
void level5(void) //function level5
{
LATC =0x10; // LED green ON indicates the tank is full
//delay_ms(2000);
}
void Melody_alarm_Full(void)
{
Sound_Play(2200, 80); // PLAY 2.2KHZ TONE FOR 80mS
delay_ms(50); // AND PAUSE FOR 50mS
Sound_Play(820, 80); // THEN PLAY A 820HZ TONE FOR 80mS
delay_ms(50);
}
void main(){
ANSELA.F0 = 1; // Set RA0 to analog
ANSELD = 0; // Configure PORTD pins as digital
ANSELB = 0; // Configure PORTB pins as digital
ANSELC = 0; // Configure PORTC pins as digital
ADCON1=0; // ADC ref = Vdd,Vss
ADCON2=0xAF; // right justify, Frc,& 12 TAD ACQ time
TRISA = 0x01; // Configure PORTA as output
LATA = 0; // Clear PORTA
TRISB = 0; // Configure PORTD as output
LATB = 0; // Clear PORTD
TRISD = 0; // Configure PORTD as output
LATD = 0; // Clear PORTD
LATC = 0; // set PORTC to 0
TRISC = 0; // designate PORTC pins as output
T0CON = 0xC4; // Set TMR0 in 8bit mode, assign prescaler to TMR0
TMR0L = 0; // clear TMROL
digit = 0;
portd_index = 0;
Sound_Init(&PORTB, 7);
//Sound_Play(880, 1000); // Play sound at 880Hz for 1 second
shifter = 1;
GIE_bit = 1;
TMR0IE_bit = 1; //INTCON = 0xA0; // Enaable GIE,T0IE
ADCON2=0xAD;
ADC_Init(); // Initialize ADC
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 2, "LET'S THINK BINARY");
Lcd_Out(2, 1, "AUTOMATIC LEVEL TANK");
Lcd_Out(3, 1, "LEVEL TANK IS:");
Lcd_Chr(3,19,'%'); // Display "C" for Celsius
//Lcd_Out(4, 1, " ");
adc_rd = 0;
while(1){ // infinite loop
adc_rd = ADC_Read(0); // Read from channel 0
Level = adc_rd * 100.0/1024.0; // Convert to porcentage
i= Level;
floatToStr(Level, txt); // Convert to string
txt[4]=0;
Lcd_Out(3,15,txt); // Write string in seco
display();
portb.f6=1;
if (i==0) level1();
else if (i == 25) level2();
else if (i == 50) level3();
else if (i == 75) level4();
else if (i == 99) {level5();
portb.f6=0;} // // if the tank is full stop pump
else portc=0x00;
if ((i>=0)&& (i<=25)) Lcd_Out(4, 1, "MOTOR ON BUZZER OFF"); else if ((i>25)&& (i<=50)) Lcd_Out(4, 1, "MOTOR ON BUZZER OFF"); else if ((i>50)&& (i<=75)) Lcd_Out(4, 1, "MOTOR ON BUZZER OFF"); else if ((i>75)&& (i<=98)) Lcd_Out(4, 1, "MOTOR ON BUZZER OFF"); else {Lcd_Out(4, 1, "MOTOR OFF BUZZER ON"); // if the tank is full stop pump Melody_alarm_Full();} } // end while } // end of program

AUTOMATIC WATER LEVEL CONTROLLER USING MICRO-CONTROLLER PIC18F45K22 (Schematic Diagram)

AUTOMATIC WATER LEVEL CONTROLLER USING MICROCONTROLLER PIC18F45K22

water level indicator using PIC

 




Current Project / Post can also be found using:

  • Robot prject using)pic18
  • automatic water level controller using pic16f877a
  • conclusion for traffic light using pic microcontroller and seven segments
  • pic controller using robot

Leave a Comment

*
= 5 + 1

Read previous post:
SOLID STATE SUPPLIES OFFERS WORLD’S SMALLEST BLUETOOTH® LOW ENERGY (BLE) MODULE
SOLID STATE SUPPLIES OFFERS WORLD’S SMALLEST BLUETOOTH® LOW ENERGY (BLE) MODULE

Acknowledged as the UK’s leading source of advanced embedded technology, Solid State Supplies Ltd. now offers the world’s smallest Bluetooth® Low...

Close
Scroll to top