Está en la página 1de 12

Intelligent Water Control System using 8051 (AT89C51)

Project Report

Submitted to:
Engr. Azhar Ali Zaidi

Submitted by:
Asad Abbas 08-EE-09 Muhammad Abdullah Adnan Farooqi 08-EE-87

Department of Electrical Engineering University of Engineering and Technology Taxila

Abstract:
This report illustrates the construction and working of a liquid level indicator. Such an indicator is used in tanks to indicate the level of liquids and alert us when the tank is full. So by this circuit we can monitor the various levels of the tank and can avoid spillage of water and also we can configure our supplies according to the various levels of tank. Such module or circuit can be installed in big buildings where manual monitor of tanks is difficult and its indicator can be placed at some centralized place.

Description:
This circuit works on the principle that water conducts electricity. A wire connected to VCC and four other wires are dipped in tank at different levels namely quarter, half, threefourth, full and their output are taken on pins P3.0, P3.1, P3.2, P3.3 via a transistor BC547. Port P2 is connected to data pins of LCD and P1.0, P1.1, P1.2 are respectively connected to RS, RW, and EN pins of LCD. Initially when the tank is empty LCD will show the message VACANT. As the tank starts filling up wire at different levels get some positive voltage, due to conducting nature of water. This voltage is then fed to their corresponding pins on controller. When level reaches to quarter level, LCD displays the message QUARTER. On further rise of level, HALF and 3/4 QUARTER are displayed on LCD. When tank gets full LCD shows the message FULL CLOSE TAP. A buzzer is also provided to produce an alert the user when the tank gets filled. LED is connected to indicate when tank is not Full.

Circuit Diagram:

Components:
The main components used in this circuit are as follows: 1. 8051 (AT89C51) Microcontroller 2. 16x2 LCD 3. Transistor BC547,D400 4. Piezo Buzzer 5. Resistors and capacitors 6. Connecting lead

We will describe each component in detail.

1- 8051 (AT89C51) Microcontroller:


AT89C51 is an 8-bit microcontroller and belongs to Atmel's 8051 family. AT89C51 has 4KB of Flash programmable and erasable read only memory (PEROM) and 128 bytes of RAM. It can be erased and program to a maximum of 1000 times. In 40 pin AT89C51, there are four ports designated as P 1, P2, P3 and P0. All these ports are 8-bit bi-directional ports, i.e., they can be used as both input and output ports. Except P0 which needs external pull-ups, rest of the ports have internal pull-ups. When 1s are written to these port pins, they are pulled high by the internal pull-ups and can be used as inputs. These ports are also bit addressable and so their bits can also be accessed individually. Port P0 and P2 are also used to provide low byte and high byte addresses, respectively, when connected to an external memory. Port 3 has multiplexed pins for special functions like serial communication, hardware interrupts, timer inputs and read/write operation from external memory. AT89C51 has an inbuilt UART for serial communication. It can be programmed to operate at different baud rates. Including two timers & hardware interrupts, it has a total of six interrupts.

Pin Description:
Pin No 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 Function Name P1.0 P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 Reset P3.0 P3.1 8 bit input/output port (P3) pins P3.2 P3.3 P3.4 P3.5 P3.6 P3.7 Crystal 2 Crystal 1 Ground P2.0/ A8 P2.1/ A9 P2.2/ A10 P2.3/ A11 P2.4/ A12 P2.5/ A13 P2.6/ A14 P2.7/ A15 PSEN ALE Prog EA Vpp P0.7/ AD7 P0.6/ AD6 P0.5/ AD5 P0.4/ AD4 P0.3/ AD3 P0.2/ AD2 P0.1/ AD1 P0.0/ AD0 Vcc

8 bit input/output port (P1) pins

Reset pin; Active high Input (receiver) for serial RxD communication Output (transmitter) for serial TxD communication External interrupt 1 Int0 External interrupt 2 Int1 Timer1 external input T0 Timer2 external input T1 Write to external data memory Write Read from external data memory Read Quartz crystal oscillator (up to 24 MHz) Ground (0V)

8 bit input/output port (P2) pins / High-order address bits when interfacing with external memory

Program store enable; Read from external program memory Address Latch Enable Program pulse input during Flash programming External Access Enable; Vcc for internal program executions Programming enable voltage; 12V (during Flash programming)

8 bit input/output port (P0) pins Low-order address bits when interfacing with external memory

Supply voltage; 5V (up to 6.6V)

2- Liquid Crystal Display (16x2):


LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments and other multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on. A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data. The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.

