Microprocessor and Interfacing CSE-2006: TOPIC - Water Level Indicator Using 8051 Microcontroller
Microprocessor and Interfacing CSE-2006: TOPIC - Water Level Indicator Using 8051 Microcontroller
Microprocessor and Interfacing CSE-2006: TOPIC - Water Level Indicator Using 8051 Microcontroller
CSE-2006
PROJECT REPORT
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.
1. Aim
2. Introduction
3. Abstract
4. Objective
9. Block Diagram
10. Architecture
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.
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.
Pin 20
Also called Vss. This is the ground pin that represents 0V.
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.
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.
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;
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);
}
}
}
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