0% found this document useful (0 votes)
62 views13 pages

Microprocessor and Interfacing CSE-2006: TOPIC - Water Level Indicator Using 8051 Microcontroller

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 13

MICROPROCESSOR AND INTERFACING

CSE-2006

PROJECT REPORT

TOPIC – Water Level Indicator using 8051


Microcontroller

Project submitted by:

Sadrika Srivastava 17BCB0066

Prishita Ray 17BCE2405


DECLARATION BY THE CANDIDATE

We hereby declare that the project report entitled “Water Level Indicator using
8051 Microcontroller” submitted by us to Vellore Institute of Technology,
Vellore in partial fulfilment of the requirement for the award of the degree of
B. Tech (CSE) is a record of J- component of project work carried out by us
under the guidance of Prof. Rajarajan G. We further declare that the work
reported in this project has not been submitted and will not be submitted,
either in part or in full, for the award of any other degree or diploma in this
institute or any other institute or university.

Place : Vellore Institute of Technology, Vellore.


Date : 28-03-2019

Signature of the faculty Signature of the Candidates


TABLE OF CONTENTS

1. Aim
2. Introduction

3. Abstract
4. Objective

5. Proposed System & Architecture


6. System Design & Architecture

7. Pin Diagram of 8051


8. Pin Description

9. Block Diagram
10. Architecture

11. Component Required


12. Algorithm

13. Code
14. Conclusion and Result

15. Reference
Aim
To create water level indicator using 8051 microcontroller containing 4
indicator levels and display of results on an LCD Screen

Introduction
Water Level Controller using 8051 Microcontroller project will help in
automatically controlling the water motor by sensing the water level in a tank.
This explains how to detect and control the water level in an overhead tank or
any other container. This system monitors the water level of the tank and
automatically switches on the motor whenever tank is empty.
The motor is switched off when the overhead tank or container is full. Here,
the water level of the tank is indicated on LCD (Liquid crystal Display). Using
this system, we can avoid the overflow of the water.

Abstract
This system mainly works on a principle that “water conducts electricity”. The
four wires which are dipped into the tank will indicate the different water
levels. Based on the outputs of these wires, micro-controller displays water
level on LCD as well as controls the motor.
Initially when the tank is empty, LCD will display the message LOW and motor
runs automatically. When water level reaches to half level, now LCD displays
HALF and still motor runs.
When the tank is full, LCD displays FULL and motor automatically stops. Again,
the motor runs when water level in the tank becomes LOW.
In this system, water sensing can be done by using a set of 4 wires, which are
placed at different levels in tank. DC supply probe is placed at the base of the
tank. 

Objective
In this project we aim to display and control the water level in a container as
empty, low, medium or high using an 8051 Microcontroller based on the water
levels detected by the corresponding probes. This system mainly works on a
principle that “water conducts electricity”.
Proposed System & Architecture
 The heart of the Water Level Controller is the 8051 Microcontroller. The
water level probes are connected to the P0.0, P0.1 and P0.2 through the
transistors (they are connected to the base of the transistors through
corresponding current limiting resistors). P0.0 for LOW level, P0.1 for HALF
Level and P0.2 for HIGH Level
 The Collector terminals of the Transistors are connected to VCC and the
Emitter terminals are connected to PORT0 terminals (P0.0, P0.1 and P0.2)
 PORT1 of the microcontroller is connected to the data pins of LCD and the
control pins RS, RW and EN of the LCD Display are connected to the P3.6,
GND and P3.7 respectively.
 For demonstration purpose, we have used a simple DC Motor Pump. It is
connected to the Relay and the input to the relay is fed from P0.7 through
a transistor.

Working Model and Circuit Diagram


Pin Diagram of 8051

Pin Description
Pins from 1-8
Port 1: The pins in this port are bi-directional and can be used for input and
output. The pins are individually controlled; some are used for input while
others are used for output purposes.

Pin 9
This pin is also called ‘Reset Pin’. This is used for resetting the
microcontroller to its initial values. If the pin is set at logic 0, the chip runs
normally. When the oscillator is running, setting the pin at logic 1 for more
than two machine cycles will reset the microcontroller.

Pins from 10-17


PORT 3: These pins are same as pins in port 1 because of their bidirectional
input port.

 Pin 10 and Pin 11 perform receiving and transmitting operation of


serial data using ‘RS-232’ protocol.
 Pin 12 and Pin 13 are used to interrupt inputs.
 Pin 14 and Pin 15 perform alternative functions linked with Timer 0
and Timer 1.
 Pin 16 and Pin 17 are used when working with external memory.

Pins from 18-19


The pins are used for connecting an external crystal oscillator module with the
microcontroller.

Pin 20
Also called Vss. This is the ground pin that represents 0V.

Pins from 21-28