3- Transistor BC547:
BC547 is an NPN bi-polar junction transistor. A transistor, stands for transfer of resistance, is commonly used to amplify current. A small current at its base controls a larger current at collector & emitter terminals. BC547 is mainly used for amplification and switching purposes. It has a maximum current gain of 800. Its equivalent transistors are BC548 and BC549. The transistor terminals require a fixed DC voltage to operate in the desired region of its characteristic curves. This is known as the biasing. For amplification applications, the transistor is biased such that it is partly on for all input conditions. The input signal at base is amplified and taken at the emitter. BC547 is used in common emitter configuration for amplifiers. The voltage divider is the commonly used biasing mode. For switching applications, transistor is biased so that it remains fully on if there is a signal at its base. In the absence of base signal, it gets completely off.

4- Piezo Buzzer:
The piezo buzzer produces sound based on reverse of the piezoelectric effect. The generation of pressure variation or strain by the application of electric potential across a piezoelectric material is the underlying principle. These buzzers can be used alert a user of an event corresponding to a switching action, counter signal or sensor input. They are also used in alarm circuits. The buzzer produces a same noisy sound irrespective of the voltage variation applied to it. It consists of piezo crystals between two conductors. When a potential is applied across these crystals, they push on one conductor and pull on the other. This, push and pull action, results in a sound wave. Most buzzers produce sound in the range of 2 to 4 kHz. The Red lead is connected to the Input and the Black lead is connected to ground.

Block Diagram

Buzzer 8051 Microcontroller Water Tank LCD 16x2

Code
#include<reg51.h> sbit rs=P1^0; sbit rw=P1^1; sbit e=P1^2; sbit quat=P3^0; sbit half=P3^1; sbit quat_3=P3^2; sbit full=P3^3; sbit spkr_on=P3^4; sbit spkr_off=P3^5; sbit tap=P3^7; void delay(int k) { int i,j; for(i=0;i<k;i++) for(j=0;j<1275;j++); } void write(int j) { rs=1; rw=0; P2=j; e=1; delay(100); //register select pin //read/write pin //enable pin //pin connected to quarter level of tank //pin connected to half level of tank //pin connected to three -fourth level of tank //pin connected to full level of tank // pin to off speaker //pin to control Tap //delay function

//write function //selecting command register //selecting to write //putting value on the pins //strobe the enable pin

e=0; return; } void cmd(int j) { P2=j; rs=0; rw=0; e=1; delay(1); e=0; return; } void puts(char *a) { unsigned int p=0; for(;a[p]!=0;p++) write(a[p]); } //command function //put the value on pins //selecting command register //selecting to write //strobe enable pin

//puts function to print a string

void lcd_init(void) { cmd(0x38); delay(50); cmd(0x0e); delay(50); cmd(0x01); cmd(0x80); } void startup(void) { cmd(0x80); puts("Welcome to IWS"); delay(50); cmd(0xC0); puts("By 08-EE-09 & 87"); delay(50); cmd(0x01); } void status(void) {

// function to initialise the LCD //setting 8-bit interface, 2 lines, 5*7 Pixels //turning on underline visible cursor //clearing screen //moving cursor to the begining of line 1 of LCD

cmd(0x85); puts("Status"); } void main() { lcd_init(); startup(); quat=1;half=1;quat_3=1;full=1;spkr_off=1; quat=0;half=0;quat_3=0;full=0;spkr_off=0; spkr_on=1; //configuring as input pins //lowering input pins // making speaker on pin high,as it // works on negative logic

tap=0; while(1) { spkr_on=1; while(quat==0&&half==0&&quat_3==0&&full==0&&spkr_off==0) //condition when tank is empty { lcd_init(); // initialising LCD status(); cmd(0xC0); puts("EMPTY; TAP ON"); //printing Empty on lcd tap=1; } while(quat==1&&half==0&&qua t_3==0&&full==0&&spkr_off==0) //condition when tank is quater { lcd_init(); status(); cmd(0xC0); puts("Tank is QUARTER"); //printing QUATER on lcd } while(quat==1&&half==1&&quat_3==0&&full==0&&spkr_off==0) //condition when tank is half { lcd_init(); status(); cmd(0xC0); puts("Tank is HALF"); //printing HALF on lcd } while(quat==1&&half==1&&quat_3==1&&full==0&&spkr_off==0) //condition when tank is three-fourth

{ lcd_init(); status(); cmd(0xC0); puts("Tank is 3/4 FULL"); //printing 3/4 FULL on lcd } while(quat==1&&half==1&&quat_3==1&&full==1&&spkr_off==0) //condition when tank is full { lcd_init(); status(); cmd(0xC0); puts("FULL;CLOSE TAP"); //printing FULL;CLOSE TAP on lcd spkr_on=0; // Enabling speaker tap=0; } while(quat==1&&half==1&&quat_3==1&&full==1&&spkr_on==0&&spkr_off==1) //enabling high speaker_off pin { spkr_on=1; //disabling speaker } } }

También podría gustarte