PORT 2: These are another set of bidirectional input port, they are used
when processing external memory. Higher order address bus signals are
multiplexed with this quasi-bidirectional port.

Pin 29
Also called PSEN (Program Store Enable) it controls and manages the
access to external CODE memory.

Pin 30
Named as Address Latch Enable (ALE). It is used when working with
external memory. ALE activity is disabled in some devices where external
memory is not used. Thus helping in reducing the electromagnetic
interference generated by the product.

Pin 31
Named as External Access (EA). In order to execute code from internal
memory this pin is connected to Vcc. To execute code from external
memory the pin must be grounded.

Pins from 32-39


Port 0: These are set of another bidirectional input port. Unlike Port 1, Port2
and Port 3 this port lacks pull-up resistors.

Pin 40
Named as Vcc. This is usually a 5V pin on 5V devices and 3V pin on 3V
devices.

I/O Pins
The 8051 microcontrollers are mostly 8-bit ports, thus giving a total of 32
pins which you can use to read input and control output. All of them are
bidirectional in nature so they can perform as both input and output. Some
of the ports perform alternate functions as discussed above such as to
support access to external memory. This is done to reduce the size of the
microcontroller device. When these ports are busy in performing their
alternate functions, they can not be made to act as input-output ports.

Block Diagram

Architecture
Central Processor Unit (CPU)
As we know that the CPU is the brain of any processing device of the
microcontroller. It monitors and controls all operations that are performed on
the Microcontroller units. The  User has no control over the work of the CPU
directly . It reads program written in ROM memory and executes them and do
the expected task of that application.
Interrupts
As its name suggests, Interrupt is a subroutine call that interrupts of the
microcontrollers main operations or work and causes it to execute any other 
program, which is more important at the time of operation. The feature of
Interrupt is very useful as it helps in case of emergency operations. An
Interrupts gives us a mechanism to put on hold the ongoing operations,
execute a subroutine and then again resumes to another type of operations.
The Microcontroller 8051 can be configured in such a way that it temporarily
terminates or pause the main program at the occurrence of interrupts. When a
subroutine is completed, Then the execution of main program starts. Generally
five interrupt sources are there in 8051 Microcontroller. There are 5 vectored
interrupts are shown in below
 INTO
 TFO
 INT1
 TF1
 R1/T1
Out of these,  (INT0) ̅ and (INT1) ̅ are external interrupts that could be negative
edge triggered or low level triggered. When All these interrupts are activated,
set the corresponding flogs  except for serial interrupt,.The interrupt flags are
cleared when the processor branches to the interrupt service routine (ISR). The
external interrupt flags are cleared when the processor branches to the
interrupt service routine,  provides the interrupt is a negative edge triggered
whereas the timers and serial port interrupts  two of them are  external
interrupts, two of them are timer interrupts and one serial port interrupt
terminal in general.

Memory
Microcontroller requires a program which is a collection of instructions. This
program tells microcontroller to do specific tasks. These programs require a
memory on which these can be saved and read by Microcontroller to perform
specific operations of a particular task. The memory which is used to store
the program of the microcontroller is known as code memory or Program
memory of applications. It is known as ROM memory of  microcontroller also
requires a memory to store data or operands temporarily of the micro
controller. The data memory of the 8051 is used to store data temporarily for
operation is known RAM memory. 8051 microcontroller  has 4K of code
memory or program memory,that  has 4KB ROM and also 128 bytes of data
memory of RAM.

BUS
Basically Bus is a collection of wires which work as a communication channel
or medium for transfer of Data. These buses consists of 8, 16 or more wires of
the microcontroller. Thus, these can carry 8 bits,16 bits simultaneously. Hire
two types of buses that are shown in below
 Address Bus
 Data Bus
Address Bus: Microcontroller 8051 has a 16 bit address bus for transferring the
data. It is used to address memory locations and to transfer the address from
CPU to Memory of the microcontroller. It has  four addressing modes that are
Immediate addressing modes.
 Bank address (or) Register addressing mode.
 Direct Addressing mode.
 Register indirect addressing mode.
Data Bus: Microcontroller 8051 has 8 bits of  the data bus, which is used to
carry data of particular applications.

Oscillator
Generally, we know that  the microcontroller is a device, therefore it requires
clock pulses for its operation of microcontroller applications. For this purpose,
microcontroller 8051 has an on-chip oscillator which works as a clock source
for Central Processing Unit of the microcontroller. The output pulses of
oscillator are stable. Therefore, it enables synchronized work of all parts of the
8051 Microcontroller.

Input/Output Port
Normally microcontroller is used in embedded systems to control the
operation of machines in the microcontroller. Therefore, to connect  it to other
machines, devices or peripherals we require I/O interfacing ports in 
the microcontroller interface. For this purpose microcontroller 8051 has 4
input, output ports to connect it to the other peripherals

Timers/Counters
8051 microcontroller has two 16 bit timers and counters. These counters are
again divided into a 8 bit register. The timers are used for measurement of
intervals to determine the pulse width of pulses.

Features of 8051 Microcontroller


An 8051 microcontroller comes bundled with the following features −
 64K bytes on-chip program memory (ROM)
 128 bytes on-chip data memory (RAM)
 Four register banks
 128 user defined software flags
 8-bit bidirectional data bus
 16-bit unidirectional address bus
 32 general purpose registers each of 8-bit
 16 bit Timers (usually 2, but may have more or less)
 Three internal and two external Interrupts
 Four 8-bit ports,(short model have two 8-bit ports)
 16-bit program counter and data pointer
 8051 may also have a number of special features such as UARTs, ADC, Op-
amp, etc.
Components Required

 AT89C51 Microcontroller (or any 8051 based Microcontroller)


 8051 Programmer (Programming Board)
 4 x 2N2222 (NPN) Transistors
 1KΩ x 8 Resistor Pack (for Pull – up)
 Push Button
 16 x 2 LCD Display
 DC Motor (for demonstration)
 10KΩ Potentiometer
 2 x 10KΩ Resistor(1/4Watt)
 5V Relay
 1N4007 PN Junction Diode
 Programming cable
 Connecting wires
 Power Supply

Algorithm
 First configure the controller pins P0.0, P0.1 and P0.2 as inputs and P0.7 as
output.
 Now, initialize the LCD.
 Continuously check the water level input pins P0.0, P0.1 and P0.2.
 If all the pins are low, then display tank as “EMPTY” on the LCD and make
P0.7 pin HIGH to run the motor automatically.
 If the level is low i.e. if P0.0 is HIGH, display the water level as “LOW” and
continue to run the motor.
 A HIGH pulse on the pin P0.1 indicates that water has reached half level.
So, display the same thing on LCD and run the motor normally.
 If P0.2 is HIGH, then the water level in the tank is FULL.
 Now, make the P0.7 pin as LOW to turn off the motor automatically.

Program Code
#include<reg51.h>
#define lcd P1
sbit rs=P3^6;
sbit e=P3^7;

sbit mot=P0^7;

sbit low=P0^0;
sbit mid=P0^1;
sbit high=P0^2;

void delay (int d)


{
unsigned char i;
for(;d>0;d--)
{
for(i=250;i>0;i--);
for(i=248;i>0;i--);
}
}
void cmd (unsigned char c)
{
lcd=c;
rs=0;
e=1;
delay(5);
e=0;
}
void display (unsigned char c)
{
lcd=c;
rs=1;
e=1;
delay(5);
e=0;
}
void string (char *p)
{
while(*p)
{
display(*p++);
}
}
void init (void)
{
cmd(0x38);
cmd(0x0c);
cmd(0x01);
cmd(0x80);
}
void main()
{
char lowp=0,midp=0,highp=0,ctrl=0;
P0=0x00;
init();

string(" Project ");


cmd(0xc0);
delay(3000);

cmd(0x80);
string(" Water Level ");
cmd(0xc0);
string(" controller ");
delay(3000);

cmd(0x80);
string("Level : ");
cmd(0xc0);
string("motor : ");
if(low==0)
{
mot=1;
}
while(1)
{
if(low!=lowp)//--------1
{
cmd(0x88);
string("LOW ");
cmd(0xc8);
string("ON ");
mot=1;
lowp=low;
ctrl=0;highp=0;
//delay(1000);
}
else if(mid!=midp)
{
cmd(0x88);
string("MEDIUM");
midp=mid;
}
else if((high!=highp)&&ctrl==0)
{
cmd(0x88);
string("HIGH ");
cmd(0xc8);
string("OFF");
mot=0;
highp=high;
ctrl=1;
//delay(100);
}
}
}

Conclusion and Result


This system mainly works on a principle that “water conducts electricity”. It will
help in automatically controlling the water motor by sensing the water level in
a tank. In this system, water sensing can be done by using a set of 4 wires,
which are placed at different levels in tank. DC supply probe is placed at the
base of the tank.
The four wires which are dipped into the tank will indicate the different water
levels. Based on the outputs of these wires, microcontroller displays water level
on LCD as well as controls the motor.
Initially when the tank is empty, LCD will display the message LOW and motor
runs automatically. When water level reaches to half level, now LCD displays
HALF and still motor runs.
When the tank is full, LCD displays FULL and motor automatically stops. Again,
the motor runs when water level in the tank becomes LOW.

References
 https://en.wikipedia.org/wiki/Float_switch
 https://waterlevelcontrols.com/water-level-control-
advantages-disadvantages/
 https://www.electronicshub.org/water-level-indicator/
 https://www.electronicshub.org/water-level-controller-
using-8051-microcontroller

You might also like